feat(plan): add categories query, type, and map helpers (frontend)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-06 00:44:28 +02:00
parent a55356d417
commit 4b1c42b17f

View File

@@ -29,6 +29,30 @@ export interface ResolvedCell {
rangeTo: string | null; rangeTo: string | null;
} }
export interface PlanCategory {
id: number;
key: string;
label: string;
color: string;
sort_order: number;
is_active: boolean;
}
export const planCategoriesOptions = () =>
queryOptions({
queryKey: ["plan", "categories"],
queryFn: () => jsonQuery<PlanCategory[]>("/api/admin/plan/categories"),
});
/** Build a key → category lookup from the categories list. */
export function categoryMap(
categories: PlanCategory[] | undefined,
): Record<string, PlanCategory> {
const map: Record<string, PlanCategory> = {};
for (const c of categories ?? []) map[c.key] = c;
return map;
}
/** Czech labels for the plan_category enum — single source of truth shared /** Czech labels for the plan_category enum — single source of truth shared
* by the grid chips, the detail view, and aria-labels. */ * by the grid chips, the detail view, and aria-labels. */
export const PLAN_CATEGORIES: ReadonlyArray<{ value: string; label: string }> = export const PLAN_CATEGORIES: ReadonlyArray<{ value: string; label: string }> =
@@ -42,13 +66,14 @@ export const PLAN_CATEGORIES: ReadonlyArray<{ value: string; label: string }> =
{ value: "other", label: "Jiné" }, { value: "other", label: "Jiné" },
]; ];
const PLAN_CATEGORY_LABELS: Record<string, string> = Object.fromEntries( /** Czech label for a plan category key, resolved from the loaded categories
PLAN_CATEGORIES.map((c) => [c.value, c.label]), * map, falling back to the raw key. The `map` arg is optional so callers not
); * yet threading categories still compile (they show the raw key until wired). */
export function planCategoryLabel(
/** Czech label for a plan category, falling back to the raw value. */ key: string,
export function planCategoryLabel(value: string): string { map?: Record<string, PlanCategory>,
return PLAN_CATEGORY_LABELS[value] ?? value; ): string {
return map?.[key]?.label ?? key;
} }
/** Build the display label for a cell's project, preferring the server- /** Build the display label for a cell's project, preferring the server-