Initialize configurable Quick Access module
Module Package Release / publish-packages (push) Successful in 12s
Module Package Release / publish-packages (push) Successful in 12s
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { apiFetch, type ApiSettings } from "@govoplan/core-webui";
|
||||
|
||||
export type QuickAccessPreference = {
|
||||
enabled?: boolean | null;
|
||||
forced?: boolean;
|
||||
order?: number | null;
|
||||
};
|
||||
|
||||
export type QuickAccessProfile = {
|
||||
scope_type: "system" | "tenant" | "user";
|
||||
tenant_id?: string | null;
|
||||
scope_id?: string | null;
|
||||
revision: number;
|
||||
etag: string;
|
||||
category_preferences: Record<string, QuickAccessPreference>;
|
||||
tool_preferences: Record<string, QuickAccessPreference>;
|
||||
stale_category_ids: string[];
|
||||
stale_tool_ids: string[];
|
||||
};
|
||||
|
||||
export type QuickAccessCategory = {
|
||||
id: string;
|
||||
label: string;
|
||||
description: string;
|
||||
icon: string;
|
||||
order: number;
|
||||
};
|
||||
|
||||
export type QuickAccessTool = {
|
||||
id: string;
|
||||
module_id: string;
|
||||
category_id: string;
|
||||
label: string;
|
||||
description?: string | null;
|
||||
icon: string;
|
||||
surface_id: string;
|
||||
full_page_path?: string | null;
|
||||
required_all: string[];
|
||||
required_any: string[];
|
||||
order: number;
|
||||
default_enabled: boolean;
|
||||
modes: string[];
|
||||
};
|
||||
|
||||
export type QuickAccessCatalogue = {
|
||||
categories: QuickAccessCategory[];
|
||||
tools: QuickAccessTool[];
|
||||
};
|
||||
|
||||
export type EffectiveQuickAccessTool = QuickAccessTool & {
|
||||
enabled: boolean;
|
||||
forced: boolean;
|
||||
locked_by?: string | null;
|
||||
};
|
||||
|
||||
export type EffectiveQuickAccessCategory = QuickAccessCategory & {
|
||||
enabled: boolean;
|
||||
forced: boolean;
|
||||
locked_by?: string | null;
|
||||
tools: EffectiveQuickAccessTool[];
|
||||
};
|
||||
|
||||
export type EffectiveQuickAccess = {
|
||||
categories: EffectiveQuickAccessCategory[];
|
||||
diagnostics: string[];
|
||||
};
|
||||
|
||||
const profileEndpoints = {
|
||||
system: "/api/v1/quick-access/profiles/system",
|
||||
tenant: "/api/v1/quick-access/profiles/tenant",
|
||||
me: "/api/v1/quick-access/profiles/me"
|
||||
} as const;
|
||||
|
||||
export function loadQuickAccessCatalogue(
|
||||
settings: ApiSettings,
|
||||
includeAll = false
|
||||
): Promise<QuickAccessCatalogue> {
|
||||
const query = includeAll ? "?include_all=true" : "";
|
||||
return apiFetch(settings, `/api/v1/quick-access/catalogue${query}`);
|
||||
}
|
||||
|
||||
export function loadEffectiveQuickAccess(
|
||||
settings: ApiSettings,
|
||||
includeAll = false
|
||||
): Promise<EffectiveQuickAccess> {
|
||||
const query = includeAll ? "?include_all=true" : "";
|
||||
return apiFetch(settings, `/api/v1/quick-access/effective${query}`);
|
||||
}
|
||||
|
||||
export function loadQuickAccessProfile(
|
||||
settings: ApiSettings,
|
||||
scope: "system" | "tenant" | "me"
|
||||
): Promise<QuickAccessProfile> {
|
||||
return apiFetch(settings, profileEndpoints[scope]);
|
||||
}
|
||||
|
||||
export function saveQuickAccessProfile(
|
||||
settings: ApiSettings,
|
||||
scope: "system" | "tenant" | "me",
|
||||
profile: QuickAccessProfile,
|
||||
categoryPreferences: Record<string, QuickAccessPreference>,
|
||||
toolPreferences: Record<string, QuickAccessPreference>
|
||||
): Promise<QuickAccessProfile> {
|
||||
return apiFetch(settings, profileEndpoints[scope], {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"If-Match": profile.etag
|
||||
},
|
||||
body: JSON.stringify({
|
||||
base_revision: profile.revision,
|
||||
category_preferences: categoryPreferences,
|
||||
tool_preferences: toolPreferences
|
||||
})
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user