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/switchable card grouping: tweak the way "Status" is listed
Adorian Doranc4981f781a94
diff --git a/apps/client/src/widgets/collections/board/group_by.spec.ts b/apps/client/src/widgets/collections/board/group_by.spec.tsindex c396e6f71e..6e6fe1a52a 100644--- a/apps/client/src/widgets/collections/board/group_by.spec.ts+++ b/apps/client/src/widgets/collections/board/group_by.spec.ts@@ -43,22 +43,24 @@ describe("groupingOptions", () => {]);});- it("offers them in the order the reader arranged the promoted attributes", () => {+ 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([ "priority", "status" ]);+ .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")[0]).toEqual({+ 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")[0])+ expect(groupingOptions(board, undefined, "severity")[1]).toEqual({ value: "severity", title: "severity" });});@@ -73,11 +75,32 @@ describe("groupingOptions", () => {.toEqual([ "status", "priority" ]);});- it("offers nothing but the grouping in force on a board defining no selects", () => {+ /**+ * 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: "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.tsx b/apps/client/src/widgets/collections/board/group_by.tsxindex df29e2194a..6853c17b78 100644--- a/apps/client/src/widgets/collections/board/group_by.tsx+++ b/apps/client/src/widgets/collections/board/group_by.tsx@@ -5,7 +5,9 @@ import { t } from "../../../services/i18n";import Dropdown from "../../react/Dropdown";import { FormListItem } from "../../react/FormList";import Icon from "../../react/Icon";-import { type PromotedAttributeSetting, resolvePromotedAttributes } from "../promoted_attributes";+import {+ type PromotedAttribute, type PromotedAttributeSetting, resolvePromotedAttributes+} from "../promoted_attributes";/** One attribute the board offers to group its cards by. */export interface GroupingOption {@@ -47,8 +49,8 @@ export default function BoardGroupBy({ options, current, onSelect }: {}/**- * The attributes the board offers to group by: the select fields it defines, and the grouping in- * force whatever defines it.+ * The attributes the board offers to group by: the default grouping, the select fields it defines,+ * and the grouping in force whatever defines it.** Only a select says what its columns are, so nothing else can be grouped by from here. The current* grouping is listed all the same — a board grouping by a relation, or by a label nobody defined,@@ -71,5 +73,27 @@ export function groupingOptions(options.unshift({ value: current, title: attribute?.title ?? current.replace(/^~/, "") });}+ // The default grouping leads, and is offered even where nothing defines it: it is what a board+ // groups by when `#board:groupBy` names nothing, so switching away is never a step with no way+ // back.+ const listed = options.findIndex(option => option.value === DEFAULT_BOARD_GROUP_BY);+ if (listed >= 0) {+ options.splice(listed, 1);+ }+ options.unshift({ value: DEFAULT_BOARD_GROUP_BY, title: defaultGroupingTitle(defined) });+return options;}++/**+ * What the default grouping is listed as: the alias its definition gives, or the stock word.+ *+ * Named rather than left to read as the label it is, which every other grouping is named by: the+ * board writes the same word into the definition it creates for a new board, so a board that has+ * one and a board that has none are listed alike.+ */+function defaultGroupingTitle(defined: PromotedAttribute[]) {+ const status = defined.find(attribute =>+ attribute.type === "label" && attribute.name === DEFAULT_BOARD_GROUP_BY);+ return status?.promotedAlias || t("board_view.status-alias");+}diff --git a/apps/client/src/widgets/collections/promoted_attributes.spec.ts b/apps/client/src/widgets/collections/promoted_attributes.spec.tsindex 88a1f0fca5..f57377bad7 100644--- a/apps/client/src/widgets/collections/promoted_attributes.spec.ts+++ b/apps/client/src/widgets/collections/promoted_attributes.spec.ts@@ -55,6 +55,7 @@ describe("resolvePromotedAttributes", () => {definitionName: "label:dueDate",type: "label",title: "Due",+ promotedAlias: "Due",hidden: false,definitionValue: "promoted,single,text",isOwned: true,@@ -63,7 +64,8 @@ describe("resolvePromotedAttributes", () => {// No alias, so the name is prefixed by the kind that defines it.expect.objectContaining({name: "requiresResearch",- title: "promoted_attributes.label_name:requiresResearch"+ title: "promoted_attributes.label_name:requiresResearch",+ promotedAlias: undefined}),expect.objectContaining({name: "owner",diff --git a/apps/client/src/widgets/collections/promoted_attributes.ts b/apps/client/src/widgets/collections/promoted_attributes.tsindex e0da88b19d..ec8144d921 100644--- a/apps/client/src/widgets/collections/promoted_attributes.ts+++ b/apps/client/src/widgets/collections/promoted_attributes.ts@@ -24,6 +24,8 @@ export interface PromotedAttribute {* where it gives none. See {@link defaultTitle}.*/title: string;+ /** The name the definition gives it, absent where it gives none. */+ promotedAlias?: string;/** Whether the attribute is kept off the items. */hidden: boolean;/** The definition as stored, which the attribute editor is handed to edit. */@@ -76,6 +78,7 @@ export function resolvePromotedAttributes(definitionName: definition.name,type,title: parsed?.promotedAlias || defaultTitle(type, name),+ promotedAlias: parsed?.promotedAlias,labelType: parsed?.labelType,selectOptions: parsed?.selectOptions,hidden: false,