v0.3.7-pre.006
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// file: crates/ksp-app-backfill-desk/frontend/ts/main.ts
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
import "bootstrap";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import "simplebar";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import type { BackfillDeskOptionsDto } from "./bindings/ksp_app_backfill_desk/dto_common/BackfillDeskOptionsDto.ts";
|
||||
import type { BackfillHttpRouteOptionDto } from "./bindings/ksp_app_backfill_desk/dto_common/BackfillHttpRouteOptionDto.ts";
|
||||
import type { ShellStatusDto } from "./bindings/ksp_app_backfill_desk/dto_common/ShellStatusDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, frontendWarn, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
@@ -77,6 +79,74 @@ function bindNavigation(): void {
|
||||
frontendTrace("main", "Backfill Desk navigation handlers installed");
|
||||
}
|
||||
|
||||
|
||||
function routeLabel(route: BackfillHttpRouteOptionDto): string {
|
||||
if (route.pooled) {
|
||||
return `Pool multi-provider — ${route.providers.join(" + ")}`;
|
||||
}
|
||||
return route.providers.length === 1 ? `Provider — ${route.providers[0]}` : route.role;
|
||||
}
|
||||
|
||||
function renderBackfillOptions(options: BackfillDeskOptionsDto): void {
|
||||
const select = document.querySelector<HTMLSelectElement>("#backfillHttpRoute");
|
||||
if (select) {
|
||||
const previous = select.value;
|
||||
select.replaceChildren();
|
||||
for (const route of options.httpRoutes) {
|
||||
const option = document.createElement("option");
|
||||
option.value = route.role;
|
||||
option.textContent = routeLabel(route);
|
||||
select.append(option);
|
||||
}
|
||||
select.disabled = !options.transportReady || options.httpRoutes.length === 0;
|
||||
const reusable = options.httpRoutes.some(route => route.role === previous);
|
||||
if (reusable) {
|
||||
select.value = previous;
|
||||
}
|
||||
}
|
||||
const values: Record<string, string> = {
|
||||
backfillNetwork: options.configuredNetworks.length === 1 ? options.configuredNetworks[0] : options.configuredNetworks.join(", ") || "indisponible",
|
||||
backfillTransportReady: options.transportReady ? "ready" : "non ready",
|
||||
backfillStoreReady: options.storeReady ? "ready" : "non ready",
|
||||
backfillCompositionReady: options.compositionReady ? "ready" : "non ready",
|
||||
};
|
||||
for (const [id, value] of Object.entries(values)) {
|
||||
const element = document.querySelector<HTMLElement>(`#${id}`);
|
||||
if (element) {
|
||||
element.textContent = value;
|
||||
}
|
||||
}
|
||||
const diagnostic = document.querySelector<HTMLElement>("#backfillOptionsDiagnostic");
|
||||
if (diagnostic) {
|
||||
const error = options.transportDiagnostic ?? options.storeDiagnostic;
|
||||
diagnostic.hidden = error === null;
|
||||
diagnostic.textContent = error === null ? "" : `${error.domain}/${error.code}: ${error.message}`;
|
||||
}
|
||||
frontendTrace("main", "Backfill Desk HTTP route options rendered", {
|
||||
compositionReady: options.compositionReady,
|
||||
routeCount: options.httpRoutes.length,
|
||||
transportReady: options.transportReady,
|
||||
});
|
||||
}
|
||||
|
||||
async function loadBackfillOptions(source: "startup" | "user"): Promise<void> {
|
||||
frontendDebug("main", "Backfill Desk HTTP route options load started", { source });
|
||||
const options = await invokeKsp<BackfillDeskOptionsDto>("main", "backfill_options");
|
||||
renderBackfillOptions(options);
|
||||
frontendDebug("main", "Backfill Desk HTTP route options load completed", { source, routeCount: options.httpRoutes.length });
|
||||
}
|
||||
|
||||
function bindBackfillRouteSelection(): void {
|
||||
const select = document.querySelector<HTMLSelectElement>("#backfillHttpRoute");
|
||||
if (!select) {
|
||||
return;
|
||||
}
|
||||
select.addEventListener("change", () => {
|
||||
frontendDebug("main", "Backfill Desk HTTP route selection changed", { role: select.value || "none" });
|
||||
});
|
||||
frontendTrace("main", "Backfill Desk HTTP route selection handler installed");
|
||||
}
|
||||
|
||||
function renderRuntimeStatus(status: ShellStatusDto): void {
|
||||
const values: Record<string, string> = {
|
||||
runtimeVersion: status.applicationVersion,
|
||||
@@ -131,9 +201,10 @@ async function initializeMain(): Promise<void> {
|
||||
bindFrontendInteractions();
|
||||
bindNavigation();
|
||||
bindRuntimeStatusRefresh();
|
||||
bindBackfillRouteSelection();
|
||||
activateView("backfill", "startup");
|
||||
try {
|
||||
await loadRuntimeStatus("startup");
|
||||
await Promise.all([loadRuntimeStatus("startup"), loadBackfillOptions("startup")]);
|
||||
} catch {
|
||||
frontendWarn("main", "Backfill Desk startup runtime status load failed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user