54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
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)
|
|
});
|
|
}
|