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
client/collections/board: don't show the Options input field when creating a new grouping attribute
Adorian Dorane44f9168888e
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsxindex c63354cb1a..4c635c47f6 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx@@ -5,6 +5,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import Component from "../../components/component";import { ParentComponent } from "../react/react_utils";+// i18next is never initialized here, so `t()` returns undefined and a row whose label is only a+// translated string renders without the `<label for>` the tests below look rows up by.+vi.mock("../../services/i18n", async (importOriginal) => ({+ ...(await importOriginal<typeof import("../../services/i18n")>()),+ t: (key: string) => key+}));+// The popup docks differently under the new layout, and the flag behind that is read once when the// module loads — so the two are exercised by loading it twice.const newLayout = vi.hoisted(() => ({ enabled: false }));@@ -198,6 +205,7 @@ describe("attribute detail popup naming", () => {expect(isSameShow(shown, opts({ ...shown, hideInheritance: true }))).toBe(false);expect(isSameShow(shown, opts({ ...shown, hideMultiplicity: true }))).toBe(false);expect(isSameShow(shown, opts({ ...shown, hideType: true }))).toBe(false);+ expect(isSameShow(shown, opts({ ...shown, hideTypeOptions: true }))).toBe(false);// ...but the very same request handed back is the host re-rendering around an untouched// popup, which every keystroke does — rebuilding the form there costs the focus and, with a@@ -346,10 +354,11 @@ describe("the rows the form carries", () => {!!host.querySelector(`[name="${name}"], [id^="${name}"], [for^="${name}"]`);}- it("carries the kind, multiplicity and inheritance rows by default", async () => {+ it("carries the kind, kind options, multiplicity and inheritance rows by default", async () => {const has = await renderForm();expect(has("attr-label-type")).toBe(true);+ expect(has("attr-select-options")).toBe(true);expect(has("attr-multiplicity")).toBe(true);expect(has("attr-inheritable")).toBe(true);});@@ -364,6 +373,18 @@ describe("the rows the form carries", () => {expect(has("attr-multiplicity")).toBe(true);expect(has("attr-inheritable")).toBe(true);});++ /** A host that fills the kind's own rows in itself, such as a board making the columns. */+ it("leaves out the select options alone for `hideTypeOptions`", async () => {+ const has = await renderForm({ hideTypeOptions: true });++ expect(has("attr-select-options")).toBe(false);+ // Only that row: the rest of the form is untouched.+ expect(has("attr-name")).toBe(true);+ expect(has("attr-label-type")).toBe(true);+ expect(has("attr-multiplicity")).toBe(true);+ expect(has("attr-inheritable")).toBe(true);+ });});const NO_OFFSET = { top: 0, left: 0 };diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 5e10c71f92..9d2e0b87ab 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -59,6 +59,11 @@ export interface AttributeDetailOpts {* that can only use one, such as a board grouping by a select.*/hideType?: boolean;+ /**+ * Leaves out the rows the chosen kind adds, such as the precision of a number or the options of a+ * select. For a host that fills them in itself, such as a board whose columns are the options.+ */+ hideTypeOptions?: boolean;/*** Places the popup beside this element instead of at `x`/`y`. For hosts whose attributes are shown* far from the note attributes pane the coordinates are otherwise resolved against, e.g. the@@ -339,6 +344,7 @@ export function isSameShow(previous: AttributeDetailOpts | null, next: Attribute&& previous.hideMultiplicity === next.hideMultiplicity&& previous.hideInheritance === next.hideInheritance&& previous.hideType === next.hideType+ && previous.hideTypeOptions === next.hideTypeOptions&& previous.attribute.noteId === next.attribute.noteId&& previous.attribute.type === next.attribute.type&& previous.attribute.name === next.attribute.name@@ -625,7 +631,8 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,</OptionsRow>)}- {attrType === "label-definition" && definition.labelType === "number" && (+ {attrType === "label-definition" && definition.labelType === "number"+ && !opts.hideTypeOptions && (<OptionsRowname="attr-number-precision"label={t("attribute_detail.precision")}@@ -645,7 +652,8 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,</OptionsRow>)}- {attrType === "label-definition" && definition.labelType === "select" && (+ {attrType === "label-definition" && definition.labelType === "select"+ && !opts.hideTypeOptions && (<OptionsRowname="attr-select-options"label={t("attribute_detail.select_options")}@@ -666,7 +674,7 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,</OptionsRow>)}- {attrType === "relation-definition" && (+ {attrType === "relation-definition" && !opts.hideTypeOptions && (<OptionsRowname="attr-inverse-relation"label={t("attribute_detail.inverse_relation")}diff --git a/apps/client/src/widgets/collections/board/group_by.spec.tsx b/apps/client/src/widgets/collections/board/group_by.spec.tsxindex a08ca08e8d..b6a997c34a 100644--- a/apps/client/src/widgets/collections/board/group_by.spec.tsx+++ b/apps/client/src/widgets/collections/board/group_by.spec.tsx@@ -203,9 +203,10 @@ describe("BoardGroupBy", () => {expect(mocks.detail.opts).toMatchObject({isOwned: true,focus: "name",- // A grouping is a select whose options are the columns, and a card stands in one of- // them: none of the three is the reader's to change here.+ // A grouping is a select whose options are the columns the board makes, and a card+ // stands in one of them: none of the four is the reader's to change here.hideType: true,+ hideTypeOptions: true,hideMultiplicity: true,hideInheritance: true,attribute: {diff --git a/apps/client/src/widgets/collections/board/group_by.tsx b/apps/client/src/widgets/collections/board/group_by.tsxindex 8051a49768..98db56eb3e 100644--- a/apps/client/src/widgets/collections/board/group_by.tsx+++ b/apps/client/src/widgets/collections/board/group_by.tsx@@ -64,9 +64,10 @@ export default function BoardGroupBy({ note, options, current, onSelect }: {x: event.pageX,y: event.pageY,focus: "name",- // The board answers for all three: a grouping is a promoted, inheritable select whose- // options are its columns, and a card stands in one column at a time.+ // The board answers for all four: a grouping is a promoted, inheritable select whose+ // options are the columns the board makes, and a card stands in one column at a time.hideType: true,+ hideTypeOptions: true,hideMultiplicity: true,hideInheritance: true});