Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: allow columns to be archived

Adorian Dorand4b78fac750f
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1c5c72af8d..fbd3887e9a 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3346,6 +3346,8 @@
"insert-above": "Insert above",
"insert-below": "Insert below",
"delete-column": "Delete column",
+ "archive-column": "Archive column",
+ "unarchive-column": "Unarchive column",
"delete-column-confirmation": "Are you sure you want to delete this column? The corresponding attribute will be deleted in the notes under this column as well.",
"new-item": "New item",
"new-item-placeholder": "Enter note title...",
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index b98812c3ec..09a841cfae 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -130,6 +130,19 @@ describe("BoardApi column mutations", () => {
expect(saved.at(-1)?.columns).toEqual([ { value: "To Do", icon: "bx bx-list-ul" } ]);
});
+ it("archives a column and brings it back, storing nothing once it is not", async () => {
+ const { api, saved } = createApi(
+ { columns: [ { value: "To Do", icon: "bx bx-list-ul" } ] }, [ "To Do" ]);
+
+ await api.setColumnArchived("To Do", true);
+ expect(saved.at(-1)?.columns).toEqual([
+ { value: "To Do", icon: "bx bx-list-ul", archived: true }
+ ]);
+
+ await api.setColumnArchived("To Do", false);
+ expect(saved.at(-1)?.columns).toEqual([ { value: "To Do", icon: "bx bx-list-ul" } ]);
+ });
+
it("keeps the icon of a column it renames", async () => {
const { api, saved } = createApi(
{ columns: [ { value: "Done", icon: "bx bx-check" } ] }, [ "Done" ]);
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 3b43042315..306741df8b 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -115,6 +115,14 @@ export default class BoardApi {
this.updateColumn(column, { color: color ?? undefined });
}
+ /**
+ * Archives a column or brings it back. An archived one is shown only while the board is set to
+ * show archived notes, and greyed out where it is.
+ */
+ async setColumnArchived(column: string, archived: boolean) {
+ this.updateColumn(column, { archived });
+ }
+
/**
* Writes properties onto a column, dropping each one given as nothing so that it goes back to
* its default rather than being stored empty.
@@ -128,6 +136,7 @@ export default class BoardApi {
const updated = { ...stored, ...patch };
if (!updated.icon) delete updated.icon;
if (!updated.color) delete updated.color;
+ if (!updated.archived) delete updated.archived;
return updated;
};
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index b438ae1877..76554fb810 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -32,6 +32,7 @@ export default function Column({
columnIndex,
icon,
color,
+ archived,
isDraggingColumn,
columnItems,
api,
@@ -45,6 +46,8 @@ export default function Column({
icon?: string,
/** The stored CSS colour, absent until one is picked. */
color?: string,
+ /** Whether the column is archived. Only ever rendered while archived notes are shown. */
+ archived?: boolean,
isDraggingColumn: boolean,
api: BoardApi,
parentNote: FNote,
@@ -65,9 +68,10 @@ export default function Column({
openColumnContextMenu(api, e, {
value: column,
color,
+ archived,
onEditTitle: () => setColumnNameToEdit(column)
});
- }, [ api, column, color, setColumnNameToEdit ]);
+ }, [ api, column, color, archived, setColumnNameToEdit ]);
// A fully desaturated colour has no hue to tint with, and leaves the column plain.
const hue = useMemo(() => {
@@ -112,7 +116,8 @@ export default function Column({
className={clsx("board-column", {
"drag-over": dropTarget === column && draggedCard?.fromColumn !== column,
// The class the themes key a hue off, worn here as anywhere else that carries one.
- "with-hue": hue !== undefined
+ "with-hue": hue !== undefined,
+ "board-column-archived": archived
})}
onDragOver={isAnyColumnDragging ? handleColumnDragOver : handleDragOver}
onDragLeave={handleDragLeave}
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index df6539b824..f2846b7b56 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -18,7 +18,11 @@ describe("Board column context menu", () => {
}
});
- function openMenu(api: BoardApi, color?: string, onEditTitle = () => {}) {
+ function openMenu(
+ api: BoardApi,
+ column: { color?: string, archived?: boolean } = {},
+ onEditTitle = () => {}
+ ) {
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
const event = {
preventDefault: () => {},
@@ -27,14 +31,15 @@ describe("Board column context menu", () => {
pageY: 0
} as ContextMenuEvent;
- openColumnContextMenu(api, event, { value: "To Do", color, onEditTitle });
+ openColumnContextMenu(api, event, { value: "To Do", ...column, onEditTitle });
- return show.mock.calls[0][0].items ?? [];
+ // The spy outlives one call, so it is the menu just opened that is read back.
+ return show.mock.calls.at(-1)?.[0].items ?? [];
}
/** Renders the colour picker the menu offers for a column already carrying `color`. */
async function openPicker(api: BoardApi, color?: string) {
- const items = openMenu(api, color);
+ const items = openMenu(api, { color });
const custom = items.find(item => item && "kind" in item && item.kind === "custom");
if (!custom || !("componentFn" in custom)) {
throw new Error("expected a colour picker in the menu");
@@ -53,7 +58,7 @@ describe("Board column context menu", () => {
it("offers the title editor, which the retired header button used to open", () => {
const onEditTitle = vi.fn();
- const items = openMenu({} as BoardApi, undefined, onEditTitle);
+ const items = openMenu({} as BoardApi, {}, onEditTitle);
// Found by its icon: i18next is never initialised under test, so every title is undefined.
const entry = items.find(item =>
@@ -64,6 +69,28 @@ describe("Board column context menu", () => {
expect(onEditTitle).toHaveBeenCalled();
});
+ it("offers to archive a column, and to bring back one already archived", () => {
+ const api = { setColumnArchived: vi.fn() } as unknown as BoardApi;
+
+ const archive = openMenu(api).find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-archive");
+ if (!archive || !("handler" in archive)) throw new Error("expected an archive entry");
+ archive.handler?.(archive, {} as never);
+ expect(api.setColumnArchived).toHaveBeenLastCalledWith("To Do", true);
+
+ const unarchive = openMenu(api, { archived: true }).find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-archive-out");
+ if (!unarchive || !("handler" in unarchive)) throw new Error("expected an unarchive entry");
+ unarchive.handler?.(unarchive, {} as never);
+ expect(api.setColumnArchived).toHaveBeenLastCalledWith("To Do", false);
+ });
+
+ it("puts archiving above deleting, so the safe way out leads", () => {
+ const titled = openMenu({} as BoardApi).filter(item => item && "uiIcon" in item);
+ expect(titled.map(item => "uiIcon" in item ? item.uiIcon : undefined))
+ .toEqual([ "bx bx-edit-alt", "bx bx-archive", "bx bx-trash" ]);
+ });
+
it("shows the column's own colour as the selected one", async () => {
const api = { setColumnColor: vi.fn() } as unknown as BoardApi;
const picker = await openPicker(api, "#4d99e6");
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index db0d5945dd..0ef674528c 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -14,6 +14,7 @@ import Api from "./api";
export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: {
value: string;
color?: string;
+ archived?: boolean;
/** Puts the title into its inline editor, the menu being the only way there besides F2. */
onEditTitle: () => void;
}) {
@@ -29,6 +30,17 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:
uiIcon: "bx bx-edit-alt",
handler: column.onEditTitle
},
+ column.archived
+ ? {
+ title: t("board_view.unarchive-column"),
+ uiIcon: "bx bx-archive-out",
+ handler: () => api.setColumnArchived(column.value, false)
+ }
+ : {
+ title: t("board_view.archive-column"),
+ uiIcon: "bx bx-archive",
+ handler: () => api.setColumnArchived(column.value, true)
+ },
{
title: t("board_view.delete-column"),
uiIcon: "bx bx-trash",
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index ef0d666f32..466e33db06 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -290,6 +290,10 @@ body.mobile .board-view-container .board-add-column {
transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease, margin-top 0.2s ease;
}
+.board-view-container .board-column.board-column-archived {
+ opacity: 0.5;
+}
+
.board-view-container .board-note.archived {
opacity: 0.5;
}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 0f6a071c85..e51d2cf3b3 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -181,11 +181,12 @@ describe("Board column rename", () => {
columns: [ { value: "To Do" }, { value: "Doing" }, { value: "Done" } ]
};
- async function setup(config: BoardViewData = DEFAULT_CONFIG) {
+ async function setup(config: BoardViewData = DEFAULT_CONFIG, includeArchived = false) {
const note = buildNote({
title: "Board",
"#collection": "",
"#viewType": "board",
+ ...(includeArchived ? { "#includeArchived": "true" } : {}),
"#label:status(inheritable)":
"promoted,alias=Status,single,select,options=To Do;Doing;Done",
children: [
@@ -325,6 +326,28 @@ describe("Board column rename", () => {
.toEqual([ true, false, false ]);
});
+ it("hides an archived column, unless the board is set to show archived notes", async () => {
+ const archivedConfig: BoardViewData = {
+ columns: [ { value: "To Do" }, { value: "Doing", archived: true }, { value: "Done" } ]
+ };
+
+ const { container: hidden } = await setup(archivedConfig);
+ expect(columnTitles(hidden)).toEqual([ "To Do", "Done" ]);
+
+ // The column is only out of sight; nothing has been written out of the config.
+ expect(saved.every(config => config.columns?.some(col => col.value === "Doing")))
+ .toBe(true);
+
+ render(null, hidden);
+ hidden.remove();
+
+ const { container: shown } = await setup(archivedConfig, true);
+ expect(columnTitles(shown)).toEqual([ "To Do", "Doing", "Done" ]);
+ expect([ ...shown.querySelectorAll(".board-column") ]
+ .map(column => column.classList.contains("board-column-archived")))
+ .toEqual([ false, true, false ]);
+ });
+
it("keeps the cards of the renamed column under it", async () => {
const { container } = await setup();
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 5455e508d4..d9b13a266d 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -32,6 +32,8 @@ export interface BoardColumnData {
icon?: string;
/** The CSS colour the column is tinted with, absent until one is picked. */
color?: string;
+ /** Whether the column is archived, absent while it is not. */
+ archived?: boolean;
}
interface CardDrag {
@@ -145,6 +147,14 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
() => new Map((viewConfig?.columns ?? []).map(stored => [ stored.value, stored ])),
[ viewConfig ]);
+ // Filtered here rather than in the resolution, which is what gets written back: dropped there,
+ // an archived column would be erased from the config and the definition instead of kept out of
+ // sight. `columnDropPosition` indexes this list, so a drag places columns as they are shown.
+ const shownColumns = useMemo(
+ () => (columns ?? []).filter(column =>
+ includeArchived || !storedColumns.get(column)?.archived),
+ [ columns, storedColumns, includeArchived ]);
+
const boardDragState = useMemo<BoardDragState>(() => ({
branchIdToEdit,
columnNameToEdit,
@@ -201,15 +211,23 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
useEffect(refresh, [ parentNote, noteIds, viewConfig, statusAttributeWithPrefix, statusDefinition ]);
+ // The drag reports where the column landed among the ones on screen, which is not where it
+ // landed among them all once some are archived and hidden. Translated here so a reorder leaves
+ // every hidden column where it was rather than herding them to the end.
const handleColumnDrop = useCallback((fromIndex: number, toIndex: number) => {
- const newColumns = api.reorderColumn(fromIndex, toIndex);
+ const allColumns = columns ?? [];
+ const dropBefore = shownColumns[toIndex];
+ const newColumns = api.reorderColumn(
+ allColumns.indexOf(shownColumns[fromIndex]),
+ dropBefore === undefined ? allColumns.length : allColumns.indexOf(dropBefore));
+
if (newColumns) {
setColumns(newColumns);
}
setDraggedColumn(null);
setDraggedCard(null);
setColumnDropPosition(null);
- }, [api]);
+ }, [ api, columns, shownColumns ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
// The column list is read off the definition, which may be edited from the attribute panel,
@@ -261,7 +279,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
onDrop={handleContainerDrop}
onWheel={onWheelHorizontalScroll}
>
- {columns.map((column, index) => (
+ {shownColumns.map((column, index) => (
<>
{columnDropPosition === index && (
<div className="column-drop-placeholder show" />
@@ -273,6 +291,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
column={column}
icon={storedColumns.get(column)?.icon}
color={storedColumns.get(column)?.color}
+ archived={storedColumns.get(column)?.archived}
columnIndex={index}
columnItems={byColumn.get(column)}
isDraggingColumn={draggedColumn?.column === column}
@@ -281,7 +300,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
/>
</>
))}
- {columnDropPosition === columns?.length && draggedColumn && (
+ {columnDropPosition === shownColumns.length && draggedColumn && (
<div className="column-drop-placeholder show" />
)}