feat: add configurable view-aware dashboards
This commit is contained in:
53
webui/src/api/dashboard.ts
Normal file
53
webui/src/api/dashboard.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
apiFetch,
|
||||
apiPath,
|
||||
type ApiSettings,
|
||||
type DashboardWidgetConfiguration,
|
||||
type DashboardWidgetSize
|
||||
} from "@govoplan/core-webui";
|
||||
|
||||
export type DashboardWidgetPlacementResponse = {
|
||||
instance_id: string;
|
||||
widget_id: string;
|
||||
size: DashboardWidgetSize;
|
||||
configuration: DashboardWidgetConfiguration;
|
||||
};
|
||||
|
||||
export type DashboardLayoutResponse = {
|
||||
exists: boolean;
|
||||
view_id: string | null;
|
||||
layout_version: number;
|
||||
revision: number;
|
||||
placements: DashboardWidgetPlacementResponse[];
|
||||
known_widget_ids: string[];
|
||||
updated_at: string | null;
|
||||
};
|
||||
|
||||
export type DashboardLayoutUpdate = {
|
||||
expected_revision: number | null;
|
||||
layout_version: 1;
|
||||
placements: DashboardWidgetPlacementResponse[];
|
||||
known_widget_ids: string[];
|
||||
};
|
||||
|
||||
function layoutPath(viewId: string | null): string {
|
||||
return apiPath("/api/v1/dashboard/layout", { view_id: viewId });
|
||||
}
|
||||
|
||||
export function fetchDashboardLayout(
|
||||
settings: ApiSettings,
|
||||
viewId: string | null
|
||||
): Promise<DashboardLayoutResponse> {
|
||||
return apiFetch<DashboardLayoutResponse>(settings, layoutPath(viewId));
|
||||
}
|
||||
|
||||
export function saveDashboardLayout(
|
||||
settings: ApiSettings,
|
||||
viewId: string | null,
|
||||
payload: DashboardLayoutUpdate
|
||||
): Promise<DashboardLayoutResponse> {
|
||||
return apiFetch<DashboardLayoutResponse>(settings, layoutPath(viewId), {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user