Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board/switchable card grouping: add a quick way for the user to create new grouping attributes

Adorian Doran287eb74b4594
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx
similarity index 80%
rename from apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts
rename to apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx
index 5c76f8f102..c63354cb1a 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.tsx
@@ -1,5 +1,10 @@
+import { render } from "preact";
+import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import Component from "../../components/component";
+import { ParentComponent } from "../react/react_utils";
+
// 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 }));
@@ -8,10 +13,30 @@ vi.mock("../../services/experimental_features", async (importOriginal) => ({
isExperimentalFeatureEnabled: () => newLayout.enabled
}));
+// The form fetches the names a definition can complete against and the notes already carrying the
+// attribute. Neither is what these tests are about, and an unanswered request rejects into the run.
+vi.mock("../../services/server", () => ({
+ default: {
+ get: vi.fn(async () => []),
+ post: vi.fn(async () => ({ results: [], count: 0 }))
+ }
+}));
+
import type { AttributeDetailOpts } from "./attribute_detail";
const VIEWPORT = { width: 1200, height: 800 };
+// Every popup these tests render counts the notes already carrying the attribute, and reads the
+// active context to name their paths. The app is never started here, so it is given one with
+// nothing hoisted rather than left to reject into the run. Mocked rather than assigned: the tests
+// below reset the module registry, which would hand the popup a fresh, unstarted context.
+vi.mock("../../components/app_context", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("../../components/app_context")>();
+ (actual.default as { tabManager?: unknown }).tabManager =
+ { getActiveContext: () => undefined };
+ return actual;
+});
+
describe("attribute detail popup positioning", () => {
beforeEach(() => {
sizeViewport(VIEWPORT.width, VIEWPORT.height);
@@ -171,6 +196,8 @@ describe("attribute detail popup naming", () => {
expect(isSameShow(shown, opts({ ...shown, focus: "name" }))).toBe(false);
// Which rows the form carries is part of what it would show.
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);
// ...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
@@ -275,6 +302,70 @@ describe("related notes menu", () => {
});
});
+describe("the rows the form carries", () => {
+ let mounted: HTMLElement | undefined;
+
+ afterEach(() => {
+ if (mounted) {
+ render(null, mounted);
+ mounted.remove();
+ mounted = undefined;
+ }
+ });
+
+ /** Renders the form on a definition, which is where the kind and multiplicity rows live. */
+ async function renderForm(overrides: Partial<AttributeDetailOpts> = {}) {
+ const { AttributeForm } = await import("./attribute_detail");
+ const host = document.createElement("div");
+ mounted = host;
+ document.body.appendChild(host);
+
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <AttributeForm
+ opts={opts({
+ attribute: {
+ type: "label",
+ name: "label:severity",
+ value: "promoted,single,select"
+ },
+ ...overrides
+ })}
+ attrType="label-definition"
+ onCancel={() => {}}
+ />
+ </ParentComponent.Provider>,
+ host
+ );
+ });
+
+ // `OptionsRow` names the control it wraps, labelling it by a unique id built from that
+ // name.
+ return (name: string) =>
+ !!host.querySelector(`[name="${name}"], [id^="${name}"], [for^="${name}"]`);
+ }
+
+ it("carries the kind, multiplicity and inheritance rows by default", async () => {
+ const has = await renderForm();
+
+ expect(has("attr-label-type")).toBe(true);
+ expect(has("attr-multiplicity")).toBe(true);
+ expect(has("attr-inheritable")).toBe(true);
+ });
+
+ /** A host that can only use one kind, such as a board grouping by a select, leaves it out. */
+ it("leaves out the kind row alone for `hideType`", async () => {
+ const has = await renderForm({ hideType: true });
+
+ expect(has("attr-label-type")).toBe(false);
+ // Only that row: the rest of the form is untouched.
+ expect(has("attr-name")).toBe(true);
+ expect(has("attr-multiplicity")).toBe(true);
+ expect(has("attr-inheritable")).toBe(true);
+ });
+});
+
const NO_OFFSET = { top: 0, left: 0 };
function opts(overrides: Partial<AttributeDetailOpts>): AttributeDetailOpts {
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index fb402c1601..5e10c71f92 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -54,6 +54,11 @@ export interface AttributeDetailOpts {
* collection whose attributes are all inheritable and promoted.
*/
hideInheritance?: boolean;
+ /**
+ * Leaves out the kind dropdown, holding the definition to the kind it was opened on. For a host
+ * that can only use one, such as a board grouping by a select.
+ */
+ hideType?: 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
@@ -333,6 +338,7 @@ export function isSameShow(previous: AttributeDetailOpts | null, next: Attribute
&& previous.isOwned === next.isOwned
&& previous.hideMultiplicity === next.hideMultiplicity
&& previous.hideInheritance === next.hideInheritance
+ && previous.hideType === next.hideType
&& previous.attribute.noteId === next.attribute.noteId
&& previous.attribute.type === next.attribute.type
&& previous.attribute.name === next.attribute.name
@@ -598,7 +604,7 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,
{/* No description: the values name themselves, and what they do to the field is plain
enough once one is picked. */}
- {isDefinition(attrType) && (
+ {isDefinition(attrType) && !opts.hideType && (
<OptionsRow name="attr-label-type" label={t("attribute_detail.label_type")}>
<FormDropdownList
className="attr-input-label-type"
diff --git a/apps/client/src/widgets/collections/board/group_by.spec.ts b/apps/client/src/widgets/collections/board/group_by.spec.ts
deleted file mode 100644
index 6e6fe1a52a..0000000000
--- a/apps/client/src/widgets/collections/board/group_by.spec.ts
+++ /dev/null
@@ -1,106 +0,0 @@
-import $ from "jquery";
-import { beforeEach, describe, expect, it, vi } from "vitest";
-
-import noteAttributeCache from "../../../services/note_attribute_cache";
-import { buildNote } from "../../../test/easy-froca";
-import { groupingOptions } from "./group_by";
-
-// i18next is never initialised under test, so a translated title would come back undefined. What is
-// interpolated is carried along, for the titles these tests are about.
-vi.mock("../../../services/i18n", () => ({
- t: (key: string, opts?: Record<string, unknown>) =>
- opts ? `${key}:${JSON.stringify(opts)}` : key,
- translationsInitializedPromise: $.Deferred().resolve()
-}));
-
-/** A board defining two selects, a text label and a relation, all promoted to its cards. */
-function buildBoard(extra: Record<string, string> = {}) {
- delete noteAttributeCache.attributes["boardNote"];
-
- return buildNote({
- id: "boardNote",
- title: "Board",
- "#viewType": "board",
- "#label:status(inheritable)": "promoted,alias=Status,single,select,options=To Do;Done",
- "#label:priority(inheritable)": "promoted,alias=Priority,single,select,options=High;Low",
- "#label:notes(inheritable)": "promoted,single,text",
- "#relation:assignee(inheritable)": "promoted,single",
- ...extra
- });
-}
-
-describe("groupingOptions", () => {
- let board: ReturnType<typeof buildNote>;
-
- beforeEach(() => {
- board = buildBoard();
- });
-
- it("offers the select fields and nothing else", () => {
- expect(groupingOptions(board, undefined, "status")).toEqual([
- { value: "status", title: "Status" },
- { value: "priority", title: "Priority" }
- ]);
- });
-
- it("leads with the default grouping, whatever the reader arranged", () => {
- const settings = [ { name: "priority" }, { name: "status" } ];
-
- expect(groupingOptions(board, settings, "status").map(option => option.value))
- .toEqual([ "status", "priority" ]);
- expect(groupingOptions(board, settings, "priority").map(option => option.value))
- .toEqual([ "status", "priority" ]);
- });
-
- it("names the grouping in force even where no select defines it", () => {
- // A relation cannot be switched to from here, but a board on one still has to say so.
- expect(groupingOptions(board, undefined, "~assignee")[1]).toEqual({
- value: "~assignee",
- title: 'promoted_attributes.relation_name:{"name":"assignee"}'
- });
-
- // A label nobody defined, which reads as the name the board groups by.
- expect(groupingOptions(board, undefined, "severity")[1])
- .toEqual({ value: "severity", title: "severity" });
- });
-
- it("lists the grouping in force once, whichever way it is written", () => {
- const values = groupingOptions(board, undefined, "#priority").map(option => option.value);
-
- expect(values).toEqual([ "status", "priority" ]);
- });
-
- it("falls back to the default grouping for a board naming none", () => {
- expect(groupingOptions(board, undefined, "").map(option => option.value))
- .toEqual([ "status", "priority" ]);
- });
-
- /**
- * A board can be switched to something else and have nothing defining `#status`, which would
- * otherwise leave the reader no way back to what the board groups by out of the box.
- */
- it("offers the default grouping on a board that defines nothing at all", () => {
- delete noteAttributeCache.attributes["plainBoard"];
- const plain = buildNote({ id: "plainBoard", title: "Board", "#viewType": "board" });
-
- expect(groupingOptions(plain, undefined, "status"))
- .toEqual([ { value: "status", title: "board_view.status-alias" } ]);
- expect(groupingOptions(plain, undefined, "severity")).toEqual([
- { value: "status", title: "board_view.status-alias" },
- { value: "severity", title: "severity" }
- ]);
- });
-
- it("names the default grouping with the stock word where its definition gives no alias", () => {
- delete noteAttributeCache.attributes["plainBoard"];
- const plain = buildNote({
- id: "plainBoard",
- title: "Board",
- "#viewType": "board",
- "#label:status(inheritable)": "promoted,single,select,options=To Do;Done"
- });
-
- expect(groupingOptions(plain, undefined, "status"))
- .toEqual([ { value: "status", title: "board_view.status-alias" } ]);
- });
-});
diff --git a/apps/client/src/widgets/collections/board/group_by.spec.tsx b/apps/client/src/widgets/collections/board/group_by.spec.tsx
new file mode 100644
index 0000000000..c1de241334
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/group_by.spec.tsx
@@ -0,0 +1,255 @@
+import { render } from "preact";
+import { act } from "preact/test-utils";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import $ from "jquery";
+
+import Component from "../../../components/component";
+import type FNote from "../../../entities/fnote";
+import type { Attribute } from "../../../services/attribute_parser";
+import type { AttributeDetailOpts } from "../../attribute_widgets/attribute_detail";
+import { ParentComponent } from "../../react/react_utils";
+import BoardGroupBy, { groupingOptions } from "./group_by";
+
+// i18next is never initialised under test, so a translated title would come back undefined. What is
+// interpolated is carried along, for the titles these tests are about.
+vi.mock("../../../services/i18n", () => ({
+ t: (key: string, opts?: Record<string, unknown>) =>
+ opts ? `${key}:${JSON.stringify(opts)}` : key,
+ translationsInitializedPromise: Promise.resolve()
+}));
+
+const mocks = vi.hoisted(() => ({
+ setLabel: vi.fn(async () => {}),
+ /** The editor the dropdown opens, which the test drives through the callbacks it was given. */
+ detail: { opts: null as AttributeDetailOpts | null, callbacks: {} as Record<string, Function> }
+}));
+
+vi.mock("../../../services/attributes", () => ({
+ default: { setLabel: mocks.setLabel, isAffecting: () => true }
+}));
+
+// The editor is tested where it lives; what the dropdown answers for is what it hands over and what
+// it writes once the editor reports a definition.
+vi.mock("../../attribute_widgets/attribute_detail", () => ({
+ AttributeDetail: (props: { opts: AttributeDetailOpts | null }) => {
+ mocks.detail.opts = props.opts;
+ mocks.detail.callbacks = props as unknown as Record<string, Function>;
+ return props.opts ? <div className="attribute-detail-stub" /> : null;
+ }
+}));
+
+/** A definition as the board note carries it. */
+function definition(name: string, { alias, labelType }: {
+ alias?: string;
+ labelType?: string;
+} = {}) {
+ return {
+ name,
+ value: `promoted,single,${labelType ?? "text"}`,
+ noteId: "board1",
+ isInheritable: true,
+ getDefinition: () => ({ isPromoted: true, promotedAlias: alias, labelType })
+ };
+}
+
+/** A board defining two selects, a text label and a relation, all promoted to its cards. */
+const DEFINED = [
+ definition("label:status", { alias: "Status", labelType: "select" }),
+ definition("label:priority", { alias: "Priority", labelType: "select" }),
+ definition("label:notes"),
+ definition("relation:assignee")
+];
+
+function board(defined = DEFINED) {
+ return {
+ noteId: "board1",
+ getAttributeDefinitions: () => defined
+ } as unknown as FNote;
+}
+
+describe("groupingOptions", () => {
+ it("offers the select fields and nothing else", () => {
+ expect(groupingOptions(board(), undefined, "status")).toEqual([
+ { value: "status", title: "Status" },
+ { value: "priority", title: "Priority" }
+ ]);
+ });
+
+ it("leads with the default grouping, whatever the reader arranged", () => {
+ const settings = [ { name: "priority" }, { name: "status" } ];
+
+ expect(groupingOptions(board(), settings, "status").map(option => option.value))
+ .toEqual([ "status", "priority" ]);
+ expect(groupingOptions(board(), settings, "priority").map(option => option.value))
+ .toEqual([ "status", "priority" ]);
+ });
+
+ it("names the grouping in force even where no select defines it", () => {
+ // A relation cannot be switched to from here, but a board on one still has to say so.
+ expect(groupingOptions(board(), undefined, "~assignee")[1]).toEqual({
+ value: "~assignee",
+ title: 'promoted_attributes.relation_name:{"name":"assignee"}'
+ });
+
+ // A label nobody defined, which reads as the name the board groups by.
+ expect(groupingOptions(board(), undefined, "severity")[1])
+ .toEqual({ value: "severity", title: "severity" });
+ });
+
+ it("lists the grouping in force once, whichever way it is written", () => {
+ expect(groupingOptions(board(), undefined, "#priority").map(option => option.value))
+ .toEqual([ "status", "priority" ]);
+ });
+
+ it("falls back to the default grouping for a board naming none", () => {
+ expect(groupingOptions(board(), undefined, "").map(option => option.value))
+ .toEqual([ "status", "priority" ]);
+ });
+
+ /**
+ * A board can be switched to something else and have nothing defining `#status`, which would
+ * otherwise leave the reader no way back to what the board groups by out of the box.
+ */
+ it("offers the default grouping on a board that defines nothing at all", () => {
+ expect(groupingOptions(board([]), undefined, "status"))
+ .toEqual([ { value: "status", title: "board_view.status-alias" } ]);
+ expect(groupingOptions(board([]), undefined, "severity")).toEqual([
+ { value: "status", title: "board_view.status-alias" },
+ { value: "severity", title: "severity" }
+ ]);
+ });
+
+ it("names the default grouping with the stock word where its definition gives no alias", () => {
+ const defined = [ definition("label:status", { labelType: "select" }) ];
+
+ expect(groupingOptions(board(defined), undefined, "status"))
+ .toEqual([ { value: "status", title: "board_view.status-alias" } ]);
+ });
+});
+
+describe("BoardGroupBy", () => {
+ let container: HTMLElement | undefined;
+
+ afterEach(() => {
+ mocks.setLabel.mockClear();
+ mocks.detail.opts = null;
+ if (container) {
+ render(null, container);
+ container.remove();
+ container = undefined;
+ }
+ });
+
+ /** Renders the dropdown with its menu open, which is where its items are drawn. */
+ async function setup(current = "status") {
+ const onSelect = vi.fn();
+ const mountPoint = document.createElement("div");
+ container = mountPoint;
+ document.body.appendChild(mountPoint);
+
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <BoardGroupBy
+ note={board()}
+ options={groupingOptions(board(), undefined, current)}
+ current={current}
+ onSelect={onSelect}
+ />
+ </ParentComponent.Provider>,
+ mountPoint
+ );
+ });
+
+ // Bootstrap does not open a menu under happy-dom, and the items are drawn only once it is.
+ await act(async () => {
+ $(mountPoint.querySelector(".dropdown") as HTMLElement).trigger("show.bs.dropdown");
+ });
+
+ return { mountPoint, onSelect };
+ }
+
+ const items = (mountPoint: HTMLElement) =>
+ [ ...mountPoint.querySelectorAll(".dropdown-menu .dropdown-item") ];
+
+ it("offers making a grouping after the ones the board has, behind a divider", async () => {
+ const { mountPoint } = await setup();
+
+ expect(items(mountPoint).map(item => item.textContent?.trim())).toEqual([
+ "Status", "Priority", "promoted_attributes.create_attribute"
+ ]);
+ // Set apart from the groupings above it: the entry makes one rather than picking one.
+ const menu = [ ...(mountPoint.querySelector(".dropdown-menu")?.children ?? []) ];
+ const divider = menu.findIndex(child => child.classList.contains("dropdown-divider"));
+ const create = menu.findIndex(child => child.classList.contains("board-group-by-create"));
+ expect(divider).toBeGreaterThan(0);
+ expect(create).toBe(divider + 1);
+ });
+
+ it("opens the editor on a promoted, inheritable select that cannot be changed", async () => {
+ const { mountPoint } = await setup();
+
+ await act(async () => {
+ mountPoint.querySelector<HTMLElement>(".board-group-by-create")?.click();
+ });
+
+ 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.
+ hideType: true,
+ hideMultiplicity: true,
+ hideInheritance: true,
+ attribute: {
+ type: "label",
+ value: "promoted,single,select",
+ isInheritable: true
+ }
+ });
+ });
+
+ it("writes what the editor was left holding, and groups by it", async () => {
+ const { mountPoint, onSelect } = await setup();
+
+ await act(async () => {
+ mountPoint.querySelector<HTMLElement>(".board-group-by-create")?.click();
+ });
+
+ const made: Attribute = {
+ type: "label",
+ name: "label:severity",
+ value: "promoted,single,select,options=Minor;Major",
+ isInheritable: true
+ };
+ await act(async () => {
+ mocks.detail.callbacks.onAttributesChanged([ made ]);
+ await mocks.detail.callbacks.onSaveAndClose();
+ });
+
+ expect(mocks.setLabel).toHaveBeenCalledWith(
+ "board1", "label:severity", "promoted,single,select,options=Minor;Major", true);
+ // Made to be grouped by, so the board moves to it rather than leaving a second step.
+ expect(onSelect).toHaveBeenCalledWith("severity");
+ expect(mocks.detail.opts).toBeNull();
+ });
+
+ it("writes nothing for an editor closed without a name", async () => {
+ const { mountPoint, onSelect } = await setup();
+
+ await act(async () => {
+ mountPoint.querySelector<HTMLElement>(".board-group-by-create")?.click();
+ });
+
+ await act(async () => {
+ mocks.detail.callbacks.onAttributesChanged([
+ { type: "label", name: "label:", value: "promoted,single,select" }
+ ]);
+ await mocks.detail.callbacks.onSaveAndClose();
+ });
+
+ expect(mocks.setLabel).not.toHaveBeenCalled();
+ expect(onSelect).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/group_by.tsx b/apps/client/src/widgets/collections/board/group_by.tsx
index 6853c17b78..62c07b9599 100644
--- a/apps/client/src/widgets/collections/board/group_by.tsx
+++ b/apps/client/src/widgets/collections/board/group_by.tsx
@@ -1,9 +1,17 @@
import { DEFAULT_BOARD_GROUP_BY, normalizeBoardGroupBy } from "@triliumnext/commons";
+import { createPortal } from "preact/compat";
+import { useCallback, useRef, useState } from "preact/hooks";
+
import type FNote from "../../../entities/fnote";
+import type { Attribute } from "../../../services/attribute_parser";
+import attributes from "../../../services/attributes";
import { t } from "../../../services/i18n";
+import {
+ AttributeDetail, type AttributeDetailOpts
+} from "../../attribute_widgets/attribute_detail";
import Dropdown from "../../react/Dropdown";
-import { FormListItem } from "../../react/FormList";
+import { FormDropdownDivider, FormListItem } from "../../react/FormList";
import Icon from "../../react/Icon";
import {
type PromotedAttribute, type PromotedAttributeSetting, resolvePromotedAttributes
@@ -17,34 +25,109 @@ export interface GroupingOption {
title: string;
}
-/** Switches which attribute the board's columns are made from. */
-export default function BoardGroupBy({ options, current, onSelect }: {
+/**
+ * What a grouping made here starts from. The reader names it and gives its columns in the editor.
+ *
+ * A grouping is a select: its options are the board's columns, so no other kind describes one. It
+ * is promoted because the column a card sits in is the point of the board, inheritable so that the
+ * cards carry it, and single because a card stands in one column.
+ */
+const NEW_GROUPING: Attribute = {
+ type: "label",
+ name: "label:myLabel",
+ value: "promoted,single,select",
+ isInheritable: true
+};
+
+/** Switches which attribute the board's columns are made from, and makes new ones. */
+export default function BoardGroupBy({ note, options, current, onSelect }: {
+ /** The board note, which carries the definitions and any made here. */
+ note: FNote;
options: GroupingOption[];
/** The grouping in force, as {@link groupingOptions} spells its value. */
current: string;
onSelect: (groupBy: string) => void;
}) {
+ const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);
+ /** The definition the editor last reported, which {@link save} writes. */
+ const edited = useRef<Attribute>();
const selected = options.find(option => option.value === current);
+ const create = useCallback((event: MouseEvent) => {
+ const definition = { ...NEW_GROUPING };
+ edited.current = undefined;
+ setDetail({
+ attribute: definition,
+ allAttributes: [ definition ],
+ isOwned: true,
+ 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.
+ hideType: true,
+ hideMultiplicity: true,
+ hideInheritance: true
+ });
+ }, []);
+
+ /** Writes the definition the editor was left holding, and groups by it. */
+ const save = useCallback(async () => {
+ const definition = edited.current;
+ setDetail(null);
+
+ const [ , name ] = definition?.name.split(":", 2) ?? [];
+ if (!definition || !name) {
+ return;
+ }
+
+ await attributes.setLabel(
+ note.noteId, definition.name, definition.value, definition.isInheritable);
+ onSelect(name);
+ }, [ note, onSelect ]);
+
return (
- <Dropdown
- className="board-group-by"
- noDropdownListStyle
- title={t("board_view.group-by")}
- text={<>
- <Icon icon="bx bx-category-alt" />&nbsp;
- {selected?.title ?? current}
- </>}
- >
- {options.map(option => (
+ <>
+ <Dropdown
+ className="board-group-by"
+ noDropdownListStyle
+ title={t("board_view.group-by")}
+ text={<>
+ <Icon icon="bx bx-category-alt" />&nbsp;
+ {selected?.title ?? current}
+ </>}
+ >
+ {options.map(option => (
+ <FormListItem
+ key={option.value}
+ onClick={() => onSelect(option.value)}
+ selected={option.value === current}
+ disabled={option.value === current}
+ >{option.title}</FormListItem>
+ ))}
+
+ <FormDropdownDivider />
+
<FormListItem
- key={option.value}
- onClick={() => onSelect(option.value)}
- selected={option.value === current}
- disabled={option.value === current}
- >{option.title}</FormListItem>
- ))}
- </Dropdown>
+ className="board-group-by-create"
+ icon="bx bx-plus"
+ onClick={create}
+ >{t("promoted_attributes.create_attribute")}</FormListItem>
+ </Dropdown>
+
+ {/* Outside the menu, which takes its items down as it closes: the editor is opened by
+ one of them and outlives it. */}
+ {createPortal(
+ <AttributeDetail
+ opts={detail}
+ currentNoteId={note.noteId}
+ onDismiss={() => setDetail(null)}
+ onCancel={() => setDetail(null)}
+ onAttributesChanged={([ definition ]) => { edited.current = definition; }}
+ onSaveAndClose={save}
+ />,
+ document.body)}
+ </>
);
}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 553154b6aa..47803820b4 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -1029,6 +1029,7 @@ export default function BoardView({
note={parentNote}
rightChildren={<>
<BoardGroupBy
+ note={parentNote}
options={groupingChoices}
current={currentGrouping}
onSelect={setRequestedGroupBy}