From eb71f936c6ad89c3aba220f1d6ae80e95275d7bb Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Thu, 16 Jul 2026 14:13:39 +0200 Subject: [PATCH] fix(custom-widgets): remove stale form helpers --- .../custom-widgets/_custom-widget-form.tsx | 170 ------------------ 1 file changed, 170 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/manage/custom-widgets/_custom-widget-form.tsx b/apps/nextjs/src/app/[locale]/manage/custom-widgets/_custom-widget-form.tsx index 426914ea3..fd0fb62b6 100644 --- a/apps/nextjs/src/app/[locale]/manage/custom-widgets/_custom-widget-form.tsx +++ b/apps/nextjs/src/app/[locale]/manage/custom-widgets/_custom-widget-form.tsx @@ -32,176 +32,6 @@ interface CustomWidgetFormProps { definitionId?: string; } -const displayConfigBuilders: Record) => Record> = { - singleValue: (v) => ({ - type: "singleValue", - jsonPath: v.jsonPath, - label: v.label, - unit: v.unit, - valueSize: v.valueSize, - labelPosition: v.labelPosition, - }), - keyValue: (v) => ({ - type: "keyValue", - mappings: v.mappings, - layout: v.kvLayout, - columns: v.kvColumns, - }), - table: (v) => ({ - type: "table", - tablePath: v.tablePath, - columns: v.columns, - striped: v.striped, - compact: v.compact, - }), - statGrid: (v) => ({ - type: "statGrid", - items: v.statGridItems, - columns: v.statGridColumns, - cardStyle: v.cardStyle, - }), - progressBars: (v) => ({ - type: "progressBars", - bars: v.progressBars.map((b) => ({ - ...b, - maxPath: b.maxPath || undefined, - })), - showPercentage: v.showPercentage, - barSize: v.barSize, - }), - statusIndicator: (v) => ({ - type: "statusIndicator", - items: v.statusItems.map((item) => ({ - ...item, - goodValues: item.goodValues - .split(",") - .map((s) => s.trim()) - .filter(Boolean), - })), - layout: v.statusLayout, - dotSize: v.dotSize, - }), - countGrid: (v) => ({ - type: "countGrid", - items: v.countGridItems, - columns: v.countGridColumns, - valueSize: v.countValueSize, - }), - raw: (v) => ({ - type: "raw", - jsonPath: v.rawJsonPath, - maxHeight: v.rawMaxHeight, - }), - actionButton: (v) => ({ - type: "actionButton", - buttonLabel: v.buttonLabel, - buttonColor: v.buttonColor, - confirmText: v.confirmText || undefined, - successMessage: v.successMessage || undefined, - }), - customJsx: (v) => ({ type: "customJsx", template: v.template }), -}; - -const serverToFormFieldMap: Record> = { - statGrid: { items: "statGridItems" }, - countGrid: { items: "countGridItems" }, - statusIndicator: { items: "statusItems" }, - progressBars: { bars: "progressBars" }, - keyValue: { mappings: "mappings" }, - table: { columns: "columns", tablePath: "tablePath" }, - singleValue: { jsonPath: "jsonPath", label: "label", unit: "unit" }, - raw: { jsonPath: "rawJsonPath" }, - actionButton: { buttonLabel: "buttonLabel" }, - customJsx: { template: "template" }, -}; - -function extractServerErrors(err: unknown, displayType: string): Record { - const errors: Record = {}; - const trpcErr = err as { - data?: { zodError?: { fieldErrors?: Record } }; - message?: string; - }; - - if (trpcErr?.data?.zodError?.fieldErrors) { - for (const [field, messages] of Object.entries(trpcErr.data.zodError.fieldErrors)) { - if (messages?.[0]) { - errors[field] = messages[0]; - } - } - return errors; - } - - try { - const issues = JSON.parse(trpcErr?.message ?? "[]") as Array<{ - path: (string | number)[]; - message: string; - }>; - const fieldMap = serverToFormFieldMap[displayType] ?? {}; - - for (const issue of issues) { - const path = [...issue.path]; - if (path[0] === "displayConfig") { - path.shift(); - const serverField = String(path[0]); - const formField = fieldMap[serverField] ?? serverField; - path[0] = formField; - } - errors[path.join(".")] = issue.message; - } - } catch { - // not parseable, ignore - } - - return errors; -} - -const listItemDefaults = { - mapping: { label: "", jsonPath: "$", unit: "" }, - column: { header: "", jsonPath: "$" }, - statGridItem: { label: "", jsonPath: "$", unit: "", color: "blue" }, - progressBar: { - label: "", - valuePath: "$", - maxPath: "", - unit: "", - color: "blue", - }, - statusItem: { label: "", jsonPath: "$", goodValues: "online,true" }, - countGridItem: { label: "", jsonPath: "$", unit: "" }, -} as const; - -function cloneLast>(arr: T[], fallback: T): T { - const last = arr[arr.length - 1]; - return last ? { ...last } : { ...fallback }; -} - -const ALL_DISPLAY_TYPES = [ - "singleValue", - "keyValue", - "table", - "statGrid", - "progressBars", - "statusIndicator", - "countGrid", - "raw", - "actionButton", - "customJsx", -] as const; -const MANTINE_COLORS = [ - "blue", - "teal", - "green", - "red", - "orange", - "yellow", - "violet", - "pink", - "cyan", - "grape", - "indigo", - "lime", -] as const; - export function CustomWidgetForm({ mode, initialValues, definitionId }: CustomWidgetFormProps) { const router = useRouter(); const globalT = useI18n();