Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: improve the default sort order presentation in the board properties dialog

Adorian Doran9b91c586c683
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index bea337c440..9e0a8ba7b8 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3526,10 +3526,11 @@
"card-outside-filter": "This card is outside of the current filtering scope",
"sort": "Sort",
"sort-manually": "Manually",
- "sort-cards": "Sort cards",
+ "default-card-order": "Default card order",
+ "default-card-order-description": "How cards are sorted in each column, unless you choose different sorting options for a particular column.",
"sort-board-default": "Board's default",
- "sort-actions": "More actions",
- "reset-columns-to-default": "Reset all columns to default",
+ "reset-column-sorting": "Reset sorting options to default for all columns",
+ "reset-column-sorting-confirm": "Do you want to reset the sorting options for all columns from the current view to default?",
"sorted-no-reorder": "Cards cannot be reordered, since this is a sorted column."
},
"dashboard_view": {
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 5a1eb3c9f0..469088c7de 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -255,27 +255,6 @@ export function openColumnSortMenu(api: Api, x: number, y: number, column: strin
});
}
-/**
- * What can be done to the orders the columns hold, offered beside the board's own order.
- *
- * Opened at the pointer from the button in the properties card, as the template entries there open
- * theirs.
- */
-export function openSortActionsMenu(api: Api, event: { pageX: number, pageY: number }) {
- contextMenu.show({
- x: event.pageX,
- y: event.pageY,
- items: [
- {
- title: t("board_view.reset-columns-to-default"),
- uiIcon: "bx bx-reset",
- handler: () => api.resetColumnSortsToDefault()
- }
- ],
- selectMenuItemHandler() {}
- });
-}
-
/** What the board asks the shared sort menu for, wherever it is opened. */
function sortMenuOptions(api: Api, column: string): SortMenuOptions {
return {
diff --git a/apps/client/src/widgets/collections/board/properties.spec.tsx b/apps/client/src/widgets/collections/board/properties.spec.tsx
index ed6225ad40..6c14985dbd 100644
--- a/apps/client/src/widgets/collections/board/properties.spec.tsx
+++ b/apps/client/src/widgets/collections/board/properties.spec.tsx
@@ -4,7 +4,7 @@ import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type FNote from "../../../entities/fnote";
-import contextMenu, { type MenuCommandItem } from "../../../menus/context_menu";
+import dialogService from "../../../services/dialog";
import type { PromotedAttribute } from "../promoted_attributes";
import type { SortKey } from "../sorting";
import BoardApi from "./api";
@@ -151,7 +151,8 @@ describe("Board properties", () => {
describe("what the board shows", () => {
/** Both were on the board's own menu; the inbox column is now offered only here. */
it("draws a segment for each, reading what the board's labels say", () => {
- const rows = general()?.querySelectorAll(".tn-card-section") ?? [];
+ const rows = general()
+ ?.querySelectorAll(".tn-card-section:not(.tn-card-section-nested)") ?? [];
expect(rows.length).toBe(3);
expect(toggleAt(0)?.classList.contains("on")).toBe(false);
@@ -187,34 +188,32 @@ describe("Board properties", () => {
expect(picker()?.querySelector(".bx-sort-down")).toBeTruthy();
});
- it("offers a menu beside the picker for putting the columns back to it", () => {
- const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
- // The menu closes itself on any click reaching the document, so the press that opens
- // it must not get there.
- const onDocument = vi.fn();
- document.addEventListener("click", onDocument);
+ it("carries a link under the picker for putting the columns back to it", async () => {
+ const confirm = vi.spyOn(dialogService, "confirm").mockResolvedValue(true);
+ const link = resetLink();
- act(() => { actionsButton()?.click(); });
- document.removeEventListener("click", onDocument);
- expect(onDocument).not.toHaveBeenCalled();
+ expect(link?.textContent).toContain("board_view.reset-column-sorting");
- const items = show.mock.calls.at(-1)?.[0].items ?? [];
- expect(items.map(item => item && "title" in item ? item.title : ""))
- .toEqual([ "board_view.reset-columns-to-default" ]);
-
- const entry = items[0];
- if (!entry || !("handler" in entry)) throw new Error("expected a menu entry");
- act(() => { entry.handler?.(entry as MenuCommandItem<unknown>, {} as never); });
+ await act(async () => { link?.click(); });
+ expect(confirm).toHaveBeenCalledWith("board_view.reset-column-sorting-confirm");
expect(sorting).toEqual([ "reset" ]);
});
+ it("leaves the orders alone when the prompt is declined", async () => {
+ vi.spyOn(dialogService, "confirm").mockResolvedValue(false);
+
+ await act(async () => { resetLink()?.click(); });
+
+ expect(sorting).toEqual([]);
+ });
+
function picker() {
return general()?.querySelector<HTMLElement>(".board-sort-picker");
}
- function actionsButton() {
- return general()?.querySelector<HTMLElement>(".board-sort-actions");
+ function resetLink() {
+ return general()?.querySelector<HTMLElement>(".board-sort-reset");
}
});
diff --git a/apps/client/src/widgets/collections/board/properties.tsx b/apps/client/src/widgets/collections/board/properties.tsx
index e14de735d8..a971fbfc95 100644
--- a/apps/client/src/widgets/collections/board/properties.tsx
+++ b/apps/client/src/widgets/collections/board/properties.tsx
@@ -3,9 +3,9 @@ import "./properties.css";
import { useCallback } from "preact/hooks";
import type FNote from "../../../entities/fnote";
+import dialog from "../../../services/dialog";
import { t } from "../../../services/i18n";
-import ActionButton from "../../react/ActionButton";
-import { Card, OptionCardSection } from "../../react/Card";
+import { Card, CardSection, OptionCardSection } from "../../react/Card";
import FormToggle from "../../react/FormToggle";
import { useNoteLabelBoolean } from "../../react/hooks";
import Modal from "../../react/Modal";
@@ -15,7 +15,6 @@ import type { PromotedAttribute } from "../promoted_attributes";
import SortDropdown from "../SortDropdown";
import { parseSortKey } from "../sorting";
import BoardApi from "./api";
-import { openSortActionsMenu } from "./context_menu";
import { useBoardSort } from "./sort";
/** The board's settings, other than its columns and cards. */
@@ -68,6 +67,13 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {
const [ inboxShown ] = useNoteLabelBoolean(note, "enableInboxColumn");
const [ archivedShown ] = useNoteLabelBoolean(note, "includeArchived");
const defaultSort = useBoardSort(note);
+ // Every column at once, and a column's own order is not kept anywhere else: the reader is asked
+ // before it goes.
+ const resetColumnSorts = useCallback(async () => {
+ if (await dialog.confirm(t("board_view.reset-column-sorting-confirm"))) {
+ await api.resetColumnSortsToDefault();
+ }
+ }, [ api ]);
return (
<Card className="board-properties-general" heading={t("board_view.general")}>
@@ -94,7 +100,23 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {
<OptionCardSection
name="board-sort-cards"
- label={t("board_view.sort-cards")}
+ label={t("board_view.default-card-order")}
+ description={t("board_view.default-card-order-description")}
+ subSectionsVisible
+ subSections={
+ <CardSection
+ className="board-sort-reset"
+ href="#"
+ noContainedNavigation
+ onAction={(event) => {
+ // The anchor is what makes the segment read as a link; the address
+ // itself leads nowhere, and `goToLink` would navigate by it.
+ event.preventDefault();
+ event.stopPropagation();
+ void resetColumnSorts();
+ }}
+ >{t("board_view.reset-column-sorting")}</CardSection>
+ }
>
<SortDropdown
className="board-sort-picker"
@@ -108,18 +130,6 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {
onSelect={(orderBy) => api.setDefaultSort(parseSortKey(orderBy))}
onDirectionChange={(descending) => api.setDefaultSortDirection(descending)}
/>
-
- <ActionButton
- className="board-sort-actions"
- icon="bx bx-dots-vertical-rounded"
- text={t("board_view.sort-actions")}
- onClick={(event) => {
- // The press would otherwise reach the document, where the menu closes
- // itself on any click outside it.
- event.stopPropagation();
- openSortActionsMenu(api, event);
- }}
- />
</OptionCardSection>
</Card>
);