style: auto-fix lint and format
This commit is contained in:
1 parent
1cafb5edac
commit
e37bd38f34
13 files changed
+224
-216
No files matched your search
@@ -470,20 +470,74 @@ const serverToFormFieldMap: Record<string, Record<string, string>> = {
|
||||
};
|
||||
|
||||
const importToFormValues: Record<string, (config: Record<string, unknown>) => Record<string, unknown>> = {
|
||||
singleValue: (c) => ({ jsonPath: c.jsonPath, label: c.label ?? "", unit: c.unit ?? "", valueSize: c.valueSize ?? "lg", labelPosition: c.labelPosition ?? "below" }),
|
||||
keyValue: (c) => ({ mappings: (c.mappings as Array<Record<string, string>>)?.map((m) => ({ label: m.label, jsonPath: m.jsonPath, unit: m.unit ?? "" })) ?? [], kvLayout: c.layout ?? "list", kvColumns: c.columns ?? 2 }),
|
||||
table: (c) => ({ tablePath: c.tablePath, columns: c.columns ?? [], striped: c.striped ?? true, compact: c.compact ?? false }),
|
||||
statGrid: (c) => ({ statGridItems: c.items ?? [], statGridColumns: c.columns ?? 2, cardStyle: c.cardStyle ?? "filled" }),
|
||||
progressBars: (c) => ({ progressBars: (c.bars as Array<Record<string, unknown>>)?.map((b) => ({ label: b.label ?? "", valuePath: b.valuePath ?? "", maxPath: b.maxPath ?? "", unit: b.unit ?? "", color: b.color ?? "blue" })) ?? [], showPercentage: c.showPercentage ?? true, barSize: c.barSize ?? "md" }),
|
||||
statusIndicator: (c) => ({ statusItems: (c.items as Array<Record<string, unknown>>)?.map((i) => ({ label: i.label ?? "", jsonPath: i.jsonPath ?? "", goodValues: Array.isArray(i.goodValues) ? (i.goodValues as string[]).join(", ") : String(i.goodValues ?? "") })) ?? [], statusLayout: c.layout ?? "list", dotSize: c.dotSize ?? "md" }),
|
||||
countGrid: (c) => ({ countGridItems: c.items ?? [], countGridColumns: c.columns ?? 2, countValueSize: c.valueSize ?? "md" }),
|
||||
singleValue: (c) => ({
|
||||
jsonPath: c.jsonPath,
|
||||
label: c.label ?? "",
|
||||
unit: c.unit ?? "",
|
||||
valueSize: c.valueSize ?? "lg",
|
||||
labelPosition: c.labelPosition ?? "below",
|
||||
}),
|
||||
keyValue: (c) => ({
|
||||
mappings:
|
||||
(c.mappings as Array<Record<string, string>>)?.map((m) => ({
|
||||
label: m.label,
|
||||
jsonPath: m.jsonPath,
|
||||
unit: m.unit ?? "",
|
||||
})) ?? [],
|
||||
kvLayout: c.layout ?? "list",
|
||||
kvColumns: c.columns ?? 2,
|
||||
}),
|
||||
table: (c) => ({
|
||||
tablePath: c.tablePath,
|
||||
columns: c.columns ?? [],
|
||||
striped: c.striped ?? true,
|
||||
compact: c.compact ?? false,
|
||||
}),
|
||||
statGrid: (c) => ({
|
||||
statGridItems: c.items ?? [],
|
||||
statGridColumns: c.columns ?? 2,
|
||||
cardStyle: c.cardStyle ?? "filled",
|
||||
}),
|
||||
progressBars: (c) => ({
|
||||
progressBars:
|
||||
(c.bars as Array<Record<string, unknown>>)?.map((b) => ({
|
||||
label: b.label ?? "",
|
||||
valuePath: b.valuePath ?? "",
|
||||
maxPath: b.maxPath ?? "",
|
||||
unit: b.unit ?? "",
|
||||
color: b.color ?? "blue",
|
||||
})) ?? [],
|
||||
showPercentage: c.showPercentage ?? true,
|
||||
barSize: c.barSize ?? "md",
|
||||
}),
|
||||
statusIndicator: (c) => ({
|
||||
statusItems:
|
||||
(c.items as Array<Record<string, unknown>>)?.map((i) => ({
|
||||
label: i.label ?? "",
|
||||
jsonPath: i.jsonPath ?? "",
|
||||
goodValues: Array.isArray(i.goodValues) ? (i.goodValues as string[]).join(", ") : String(i.goodValues ?? ""),
|
||||
})) ?? [],
|
||||
statusLayout: c.layout ?? "list",
|
||||
dotSize: c.dotSize ?? "md",
|
||||
}),
|
||||
countGrid: (c) => ({
|
||||
countGridItems: c.items ?? [],
|
||||
countGridColumns: c.columns ?? 2,
|
||||
countValueSize: c.valueSize ?? "md",
|
||||
}),
|
||||
raw: (c) => ({ rawJsonPath: c.jsonPath ?? "$", rawMaxHeight: c.maxHeight ?? 300 }),
|
||||
actionButton: (c) => ({ buttonLabel: c.buttonLabel ?? "", buttonColor: c.buttonColor ?? "blue", confirmText: c.confirmText ?? "", successMessage: c.successMessage ?? "" }),
|
||||
actionButton: (c) => ({
|
||||
buttonLabel: c.buttonLabel ?? "",
|
||||
buttonColor: c.buttonColor ?? "blue",
|
||||
confirmText: c.confirmText ?? "",
|
||||
successMessage: c.successMessage ?? "",
|
||||
}),
|
||||
customJsx: (c) => ({ template: c.template ?? "" }),
|
||||
};
|
||||
|
||||
function importJsonToFormValues(imported: CustomWidgetImport): Partial<z.infer<typeof formSchema>> {
|
||||
const displayFields = importToFormValues[imported.displayType]?.(imported.displayConfig as unknown as Record<string, unknown>) ?? {};
|
||||
const displayFields =
|
||||
importToFormValues[imported.displayType]?.(imported.displayConfig as unknown as Record<string, unknown>) ?? {};
|
||||
return {
|
||||
name: imported.name,
|
||||
description: imported.description ?? "",
|
||||
@@ -719,14 +773,21 @@ export function CustomWidgetForm({ mode, initialValues, definitionId }: CustomWi
|
||||
const raw = e.clipboardData?.getData("text/plain");
|
||||
if (!raw) return;
|
||||
let parsed: unknown;
|
||||
try { parsed = JSON.parse(raw); } catch { return; }
|
||||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const result = customWidgetImportSchema.safeParse(parsed);
|
||||
if (!result.success) return;
|
||||
e.preventDefault();
|
||||
const formValues = importJsonToFormValues(result.data);
|
||||
form.setValues({ ...defaultCreateValues, ...formValues });
|
||||
form.clearErrors();
|
||||
showSuccessNotification({ title: t("action.paste"), message: t("notification.imported" as never, { name: result.data.name }) });
|
||||
showSuccessNotification({
|
||||
title: t("action.paste"),
|
||||
message: t("notification.imported" as never, { name: result.data.name }),
|
||||
});
|
||||
};
|
||||
document.addEventListener("paste", onPaste);
|
||||
return () => document.removeEventListener("paste", onPaste);
|
||||
|
||||
@@ -53,7 +53,11 @@ export const CustomWidgetList = ({ definitions }: CustomWidgetListProps) => {
|
||||
const raw = e.clipboardData?.getData("text/plain");
|
||||
if (!raw) return;
|
||||
let parsed: unknown;
|
||||
try { parsed = JSON.parse(raw); } catch { return; }
|
||||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const result = customWidgetImportSchema.safeParse(parsed);
|
||||
if (!result.success) return;
|
||||
e.preventDefault();
|
||||
@@ -79,8 +83,12 @@ export const CustomWidgetList = ({ definitions }: CustomWidgetListProps) => {
|
||||
<Table.Thead>
|
||||
<Table.Tr>
|
||||
<Table.Th>{t("table.name")}</Table.Th>
|
||||
<Table.Th w="30%" visibleFrom="sm">{t("table.url")}</Table.Th>
|
||||
<Table.Th w={120} visibleFrom="xs">{t("table.display")}</Table.Th>
|
||||
<Table.Th w="30%" visibleFrom="sm">
|
||||
{t("table.url")}
|
||||
</Table.Th>
|
||||
<Table.Th w={120} visibleFrom="xs">
|
||||
{t("table.display")}
|
||||
</Table.Th>
|
||||
<Table.Th w={90} />
|
||||
</Table.Tr>
|
||||
</Table.Thead>
|
||||
|
||||
Reference in new issue
Block a user