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: honor the board default card sorting option
Adorian Doran15a47d3b0dd0
diff --git a/apps/client/src/widgets/collections/SortDropdown.tsx b/apps/client/src/widgets/collections/SortDropdown.tsxindex 9a57aa8045..063f86f0c3 100644--- a/apps/client/src/widgets/collections/SortDropdown.tsx+++ b/apps/client/src/widgets/collections/SortDropdown.tsx@@ -16,7 +16,7 @@ import { type SortEntry, sortEntries, type SortMenuOptions, sortMenuTitle } fromexport default function SortDropdown({className, ...options}: SortMenuOptions & { className?: string }) {- const { orderBy, isDescending, attributes, noneTitle } = options;+ const { orderBy, isDescending, attributes, noneTitle, defaultTitle } = options;const { orders, directions } = sortEntries(options);return (@@ -24,7 +24,7 @@ export default function SortDropdown({className={clsx("sort-dropdown", className)}text={<><Icon icon={isDescending ? "bx bx-sort-down" : "bx bx-sort-up"} />- {sortMenuTitle({ orderBy, attributes, noneTitle })}+ {sortMenuTitle({ orderBy, attributes, noneTitle, defaultTitle })}</>}mobileBottomSheet// The card the dropdown stands in is a backdrop root, which would otherwise flatten thediff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 0809ee0b6b..bd029b790e 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -3611,6 +3611,28 @@ describe("a column that sorts its cards", () => {expect(sortButton(descending.board)?.classList.contains("bx-sort-down")).toBe(true);});+ it("draws a column stored as default in the board's own order, button and all", async () => {+ const { board } = await renderSortedBoard(+ { orderBy: "default" }, undefined, { orderBy: "title" });++ expect(cardTitlesIn(board, 0)).toEqual([ "Alpha", "Beta", "Delta" ]);+ // The button says the column is sorted, whichever order it took.+ expect(sortButton(board)?.classList.contains("bx-sort-up")).toBe(true);++ const backwards = await renderSortedBoard(+ { orderBy: "default" }, undefined, { orderBy: "title", isDescending: true });+ expect(cardTitlesIn(backwards.board, 0)).toEqual([ "Delta", "Beta", "Alpha" ]);+ expect(sortButton(backwards.board)?.classList.contains("bx-sort-down")).toBe(true);+ });++ /** The board holding no order of its own leaves such a column as the reader arranged it. */+ it("leaves a column stored as default alone while the board holds no order", async () => {+ const { board } = await renderSortedBoard({ orderBy: "default" });++ expect(cardTitlesIn(board, 0)).toEqual([ "Delta", "Beta", "Alpha" ]);+ expect(sortButton(board)).toBeNull();+ });+it("opens the sort menu, and takes the column away once it is arranged by hand", async () => {const { board } = await renderSortedBoard({ orderBy: "title" });const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});@@ -3698,13 +3720,21 @@ describe("a column that sorts its cards", () => {async function renderSortedBoard(sort: { orderBy?: string, descendingOrder?: boolean, collapsed?: boolean },- promoted?: { "#label:priority(inheritable)": string, values: Record<string, string> }+ promoted?: { "#label:priority(inheritable)": string, values: Record<string, string> },+ /** The order the board holds, which a column stored as `default` takes. */+ boardSort?: { orderBy: string, isDescending?: boolean }) {const priorities = promoted?.values ?? {};const note = buildNote({title: "Board","#collection": "","#viewType": "board",+ ...(boardSort+ ? {+ "#sortColumns": boardSort.orderBy,+ ...(boardSort.isDescending ? { "#sortColumnsDescending": "" } : {})+ }+ : {}),...(promoted? { "#label:priority(inheritable)": promoted["#label:priority(inheritable)"] }: {}),diff --git a/apps/client/src/widgets/collections/board/properties.tsx b/apps/client/src/widgets/collections/board/properties.tsxindex 6503d260c6..b19504442a 100644--- a/apps/client/src/widgets/collections/board/properties.tsx+++ b/apps/client/src/widgets/collections/board/properties.tsx@@ -103,7 +103,9 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {attributes={api.getPromotedAttributes()}noneTitle={t("board_view.sort-manually")}hideDefault- onSelect={(orderBy) => api.setDefaultSort(orderBy)}+ // The board's own order is a key of its own: `hideDefault` leaves it no+ // entry for taking one from above, which `parseSortKey` also rules out.+ onSelect={(orderBy) => api.setDefaultSort(parseSortKey(orderBy))}onDirectionChange={(descending) => api.setDefaultSortDirection(descending)}/>diff --git a/apps/client/src/widgets/collections/sort_menu.ts b/apps/client/src/widgets/collections/sort_menu.tsindex 0a4700ef44..bad53b3267 100644--- a/apps/client/src/widgets/collections/sort_menu.ts+++ b/apps/client/src/widgets/collections/sort_menu.ts@@ -108,12 +108,14 @@ export function sortEntries({* what the items are ordered by, and there is no title left to show for it.*/export function sortMenuTitle(- { orderBy, attributes, noneTitle }: Pick<SortMenuOptions, "orderBy" | "attributes" | "noneTitle">+ { orderBy, attributes, noneTitle, defaultTitle }:+ Pick<SortMenuOptions, "orderBy" | "attributes" | "noneTitle" | "defaultTitle">): string {const { orders } = sortEntries({orderBy,attributes,noneTitle,+ defaultTitle,isDescending: false,onSelect: () => {},onDirectionChange: () => {}@@ -124,7 +126,9 @@ export function sortMenuTitle(return current.title;}- return orderBy ? sortedAttributeName(orderBy) ?? orderBy : orders[0].title;+ return orderBy && orderBy !== DEFAULT_SORT+ ? sortedAttributeName(orderBy) ?? orderBy+ : orders[0].title;}/**