Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: add support for limiting the note count for a column

Adorian Doran16d53221c47c
diff --git a/apps/client/src/stylesheets/theme-next-dark.css b/apps/client/src/stylesheets/theme-next-dark.css
index dc90f88cb4..b874facb27 100644
--- a/apps/client/src/stylesheets/theme-next-dark.css
+++ b/apps/client/src/stylesheets/theme-next-dark.css
@@ -397,6 +397,8 @@
--space-usage-donut-hover-saturation: 90%;
--space-usage-donut-hover-lightness: 80%;
+ --board-limit-exceeded-background: #e57373;
+ --board-limit-exceeded-outline: #e5737380;
--board-column-background: #3b3b3b;
--board-column-background-saturation: 14%;
--board-column-background-lightness: 23%;
diff --git a/apps/client/src/stylesheets/theme-next-light.css b/apps/client/src/stylesheets/theme-next-light.css
index 33a9f3b518..0d72f364e2 100644
--- a/apps/client/src/stylesheets/theme-next-light.css
+++ b/apps/client/src/stylesheets/theme-next-light.css
@@ -396,6 +396,8 @@
--space-usage-donut-hover-saturation: 57%;
--space-usage-donut-hover-lightness: 68%;
+ --board-limit-exceeded-background: #c62828;
+ --board-limit-exceeded-outline: #c6282880;
--board-column-background: #e7e7e7;
--board-column-background-saturation: 26%;
--board-column-background-lightness: 86%;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index acd5dfd677..62df2a45b2 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3386,6 +3386,7 @@
"card-count_other": "{{count}} items",
"card-count-with-archived_one": "{{count}} active item, {{archived}} archived",
"card-count-with-archived_other": "{{count}} active items, {{archived}} archived",
+ "card-count-over-limit": "The note limit set for this column is exceeded!",
"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...",
@@ -3402,6 +3403,10 @@
"add-column-placeholder": "Enter column name...",
"edit-note-title": "Click to edit note title",
"rename-column": "Rename column",
+ "set-limit": "Set limit...",
+ "set-limit-ok": "Set limit",
+ "limit-capacity": "Warn for exceeding the column capacity",
+ "limit-count": "Maximum number of notes in the column",
"move-column": "Move column",
"move-column-first": "As the first column",
"move-column-after": "After {{column}}",
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 5f4d2ae7b1..21b6bce6ca 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -391,6 +391,16 @@ export default class BoardApi {
await attributes.setBooleanWithInheritance(this.parentNote, "enableInboxColumn", false);
}
+ /** The note limit set for a column, absent if disabled. */
+ getColumnLimit(column: string) {
+ return this.viewConfig?.columns?.find(col => col.value === column)?.limit;
+ }
+
+ /** Sets a column's note limit. Pass `undefined` to disable it. */
+ async setColumnLimit(column: string, limit: number | undefined) {
+ await this.updateColumn(column, { limit });
+ }
+
/** Whether the inbox reaches past the board's own children, down to the children of cards. */
async setInboxNested(nested: boolean) {
await this.updateColumn(INBOX_COLUMN, { nested });
@@ -424,6 +434,7 @@ export default class BoardApi {
if (!updated.color) delete updated.color;
if (!updated.archived) delete updated.archived;
if (!updated.displayName) delete updated.displayName;
+ if (!updated.limit) delete updated.limit;
return updated;
};
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 84622e0084..22b86dff68 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -41,6 +41,7 @@ export default function Column({
color,
archived,
nested,
+ limit,
isDraggingColumn,
columnItems,
api,
@@ -58,6 +59,8 @@ export default function Column({
archived?: boolean,
/** Whether the inbox reaches past the board's own children. Meaningless on any other column. */
nested?: boolean,
+ /** The note limit, absent if disabled. */
+ limit?: number,
isDraggingColumn: boolean,
api: BoardApi,
parentNote: FNote,
@@ -73,7 +76,7 @@ export default function Column({
} & DragContext) {
const [ isVisible, setVisible ] = useState(true);
const [ isCreatingNewItem, setIsCreatingNewItem ] = useState(false);
- const { setColumnNameToEdit } = useContext(BoardActionsContext);
+ const { setColumnNameToEdit, setColumnLimitToEdit } = useContext(BoardActionsContext);
const { branchIdToEdit, columnNameToEdit, dropTarget, draggedCard, dropPosition } = useContext(BoardDragStateContext);
const isEditing = (columnNameToEdit === column);
const editorRef = useRef<HTMLInputElement>(null);
@@ -81,6 +84,9 @@ export default function Column({
column, columnIndex, columnItems, isEditing, api, parentNote
});
+ // Read here rather than in the badge: the column body shows an outline as well.
+ const isOverLimit = limit !== undefined && (columnItems?.length ?? 0) > limit;
+
const openMenu = useCallback((e: ContextMenuEvent) => {
openColumnContextMenu(api, e, {
value: column,
@@ -94,6 +100,7 @@ export default function Column({
onAddColumn: async (direction) => {
setColumnNameToEdit(await api.insertColumn(column, direction));
},
+ onSetLimit: () => setColumnLimitToEdit(column),
onMoveColumn: (toIndex) => {
onMoveColumn(columnIndex, toIndex);
// Asked for by name: the move draws the board again, and the heading the menu was
@@ -103,7 +110,7 @@ export default function Column({
});
}, [
api, column, color, archived, nested, columns, columnIndex,
- setColumnNameToEdit, onMoveColumn, onFocusColumn
+ setColumnNameToEdit, setColumnLimitToEdit, onMoveColumn, onFocusColumn
]);
// A fully desaturated colour has no hue to tint with, and leaves the column plain.
@@ -151,7 +158,8 @@ export default function 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,
- "board-column-archived": archived
+ "board-column-archived": archived,
+ "over-limit": isOverLimit
})}
onDragOver={isAnyColumnDragging ? handleColumnDragOver : handleDragOver}
onDragLeave={handleDragLeave}
@@ -197,7 +205,7 @@ export default function Column({
: api.getColumnTitle(column)}
</span>
<div className="spacer" />
- <CountBadge items={columnItems} />
+ <CountBadge items={columnItems} limit={limit} isOver={isOverLimit} />
<ActionButton
className="column-menu"
icon="bx bx-dots-vertical-rounded"
@@ -272,19 +280,40 @@ export default function Column({
* The archived ones are among them only while the board is showing archived notes; where it is not,
* there are none to count and the badge says how many cards there are and no more.
*/
-function CountBadge({ items }: { items?: { note: FNote }[] }) {
+function CountBadge({ items, limit, isOver }: {
+ items?: { note: FNote }[],
+ limit?: number,
+ /** Whether the column is over its limit. The column body shows this too. */
+ isOver?: boolean
+}) {
const badgeRef = useRef<HTMLSpanElement>(null);
const archived = items?.filter(({ note }) => note.isArchived).length ?? 0;
const total = items?.length ?? 0;
- // Named on the element rather than handed to the tooltip, so the count still reads on hover
- // wherever the scripted tooltip does not come up.
- const title = archived
+ const counts = archived
? t("board_view.card-count-with-archived", { count: total - archived, archived })
: t("board_view.card-count", { count: total });
- useStaticTooltip(badgeRef);
+ const warning = t("board_view.card-count-over-limit");
+
+ // The tooltip gets its own markup, since a title attribute cannot show a bold line. The
+ // attribute keeps a plain version as a fallback. Memoised because `useStaticTooltip`
+ // rebuilds the tooltip whenever the config changes identity.
+ const tooltip = useMemo(() => ({
+ html: true,
+ title: isOver ? `${counts}<br><strong>${warning}</strong>` : counts
+ }), [ counts, warning, isOver ]);
+ useStaticTooltip(badgeRef, tooltip);
- return <span ref={badgeRef} className="counter-badge" title={title}>{total}</span>;
+ return (
+ <span
+ ref={badgeRef}
+ className={clsx("counter-badge", { "over-limit": isOver })}
+ title={isOver ? `${counts}
+${warning}` : counts}
+ >
+ {limit === undefined ? total : `${total}/${limit}`}
+ </span>
+ );
}
function AddNewItem({ column, api, itemCount, isCreating, setIsCreating }: {
diff --git a/apps/client/src/widgets/collections/board/column_limit.css b/apps/client/src/widgets/collections/board/column_limit.css
new file mode 100644
index 0000000000..c836f3541d
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/column_limit.css
@@ -0,0 +1,19 @@
+/* One row per setting: label on the left, control on the right. */
+.modal.board-column-limit-dialog .board-column-limit-fields {
+ display: grid;
+ grid-template-columns: 1fr auto;
+ align-items: center;
+ /* Right-align the controls, whatever width each one takes. */
+ justify-items: end;
+ gap: 8px 20px;
+}
+
+.modal.board-column-limit-dialog .board-column-limit-fields > label {
+ justify-self: start;
+ margin-bottom: 0;
+}
+
+/* Fits a count and its spinner. */
+.modal.board-column-limit-dialog .board-column-limit-count {
+ width: 7em;
+}
diff --git a/apps/client/src/widgets/collections/board/column_limit.spec.tsx b/apps/client/src/widgets/collections/board/column_limit.spec.tsx
new file mode 100644
index 0000000000..d53464c53b
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/column_limit.spec.tsx
@@ -0,0 +1,81 @@
+import { render } from "preact";
+import { act } from "preact/test-utils";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import Component from "../../../components/component";
+import { ParentComponent } from "../../react/react_utils";
+import BoardApi from "./api";
+import ColumnLimitDialog from "./column_limit";
+
+vi.mock("../../../services/i18n", () => ({
+ t: (key: string) => key,
+ translationsInitializedPromise: Promise.resolve()
+}));
+
+describe("Setting how much a column should hold", () => {
+ let container: HTMLElement | undefined;
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ if (container) {
+ render(null, container);
+ container.remove();
+ container = undefined;
+ }
+ });
+
+ async function open(limit: number | undefined) {
+ const api = {
+ getColumnLimit: () => limit,
+ setColumnLimit: vi.fn(async () => {})
+ } as unknown as BoardApi;
+
+ const element = document.createElement("div");
+ container = element;
+ document.body.appendChild(element);
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <ColumnLimitDialog api={api} column="To Do" onClose={() => {}} />
+ </ParentComponent.Provider>,
+ element
+ );
+ });
+
+ // The modal renders into the page rather than into the container it was given.
+ return { api, dialog: document.querySelector<HTMLElement>(".board-column-limit-dialog") };
+ }
+
+ /** One row per setting, the label naming the control beside it. */
+ it("puts each label beside the control it names", async () => {
+ const { dialog } = await open(3);
+ const fields = dialog?.querySelector(".board-column-limit-fields");
+
+ expect(fields).not.toBeNull();
+ expect([ ...fields?.children ?? [] ].map(el => el.tagName.toLowerCase()))
+ .toEqual([ "label", "div", "label", "input" ]);
+ // Each label points at the control it sits with, so the pair reads as one row. Scoped to
+ // the grid's own children: the switch wraps itself in a label of its own.
+ expect([ ...fields?.querySelectorAll(":scope > label") ?? [] ]
+ .map(el => el.getAttribute("for")))
+ .toEqual([ "board-column-limit-toggle", "board-column-limit-count" ]);
+ });
+
+ it("opens on what the column already holds itself to", async () => {
+ const { dialog } = await open(3);
+
+ expect(dialog?.querySelector<HTMLInputElement>(".switch-toggle")?.checked).toBe(true);
+ expect(dialog?.querySelector<HTMLInputElement>("input[type=number]")?.value).toBe("3");
+ });
+
+ /**
+ * The switch is what takes a limit away. A column holding no number is not a column meant to
+ * hold none, which is what a zero would say.
+ */
+ it("offers a number to switch on for a column holding itself to none", async () => {
+ const { dialog } = await open(undefined);
+
+ expect(dialog?.querySelector<HTMLInputElement>(".switch-toggle")?.checked).toBe(false);
+ expect(dialog?.querySelector<HTMLInputElement>("input[type=number]")?.disabled).toBe(true);
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/column_limit.tsx b/apps/client/src/widgets/collections/board/column_limit.tsx
new file mode 100644
index 0000000000..92a523fb12
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/column_limit.tsx
@@ -0,0 +1,80 @@
+import "./column_limit.css";
+
+import { useEffect, useState } from "preact/hooks";
+
+import { t } from "../../../services/i18n";
+import Button from "../../react/Button";
+import FormTextBox from "../../react/FormTextBox";
+import FormToggle from "../../react/FormToggle";
+import Modal from "../../react/Modal";
+import BoardApi from "./api";
+
+const DEFAULT_LIMIT = 5;
+
+/**
+ * Asks how many cards a column is meant to hold.
+ *
+ * The switch disables the limit, rather than a value such as 0 or -1 standing for "no limit".
+ */
+export default function ColumnLimitDialog({ api, column, onClose }: {
+ api: BoardApi,
+ /** The column being given a limit, or nothing while the dialog is not being asked for. */
+ column?: string,
+ onClose: () => void
+}) {
+ const stored = column !== undefined ? api.getColumnLimit(column) : undefined;
+ const [ isLimited, setIsLimited ] = useState(stored !== undefined);
+ const [ limit, setLimit ] = useState(stored ?? DEFAULT_LIMIT);
+
+ // The dialog is kept mounted and opened by naming a column, so what it shows is read again
+ // each time it is opened rather than only when it is first drawn.
+ useEffect(() => {
+ setIsLimited(stored !== undefined);
+ setLimit(stored ?? DEFAULT_LIMIT);
+ }, [ column, stored ]);
+
+ return (
+ <Modal
+ className="board-column-limit-dialog"
+ title={t("board_view.set-limit")}
+ size="md"
+ // Raised the way every dialog opened from a context menu is: the menu's own backdrop
+ // stands above the stock modal layer, and would otherwise cover this.
+ zIndex={2000}
+ show={column !== undefined}
+ onSubmit={() => {
+ if (column !== undefined) {
+ api.setColumnLimit(column, isLimited ? limit : undefined);
+ }
+ onClose();
+ }}
+ onHidden={onClose}
+ footer={<>
+ <Button text={t("modal.cancel")} onClick={onClose} />
+ <Button text={t("board_view.set-limit-ok")} keyboardShortcut="Enter" kind="primary" />
+ </>}
+ >
+ <div className="board-column-limit-fields">
+ {/* Labelled here, not through the switch: its own label sits inside the
+ switch and would fall outside the grid. */}
+ <label for="board-column-limit-toggle">{t("board_view.limit-capacity")}</label>
+ <FormToggle
+ id="board-column-limit-toggle"
+ currentValue={isLimited}
+ onChange={setIsLimited}
+ />
+
+ <label for="board-column-limit-count">{t("board_view.limit-count")}</label>
+ <FormTextBox
+ id="board-column-limit-count"
+ className="board-column-limit-count"
+ type="number"
+ min={1}
+ disabled={!isLimited}
+ currentValue={String(limit)}
+ onChange={(value) => setLimit(Math.max(1, parseInt(value, 10) || 1))}
+ />
+ </div>
+ </Modal>
+ );
+}
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 0bc4c5f902..8a675d907c 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -38,7 +38,8 @@ describe("Board column context menu", () => {
onEditTitle?: () => void,
onNewItem?: () => void,
onAddColumn?: (direction: "before" | "after") => void,
- onMoveColumn?: (toIndex: number) => void
+ onMoveColumn?: (toIndex: number) => void,
+ onSetLimit?: () => void
} = {}
) {
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
@@ -59,7 +60,8 @@ describe("Board column context menu", () => {
onEditTitle: callbacks.onEditTitle ?? (() => {}),
onNewItem: callbacks.onNewItem ?? (() => {}),
onAddColumn: callbacks.onAddColumn ?? (() => {}),
- onMoveColumn: callbacks.onMoveColumn ?? (() => {})
+ onMoveColumn: callbacks.onMoveColumn ?? (() => {}),
+ onSetLimit: callbacks.onSetLimit ?? (() => {})
});
// The spy outlives one call, so it is the menu just opened that is read back.
@@ -163,8 +165,8 @@ describe("Board column context menu", () => {
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-plus", "bx bx-link", "bx bx-columns",
- "bx bx-horizontal-left", "bx bx-archive", "bx bx-trash"
+ "bx bx-edit-alt", "bx bx-tachometer", "bx bx-plus", "bx bx-link",
+ "bx bx-columns", "bx bx-horizontal-left", "bx bx-archive", "bx bx-trash"
]);
});
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 7847a84b15..6ddd02ddb8 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -33,6 +33,8 @@ interface ColumnMenuTarget {
onAddColumn: (direction: "before" | "after") => void;
/** Moves this column to sit before the given position among the columns as drawn. */
onMoveColumn: (toIndex: number) => void;
+ /** Asks how many cards the column is meant to hold. */
+ onSetLimit: () => void;
}
export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: ColumnMenuTarget) {
@@ -51,6 +53,11 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:
shortcut: "F2",
handler: column.onEditTitle
},
+ {
+ title: t("board_view.set-limit"),
+ uiIcon: "bx bx-tachometer",
+ handler: column.onSetLimit
+ },
...(isInbox ? [ {
title: t("board_view.inbox-nested"),
uiIcon: "bx bx-subdirectory-right",
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index da5bc2668f..5ac84d0fbf 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -10,6 +10,9 @@
--board-item-hover-background-saturation: 100%;
--board-item-hover-background-lightness: 98.5%;
+ --board-limit-exceeded-background: #c62828;
+ /* Half opacity: the badge is the main warning, the outline supports it. */
+ --board-limit-exceeded-outline: #c6282880;
--board-focus-outline-saturation: 55%;
--board-focus-outline-lightness: 45%;
/* Follows the theme of its own accord, so neither theme has to name it again. */
@@ -496,3 +499,30 @@ body.mobile .board-view-container .board-add-column {
text-overflow: ellipsis;
white-space: nowrap;
}
+
+/* Outline around a column that is over its limit. */
+.board-view-container .board-column.over-limit {
+ box-shadow: 0 0 0 2px var(--board-limit-exceeded-outline);
+}
+
+/*
+ * Pulses the badge of a column that is over its limit. `filter` is used instead of animating
+ * `background-color`: a filter is composited, while a colour change repaints every frame,
+ * which costs battery and can drop frames on mobile.
+ */
+.board-view-container .board-column h3 .counter-badge.over-limit {
+ background-color: var(--board-limit-exceeded-background);
+ color: white;
+ animation: board-limit-pulse 1.4s ease-in-out infinite alternate;
+}
+
+@keyframes board-limit-pulse {
+ from { filter: saturate(1); }
+ to { filter: saturate(0.15); }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .board-view-container .board-column h3 .counter-badge.over-limit {
+ animation: none;
+ }
+}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 124a412a4d..dec8e8495c 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -494,6 +494,52 @@ describe("Board column rename", () => {
.toBe('board_view.card-count-with-archived:{"count":2,"archived":1}');
});
+ /** A column told how much it should hold says so, and says when it is holding more. */
+ it("shows the limit beside the count, and marks a column over it", async () => {
+ const note = buildNote({
+ title: "Board",
+ "#collection": "",
+ "#viewType": "board",
+ "#label:status(inheritable)":
+ "promoted,alias=Status,single,select,options=To Do;Done",
+ children: [
+ { title: "First", "#status": "To Do" },
+ { title: "Second", "#status": "To Do" },
+ { title: "Third", "#status": "Done" }
+ ]
+ });
+
+ const mountPoint = document.createElement("div");
+ container = mountPoint;
+ document.body.appendChild(mountPoint);
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <Harness
+ note={note}
+ noteIds={[ ...note.getChildNoteIds() ]}
+ initialConfig={{ columns: [
+ { value: "To Do", limit: 1 }, { value: "Done", limit: 4 }
+ ] }}
+ />
+ </ParentComponent.Provider>,
+ mountPoint
+ );
+ });
+ await act(async () => { await flush(); });
+
+ const badges = [ ...mountPoint.querySelectorAll(".board-column .counter-badge") ];
+ expect(badges.map(el => el.textContent)).toEqual([ "2/1", "1/4" ]);
+ // Only the one holding more than it should is marked, badge and body alike.
+ expect(badges.map(el => el.classList.contains("over-limit"))).toEqual([ true, false ]);
+ expect([ ...mountPoint.querySelectorAll(".board-column") ]
+ .map(el => el.classList.contains("over-limit"))).toEqual([ true, false ]);
+
+ // The one over its limit says so on hover, on a line of its own.
+ expect(badgeTooltip(mountPoint, 0)).toContain("board_view.card-count-over-limit");
+ expect(badgeTooltip(mountPoint, 1)).not.toContain("board_view.card-count-over-limit");
+ });
+
/** Renames the middle column, so a slot that is not the last one has to survive. */
async function renameSecondColumn(container: HTMLElement, newName: string) {
return renameColumnAt(container, 1, newName);
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index eb2f66d714..b33f359e93 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -1,6 +1,7 @@
import "./index.css";
import { createContext, TargetedKeyboardEvent } from "preact";
+import { createPortal } from "preact/compat";
import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
@@ -25,6 +26,7 @@ import Api, { getPendingWrites, PendingColumnWrites, settleColumn } from "./api"
import BoardApi from "./api";
import { DEFAULT_GROUP_BY, getStatusDefinition, INBOX_COLUMN } from "./columns";
import Column from "./column";
+import ColumnLimitDialog from "./column_limit";
import { ColumnMap, getBoardData } from "./data";
import { useBoardKeyboard } from "./keyboard";
@@ -50,6 +52,8 @@ export interface BoardColumnData {
* any other column writes the value itself, so it needs none.
*/
displayName?: string;
+ /** The note limit, absent if disabled. */
+ limit?: number;
}
interface CardDrag {
@@ -80,6 +84,7 @@ interface ColumnDrag {
interface BoardActions {
setBranchIdToEdit: Dispatch<StateUpdater<string | undefined>>;
setColumnNameToEdit: Dispatch<StateUpdater<string | undefined>>;
+ setColumnLimitToEdit: Dispatch<StateUpdater<string | undefined>>;
setDraggedCard: Dispatch<StateUpdater<CardDrag | null>>;
setDraggedColumn: (column: ColumnDrag | null) => void;
setDropPosition: (position: ColumnDrag | null) => void;
@@ -99,11 +104,12 @@ interface BoardDragState {
// Both defaults are the honest identity value rather than a stand-in, which is what lets consumers
// read these with a plain useContext(): no non-null assertion, and no guard for a provider that is
// structurally always there. Nothing is being dragged, and the setters have nothing to set.
-/* v8 ignore next 8 -- the board always provides these, so nothing but a consumer mounted outside
+/* v8 ignore next 9 -- the board always provides these, so nothing but a consumer mounted outside
it would ever call one; they exist so that consumers need no guard. */
export const BoardActionsContext = createContext<BoardActions>({
setBranchIdToEdit: () => undefined,
setColumnNameToEdit: () => undefined,
+ setColumnLimitToEdit: () => undefined,
setDraggedCard: () => undefined,
setDraggedColumn: () => undefined,
setDropPosition: () => undefined,
@@ -183,6 +189,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
const [ columnHoverIndex, setColumnHoverIndex ] = useState<number | null>(null);
const [ branchIdToEdit, setBranchIdToEdit ] = useState<string>();
const [ columnNameToEdit, setColumnNameToEdit ] = useState<string>();
+ const [ columnLimitToEdit, setColumnLimitToEdit ] = useState<string>();
/** Bumped when the definition changes, since it is read off the note rather than held in state. */
const [ definitionRevision, setDefinitionRevision ] = useState(0);
// A ref rather than state: `api` is rebuilt on every refresh, and the map has to outlive those
@@ -230,12 +237,13 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
const boardActions = useMemo<BoardActions>(() => ({
setBranchIdToEdit,
setColumnNameToEdit,
+ setColumnLimitToEdit,
setDraggedCard,
setDraggedColumn,
setDropPosition,
setDropTarget
}), [
- setBranchIdToEdit, setColumnNameToEdit, setDraggedCard,
+ setBranchIdToEdit, setColumnNameToEdit, setColumnLimitToEdit, setDraggedCard,
setDraggedColumn, setDropPosition, setDropTarget
]);
@@ -408,6 +416,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
color={storedColumns.get(column)?.color}
archived={storedColumns.get(column)?.archived}
nested={storedColumns.get(column)?.nested}
+ limit={storedColumns.get(column)?.limit}
columnIndex={index}
columns={shownColumns}
onMoveColumn={handleColumnDrop}
@@ -425,6 +434,17 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
)}
<AddNewColumn api={api} isInRelationMode={isInRelationMode} />
+ {/* Out of the board and onto the page: the dialog is positioned against
+ the window, and Bootstrap puts its backdrop on the body, so a stacking
+ context above the board would trap it underneath. */}
+ {createPortal(
+ <ColumnLimitDialog
+ api={api}
+ column={columnLimitToEdit}
+ onClose={() => setColumnLimitToEdit(undefined)}
+ />,
+ document.body
+ )}
{!isMobile() && (
<ShortcutHintButton
className="board-shortcut-hint-button"