Add product-area presentation to Views
This commit is contained in:
+36
-3
@@ -2,7 +2,8 @@ import {
|
||||
apiFetch,
|
||||
apiPath,
|
||||
type ApiSettings,
|
||||
type EffectiveViewProjection
|
||||
type EffectiveViewProjection,
|
||||
type ViewPresentation
|
||||
} from "@govoplan/core-webui";
|
||||
|
||||
export type ViewScopeType = "system" | "tenant" | "group" | "user";
|
||||
@@ -15,6 +16,11 @@ export type ViewRevision = {
|
||||
revision: number;
|
||||
surface_contract_version: string;
|
||||
visible_surface_ids: string[];
|
||||
presentation: {
|
||||
navigation_mode?: "grouped" | "flat";
|
||||
product_area_order?: string[];
|
||||
product_area_labels?: Record<string, string>;
|
||||
};
|
||||
content_hash: string;
|
||||
created_by?: string | null;
|
||||
created_at: string;
|
||||
@@ -79,6 +85,7 @@ type EffectiveViewApiResponse = {
|
||||
active_revision_id?: string | null;
|
||||
active_view_name?: string | null;
|
||||
visible_surface_ids: string[];
|
||||
presentation?: ViewRevision["presentation"];
|
||||
locked: boolean;
|
||||
available_views: Array<{
|
||||
id: string;
|
||||
@@ -113,6 +120,7 @@ function projection(response: EffectiveViewApiResponse): EffectiveViewProjection
|
||||
activeRevisionId: response.active_revision_id ?? null,
|
||||
activeViewName: response.active_view_name ?? null,
|
||||
visibleSurfaceIds: response.visible_surface_ids,
|
||||
presentation: presentationFromApi(response.presentation),
|
||||
locked: response.locked,
|
||||
availableViews: response.available_views.map((view) => ({
|
||||
id: view.id,
|
||||
@@ -211,6 +219,7 @@ export function createViewDefinition(
|
||||
name: string;
|
||||
description?: string | null;
|
||||
visible_surface_ids: string[];
|
||||
presentation?: ViewRevision["presentation"];
|
||||
}
|
||||
): Promise<ViewDefinition> {
|
||||
return apiFetch(settings, "/api/v1/views/definitions", {
|
||||
@@ -233,18 +242,42 @@ export function updateViewDefinition(
|
||||
export function createViewRevision(
|
||||
settings: ApiSettings,
|
||||
definitionId: string,
|
||||
visibleSurfaceIds: string[]
|
||||
visibleSurfaceIds: string[],
|
||||
presentation: ViewPresentation
|
||||
): Promise<ViewDefinition> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
`/api/v1/views/definitions/${definitionId}/revisions`,
|
||||
{
|
||||
method: "POST",
|
||||
...jsonBody({ visible_surface_ids: visibleSurfaceIds })
|
||||
...jsonBody({
|
||||
visible_surface_ids: visibleSurfaceIds,
|
||||
presentation: presentationToApi(presentation)
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function presentationFromApi(
|
||||
value: ViewRevision["presentation"] | undefined
|
||||
): ViewPresentation {
|
||||
return {
|
||||
navigationMode: value?.navigation_mode,
|
||||
productAreaOrder: value?.product_area_order ?? [],
|
||||
productAreaLabels: value?.product_area_labels ?? {}
|
||||
};
|
||||
}
|
||||
|
||||
export function presentationToApi(
|
||||
value: ViewPresentation
|
||||
): ViewRevision["presentation"] {
|
||||
return {
|
||||
navigation_mode: value.navigationMode ?? "grouped",
|
||||
product_area_order: value.productAreaOrder ?? [],
|
||||
product_area_labels: value.productAreaLabels ?? {}
|
||||
};
|
||||
}
|
||||
|
||||
export function publishViewRevision(
|
||||
settings: ApiSettings,
|
||||
definitionId: string,
|
||||
|
||||
Reference in New Issue
Block a user