feat: render dashboard from model
This commit is contained in:
parent
13e3ff867b
commit
fede33e8a7
11 changed files with 372 additions and 139 deletions
|
|
@ -1,31 +1,42 @@
|
|||
import { dimensionLabDashboardFixture } from "$lib/model/fixtures/dimensionlab";
|
||||
import type { DashboardDocument } from "$lib/model";
|
||||
import {
|
||||
createDashboardStore,
|
||||
DashboardPersistenceValidationError,
|
||||
type DashboardStore,
|
||||
} from "$lib/server/db/dashboard-store";
|
||||
import { UnsupportedDashboardModelVersionError } from "$lib/server/db/model-migrations";
|
||||
|
||||
export type PlaceholderStatus = "ready" | "building";
|
||||
export type DashboardRuntimeState =
|
||||
| DashboardRuntimeEmpty
|
||||
| DashboardRuntimeInvalid
|
||||
| DashboardRuntimeReady;
|
||||
|
||||
export interface PlaceholderDashboard {
|
||||
export interface DashboardRuntimeReady {
|
||||
state: "ready";
|
||||
document: DashboardDocument;
|
||||
schemaVersion: string;
|
||||
currentRevisionId: string;
|
||||
}
|
||||
|
||||
export interface DashboardRuntimeEmpty {
|
||||
state: "empty";
|
||||
title: string;
|
||||
subtitle: string;
|
||||
status: PlaceholderStatus;
|
||||
message: string;
|
||||
schemaVersion?: string;
|
||||
currentRevisionId?: string;
|
||||
}
|
||||
|
||||
export function loadPlaceholderDashboard(): PlaceholderDashboard {
|
||||
return {
|
||||
title: "Dashboard Runtime",
|
||||
subtitle: "Runtime scaffold",
|
||||
status: "building",
|
||||
message:
|
||||
"SvelteKit is running. Later issues will replace this placeholder with the validated dashboard model.",
|
||||
};
|
||||
export interface DashboardRuntimeInvalid {
|
||||
state: "invalid";
|
||||
title: string;
|
||||
subtitle: string;
|
||||
message: string;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
export function loadDashboardRuntime(store?: DashboardStore): PlaceholderDashboard {
|
||||
export function loadDashboardRuntime(
|
||||
store?: DashboardStore,
|
||||
): DashboardRuntimeState {
|
||||
const dashboardStore = store || createDashboardStore();
|
||||
|
||||
try {
|
||||
|
|
@ -37,16 +48,42 @@ export function loadDashboardRuntime(store?: DashboardStore): PlaceholderDashboa
|
|||
const document = active?.document || seeded.document;
|
||||
const currentRevisionId = active?.currentRevisionId || seeded.id;
|
||||
|
||||
if (!document) {
|
||||
return {
|
||||
state: "empty",
|
||||
title: "No Dashboard Model",
|
||||
subtitle: "No active document",
|
||||
message: "No validated dashboard document is active yet.",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
title: document.metadata.title,
|
||||
subtitle: document.metadata.subtitle || "",
|
||||
status: "building",
|
||||
message:
|
||||
"Active dashboard document loaded from SQLite. Later issues will replace this placeholder with model-driven rendering.",
|
||||
state: "ready",
|
||||
document,
|
||||
schemaVersion: document.schemaVersion,
|
||||
currentRevisionId,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof DashboardPersistenceValidationError) {
|
||||
return invalidRuntimeState(error.failure.errors);
|
||||
}
|
||||
|
||||
if (error instanceof UnsupportedDashboardModelVersionError) {
|
||||
return invalidRuntimeState([error.message]);
|
||||
}
|
||||
|
||||
throw error;
|
||||
} finally {
|
||||
if (!store) dashboardStore.close();
|
||||
}
|
||||
}
|
||||
|
||||
function invalidRuntimeState(errors: string[]): DashboardRuntimeInvalid {
|
||||
return {
|
||||
state: "invalid",
|
||||
title: "Invalid Dashboard Model",
|
||||
subtitle: "Validation failed",
|
||||
message: "The active dashboard document could not be validated.",
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue