Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(collections/table): show an unset flag as false
Elian Doran7d98d509d9b5
diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.tsindex 8f71d43973..0ac8608592 100644--- a/apps/client/src/widgets/collections/table/columns.spec.ts+++ b/apps/client/src/widgets/collections/table/columns.spec.ts@@ -253,7 +253,7 @@ describe("buildColumnDefinitions — typed columns", () => {expect(url({ getValue: () => "https://example.com" } as CellComponent)).toBe("https://example.com");});- it("shows a single flag as the chip a set of flags wears, and an unset cell as nothing", () => {+ it("shows a single flag as the chip a set of flags wears, and an unset one as false", () => {const [ column ] = buildColumnDefinitions({info: [ { name: "done", type: "boolean" } ],movableRows: false,@@ -272,11 +272,10 @@ describe("buildColumnDefinitions — typed columns", () => {expect(format(set).querySelector(".tn-chip")?.className).toContain("label-flag-chip-set");expect(format(set).querySelector(".tn-icon")?.getAttribute("title")).toBe("true");}- expect(format(false).querySelector(".tn-chip")?.className).toContain("label-flag-chip-unset");-- // An unset cell holds no flag at all, so it wears no chip either.- for (const empty of [ "", undefined, null ]) {- expect(format(empty).querySelector(".tn-chip")).toBeNull();+ // A note without the label reads as false, as the promoted checkbox shows it unticked.+ for (const unset of [ "false", false, "", undefined, null ]) {+ expect(format(unset).querySelector(".tn-chip")?.className).toContain("label-flag-chip-unset");+ expect(format(unset).querySelector(".tn-icon")?.getAttribute("title")).toBe("false");}});});diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsxindex 8344b08340..ba637d5ec5 100644--- a/apps/client/src/widgets/collections/table/columns.tsx+++ b/apps/client/src/widgets/collections/table/columns.tsx@@ -640,9 +640,9 @@ function ColorFormatter({ cell }: FormatterOpts) {function FlagFormatter({ cell }: FormatterOpts) {const value = cell.getValue();// A stored label arrives as the text "true"/"false", but one just toggled through the tickCross- // editor is a real boolean; the chip reads the stored spelling of either.- const flag = typeof value === "boolean" ? String(value) : value;- if (typeof flag !== "string" || !flag) return <span />;+ // editor is a real boolean. A note without the label reads as false, as the promoted checkbox+ // shows it unticked.+ const flag = value === true || value === "true" ? "true" : "false";return <LabelValueChips values={[ flag ]} labelType="boolean" />;}