Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(custom-fields): preserve serialized filters and normalize hidden values

Tinfb019013bbca
diff --git a/apps/api/src/custom-field/controllers/update-custom-field.ts b/apps/api/src/custom-field/controllers/update-custom-field.ts
index ab46c8249..5eec60cc0 100644
--- a/apps/api/src/custom-field/controllers/update-custom-field.ts
+++ b/apps/api/src/custom-field/controllers/update-custom-field.ts
@@ -123,9 +123,11 @@ export default async function updateCustomField(
defaultValue =
withoutHiddenOptions(defaultValue, field.type, hiddenOptions) || null;
}
- const needsMigration = oldOptions.some(
- (option) => replacements.get(option) !== option,
- );
+ const visibilityChanged =
+ JSON.stringify(hiddenOptions) !== JSON.stringify(field.hiddenOptions);
+ const needsMigration =
+ oldOptions.some((option) => replacements.get(option) !== option) ||
+ (field.type === "dropdown" && visibilityChanged);
// Keep application memory bounded while the definition lock serializes assignments.
let cursor: string | undefined;
while (needsMigration) {
diff --git a/apps/web/src/components/project/edit-custom-field-dialog.test.tsx b/apps/web/src/components/project/edit-custom-field-dialog.test.tsx
index 78489c338..ae7fff625 100644
--- a/apps/web/src/components/project/edit-custom-field-dialog.test.tsx
+++ b/apps/web/src/components/project/edit-custom-field-dialog.test.tsx
@@ -114,7 +114,7 @@ describe("edit custom field dialog", () => {
screen.getByRole("button", { name: "settings:customFields.saveButton" }),
);
expect(await screen.findByRole("alert")).toHaveTextContent(
- "Option is in use",
+ "settings:customFields.updateError",
);
expect(onClose).not.toHaveBeenCalled();
expect(screen.getAllByRole("textbox")).toHaveLength(3);
diff --git a/apps/web/src/components/project/edit-custom-field-dialog.tsx b/apps/web/src/components/project/edit-custom-field-dialog.tsx
index 10695881f..c843bca27 100644
--- a/apps/web/src/components/project/edit-custom-field-dialog.tsx
+++ b/apps/web/src/components/project/edit-custom-field-dialog.tsx
@@ -68,12 +68,8 @@ export default function EditCustomFieldDialog({
});
toast.success(t("settings:customFields.updateSuccess"));
onClose();
- } catch (error) {
- setError(
- error instanceof Error
- ? error.message
- : t("settings:customFields.updateError"),
- );
+ } catch {
+ setError(t("settings:customFields.updateError"));
}
}
diff --git a/apps/web/src/hooks/use-valid-custom-field-filters.test.tsx b/apps/web/src/hooks/use-valid-custom-field-filters.test.tsx
index db0c41bf8..dfb6c8019 100644
--- a/apps/web/src/hooks/use-valid-custom-field-filters.test.tsx
+++ b/apps/web/src/hooks/use-valid-custom-field-filters.test.tsx
@@ -14,6 +14,20 @@ vi.mock("./queries/custom-field/use-get-custom-fields-by-project", () => ({
default: () => ({ data: fields }),
}));
describe("persisted custom field filters", () => {
+ it("preserves serialized multiselect filters and drops combinations with obsolete choices", () => {
+ const valid = '["Alice", "Bob"]';
+ const old = '["Alice","Former"]';
+ const definitions = [
+ { id: "people", type: "multiselect", options: ["Alice", "Bob"] },
+ ];
+ expect(
+ reconcileCustomFieldFilters(
+ { people: [valid, old, "[]", "invalid"] },
+ definitions,
+ ),
+ ).toEqual({ people: [valid, "[]"] });
+ });
+
it("reconciles the backlog's non-null filter map without changing empty state", () => {
const empty = {};
expect(reconcileCustomFieldFilters(empty, [])).toBe(empty);
@@ -41,7 +55,7 @@ describe("persisted custom field filters", () => {
fields = [
{
id: "people",
- type: "multiselect",
+ type: "dropdown",
options: ["Alex", "Bob"],
hiddenOptions: ["Bob"],
},
diff --git a/apps/web/src/hooks/use-valid-custom-field-filters.ts b/apps/web/src/hooks/use-valid-custom-field-filters.ts
index 35a513ac9..ee71da042 100644
--- a/apps/web/src/hooks/use-valid-custom-field-filters.ts
+++ b/apps/web/src/hooks/use-valid-custom-field-filters.ts
@@ -32,11 +32,23 @@ export function reconcileCustomFieldFilters(
const field = fields.find((candidate) => candidate.id === id);
if (!field || !Array.isArray(values)) return [];
const options = field.options;
- const valid =
- (field.type === "dropdown" || field.type === "multiselect") &&
- Array.isArray(options)
- ? values.filter((value) => options.includes(value))
- : values;
+ const valid = values.filter((value) => {
+ if (!Array.isArray(options)) return true;
+ if (field.type === "dropdown") return options.includes(value);
+ if (field.type !== "multiselect") return true;
+ try {
+ const selected: unknown = JSON.parse(value);
+ return (
+ Array.isArray(selected) &&
+ selected.every(
+ (option) =>
+ typeof option === "string" && options.includes(option),
+ )
+ );
+ } catch {
+ return false;
+ }
+ });
return valid.length ? [[id, valid]] : [];
}),
);
diff --git a/tests/api-integration/custom-field-edit.test.ts b/tests/api-integration/custom-field-edit.test.ts
index 543e9f626..9a3a8e6a2 100644
--- a/tests/api-integration/custom-field-edit.test.ts
+++ b/tests/api-integration/custom-field-edit.test.ts
@@ -102,7 +102,7 @@ describe("custom field editing", () => {
});
it("omits hidden whitespace-padded legacy dropdown values when duplicating", async () => {
- const { app, field, task, update } = await fixture("dropdown");
+ const { app, field, task, update, readValue } = await fixture("dropdown");
await db
.update(schema.customFieldValueTable)
.set({ value: " Alice " })
@@ -118,6 +118,7 @@ describe("custom field editing", () => {
})
).status,
).toBe(200);
+ expect(await readValue()).toBe("Alice");
const response = await app.request(`/api/task/duplicate/${task.id}`, {
method: "POST",
headers: { "Content-Type": "application/json" },