fix: repair stale custom widget options

This commit is contained in:
Thomas Camlong authored and ajnart committed 2026-08-13 19:51:25 +02:00
1 parent 03ebb8c2db
commit c2cf25b4fb
5 files changed
+81 -10

No files matched your search

@@ -12,6 +12,18 @@ export function getCustomWidgetDefaultOptions(
return Object.fromEntries(Object.entries(options).map(([name, option]) => [name, option.default]));
}
export function normalizeCustomWidgetOptions(
options: CustomWidgetOptions,
value: Record<string, unknown>,
): Record<string, unknown> {
return Object.fromEntries(
Object.entries(options).map(([name, option]) => [
name,
getCustomWidgetOptionValueIssue(option, value[name]) ? option.default : value[name],
]),
);
}
export function validateCustomWidgetOptions(
options: CustomWidgetOptions,
value: Record<string, unknown>,
@@ -5,6 +5,7 @@ import {
customWidgetOptionControls,
customWidgetOptionSchema,
getCustomWidgetDefaultOptions,
normalizeCustomWidgetOptions,
validateCustomWidgetOptions,
} from "../core";
@@ -69,6 +70,29 @@ describe("lean Custom Widget options", () => {
expect(validateCustomWidgetOptions(options, configuration)).toEqual([]);
});
it("replaces stale values with current defaults", () => {
const options = customWidgetDefinitionSchema.parse({
$schema: "homarr-custom-widget-v2",
name: "Updated options",
sources: {},
requests: {},
options: {
limit: { label: "Limit", control: "slider", default: 5, min: 1, max: 10 },
label: { label: "Label", control: "text", default: "Default" },
},
template: "<Text>{options.limit}</Text>",
}).options;
const normalized = normalizeCustomWidgetOptions(options, {
limit: "5",
label: "Custom",
removed: true,
});
expect(normalized).toEqual({ limit: 5, label: "Custom" });
expect(validateCustomWidgetOptions(options, normalized)).toEqual([]);
});
it("rejects duplicate static choice values", () => {
expect(
customWidgetOptionSchema.safeParse({