Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: adapt the column UI behavior to support automatically sorted cards

Adorian Doran893d51c3253b
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index b2fc9a2138..d5940364b2 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import FAttribute from "../../../entities/fattribute";
+import type FBranch from "../../../entities/fbranch";
import branches from "../../../services/branches";
import attributes from "../../../services/attributes";
import { executeBulkActions } from "../../../services/bulk_action";
@@ -1847,3 +1848,98 @@ describe("how a column orders its cards", () => {
.toEqual([ { value: "To Do" }, { value: "Doing", orderBy: "title" } ]);
});
});
+
+/**
+ * A sorted column places its own cards, so nothing writes a branch position for one. The branch
+ * order is the order the reader arranged, which the column goes back to when it is sorted by hand
+ * again.
+ */
+describe("moving a card into or inside a sorted column", () => {
+ let setLabel: ReturnType<typeof vi.spyOn>;
+
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ setLabel = vi.spyOn(attributes, "setLabel").mockResolvedValue(undefined as never);
+ vi.mocked(branches.moveBeforeBranch).mockClear();
+ vi.mocked(branches.moveAfterBranch).mockClear();
+ });
+
+ function board(cards: Record<string, string[]>): ColumnMap {
+ return new Map(Object.entries(cards).map(([ column, ids ]) => [
+ column,
+ ids.map((noteId) => {
+ buildNote({ id: noteId, title: noteId });
+ return {
+ note: froca.notes[noteId],
+ branch: { branchId: `b_${noteId}` } as FBranch
+ };
+ })
+ ]));
+ }
+
+ function sortedApi(sortedColumns: string[]) {
+ return createApi(
+ {
+ columns: [ "To Do", "Done" ].map(value => ({
+ value,
+ ...(sortedColumns.includes(value) ? { orderBy: "title" } : {})
+ }))
+ },
+ [ "To Do", "Done" ],
+ undefined,
+ "status",
+ board({ "To Do": [ "a1", "a2", "a3" ], Done: [ "b1", "b2" ] }));
+ }
+
+ it("writes the value alone when a card crosses into one", async () => {
+ const { api } = sortedApi([ "Done" ]);
+
+ await api.moveWithinBoard("a2", "b_a2", 1, 0, "To Do", "Done");
+
+ expect(setLabel).toHaveBeenCalledWith("a2", "status", "Done");
+ expect(branches.moveBeforeBranch).not.toHaveBeenCalled();
+ expect(branches.moveAfterBranch).not.toHaveBeenCalled();
+ });
+
+ it("writes nothing at all for a move inside one", async () => {
+ const { api } = sortedApi([ "To Do" ]);
+
+ await api.moveWithinBoard("a1", "b_a1", 0, 2, "To Do", "To Do");
+
+ expect(branches.moveBeforeBranch).not.toHaveBeenCalled();
+ expect(branches.moveAfterBranch).not.toHaveBeenCalled();
+ });
+
+ it("still places a card in a column left in the manual order", async () => {
+ const { api } = sortedApi([ "To Do" ]);
+
+ await api.moveWithinBoard("a2", "b_a2", 1, 0, "To Do", "Done");
+
+ expect(setLabel).toHaveBeenCalledWith("a2", "status", "Done");
+ expect(branches.moveBeforeBranch).toHaveBeenCalledWith([ "b_a2" ], "b_b1");
+ });
+
+ it("sends a card across to a sorted column by value alone", async () => {
+ const { api } = sortedApi([ "Done" ]);
+
+ await api.moveToColumnEnd("a1", "b_a1", "Done");
+
+ expect(setLabel).toHaveBeenCalledWith("a1", "status", "Done");
+ expect(branches.moveAfterBranch).not.toHaveBeenCalled();
+ });
+
+ it("refuses to send a card to the head of a sorted column", async () => {
+ const { api } = sortedApi([ "To Do" ]);
+
+ await api.moveToColumnStart("a3", "b_a3", "To Do");
+
+ expect(branches.moveBeforeBranch).not.toHaveBeenCalled();
+ });
+
+ it("answers which columns order their own cards", () => {
+ const { api } = sortedApi([ "Done" ]);
+
+ expect(api.isColumnSorted("Done")).toBe(true);
+ expect(api.isColumnSorted("To Do")).toBe(false);
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 6390ec57d3..8a0d6c14ff 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -1166,8 +1166,19 @@ export default class BoardApi {
return attributes.removeOwnedLabelByName(note, this.statusAttribute);
}
+ /** Whether a column orders its own cards, which leaves no place for a move to name. */
+ isColumnSorted(column: string) {
+ return !!this.getColumnSort(column).orderBy;
+ }
+
/** Moves a card to the end of another column, where a card sent by the keyboard belongs. */
async moveToColumnEnd(noteId: string, branchId: string, targetColumn: string) {
+ // A sorted column places the card itself, so only the value it carries is written.
+ if (this.isColumnSorted(targetColumn)) {
+ await this.changeColumn(noteId, targetColumn);
+ return;
+ }
+
// What is already at the end, as far as this instance can know: nothing waits for the board
// to redraw between two keystrokes, so the column map still shows the target as it was
// before the card the last press sent. Anything sent since is remembered here instead, and
@@ -1213,6 +1224,10 @@ export default class BoardApi {
* a card, which knows the column it is in but not where it stands among the others.
*/
async moveToColumnStart(noteId: string, branchId: string, column: string) {
+ if (this.isColumnSorted(column)) {
+ return;
+ }
+
const items = this.byColumn?.get(column) ?? [];
const at = items.findIndex(item => item.branch.branchId === branchId);
if (at <= 0) {
@@ -1231,17 +1246,26 @@ export default class BoardApi {
const note = froca.getNoteFromCache(noteId);
if (!note) return;
+ // A sorted column places its own cards, so a move into or inside one writes the value
+ // alone. The branch order is left as it stands, which is the order the reader arranged
+ // and the one the column goes back to when it is sorted by hand again.
+ const isSortedTarget = this.isColumnSorted(targetColumn);
+
if (sourceColumn !== targetColumn) {
// Moving to a different column
await this.changeColumn(noteId, targetColumn);
+ if (isSortedTarget) {
+ return;
+ }
+
if (targetIndex < targetItems.length) {
const targetBranch = targetItems[targetIndex].branch;
await branches.moveBeforeBranch([ sourceBranchId ], targetBranch.branchId);
} else if (lastInTarget && lastInTarget !== sourceBranchId) {
await branches.moveAfterBranch([ sourceBranchId ], lastInTarget);
}
- } else if (sourceIndex !== targetIndex) {
+ } else if (!isSortedTarget && sourceIndex !== targetIndex) {
// Reordering within the same column
let targetBranchId: string | null = null;
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index bb396112d5..ce5a4e1b11 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -78,6 +78,8 @@ export default function Column({
totalCount,
isNew,
cardTemplates,
+ isSorted,
+ landedNoteId,
api,
parentNote,
isInRelationMode
@@ -112,6 +114,13 @@ export default function Column({
nested?: boolean,
/** The note limit, absent if disabled. */
limit?: number,
+ /**
+ * Whether the column orders its own cards. Such a column places a dropped card itself, so it
+ * opens no gap for a carried one and offers nothing that would put a card in a chosen place.
+ */
+ isSorted?: boolean,
+ /** The card just dropped here, which is revealed where the sort put it. */
+ landedNoteId?: string,
/**
* How many cards the column really holds, when an active filter leaves `columnItems` with
* fewer. The badge counts what is shown; the limit is about the real column.
@@ -145,8 +154,16 @@ export default function Column({
*/
const itemsRef = useRef(columnItems);
itemsRef.current = columnItems;
+ // A ref for the same reason: `beginInsert` below keeps one identity.
+ const isSortedRef = useRef(isSorted);
+ isSortedRef.current = isSorted;
/** Opens the field at a place among the cards, which is the index the card it makes takes. */
const beginInsert = useCallback((index: number) => {
+ // A sorted column decides where a card goes, so there is no place to open a field at.
+ if (isSortedRef.current) {
+ return;
+ }
+
setInsertBefore({ branchId: itemsRef.current?.[index]?.branch.branchId });
}, []);
/** The card the footer just made, which is revealed and scrolled to as it is drawn. */
@@ -171,7 +188,14 @@ export default function Column({
useContext(BoardDragStateContext);
// Asked about this column alone: where the gap stands changes on every step of a drag, and a
// column that the answer does not concern is left as it is rather than drawn again.
- const dropIndex = useDropIndex(column);
+ const standingDropIndex = useDropIndex(column);
+ // A sorted column shows only its border, since the card lands where the sort puts it. The
+ // column the card was picked up from keeps the hole it left, which the cards below would
+ // otherwise close up for the length of the gesture. The gap stands before the card whose
+ // place it names, so the carried card's own place is the one after it.
+ const dropIndex = !isSorted
+ ? standingDropIndex
+ : (draggedCard?.fromColumn === column ? draggedCard.index + 1 : null);
const isDropTarget = useIsDropTarget(column);
const isEditing = (columnNameToEdit === column);
const editorRef = useRef<HTMLInputElement>(null);
@@ -221,7 +245,10 @@ export default function Column({
// Read before anything is written, and `offsetTop` is no business of a transform anyway.
if (dropIndex !== null) {
const standing = cards[dropIndex];
- const last = cards[cards.length - 1];
+ // The carried card is taken out of the flow, so a gap past the last one is measured
+ // against the last card still laid out.
+ const drawn = [ ...cards ].filter(card => card.style.display !== "none");
+ const last = drawn[drawn.length - 1];
const top = standing
? standing.offsetTop
: (last ? last.offsetTop + last.offsetHeight + cardSpacing() : 0);
@@ -265,7 +292,7 @@ export default function Column({
aside.current = { from, until, room };
}, [ dropIndex, draggedCard, columnItems ]);
const { handleDragOver, handleDragLeave, handleDrop } = useDragging({
- column, columnIndex, columnItems, isEditing, api, parentNote
+ column, columnIndex, columnItems, isEditing, api, parentNote, onLanded: setCreatedNoteId
});
// Read here rather than in the badge: the column body shows an outline as well.
@@ -482,7 +509,7 @@ export default function Column({
<div
data-column={column}
className={clsx("board-column", {
- "drag-over": isDropTarget && draggedCard?.fromColumn !== column,
+ "drag-over": isDropTarget && (isSorted || 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,
@@ -619,7 +646,8 @@ export default function Column({
column={column}
index={index}
statusAttribute={api.statusAttribute}
- isNew={note.noteId === createdNoteId}
+ isNew={note.noteId === createdNoteId
+ || note.noteId === landedNoteId}
focusOnArrival={note.noteId === insertedNoteId}
isDragging={draggedCard?.noteId === note.noteId}
isEditing={branch.branchId === branchIdToEdit}
@@ -639,6 +667,7 @@ export default function Column({
api={api}
cardTemplates={cardTemplates}
column={column}
+ isSorted={isSorted}
isCreating={isCreatingNewItem}
setIsCreating={setIsCreatingNewItem}
onCreated={setCreatedNoteId}
@@ -726,11 +755,13 @@ let restoring: number | undefined;
* cards it is opened by a card's own menu, and `insert` says where it stands.
*/
function AddNewItem({
- column, api, cardTemplates, isCreating, setIsCreating, onCreated, insert
+ column, api, cardTemplates, isCreating, setIsCreating, onCreated, insert, isSorted
}: {
column: string,
api: BoardApi,
cardTemplates: CardTemplates,
+ /** Whether the column orders its own cards, which leaves the reader no end to pick. */
+ isSorted?: boolean,
isCreating?: boolean,
setIsCreating?: (isCreating: boolean) => void,
/** Names the card just made, which the column shows once the board has drawn it. */
@@ -836,8 +867,9 @@ function AddNewItem({
}}
submitTitle={t("board_view.create-new-note")}
// Only the field below the column offers both ends. One standing among the
- // cards is already at the end the reader asked for.
- openPlacements={!insert ? openCreateCardMenu : undefined}
+ // cards is already at the end the reader asked for, and a sorted column places
+ // the card itself.
+ openPlacements={!insert && !isSorted ? openCreateCardMenu : undefined}
footer={(hold) => <CardTemplatePill {...cardTemplates} {...hold} />}
icon={{
current: icon,
@@ -894,7 +926,15 @@ ${warning}` : counts}
);
}
-function useDragging({ column, columnIndex, columnItems, isEditing, api, parentNote }: DragContext & { isEditing: boolean, api: BoardApi, parentNote: FNote }) {
+function useDragging({
+ column, columnIndex, columnItems, isEditing, api, parentNote, onLanded
+}: DragContext & {
+ isEditing: boolean,
+ api: BoardApi,
+ parentNote: FNote,
+ /** Names a card a sorted column has just placed, which is revealed where it went. */
+ onLanded: (noteId: string) => void
+}) {
const { setDraggedColumn, setDropTarget, setDropPosition, setActiveColumn } =
useContext(BoardActionsContext);
const { draggedColumn } = useContext(BoardDragStateContext);
@@ -994,9 +1034,14 @@ function useDragging({ column, columnIndex, columnItems, isEditing, api, parentN
const parentNoteId = parentNote.noteId;
if (!standing) return;
+ // A sorted column places the card itself, so the note is added at the end of the
+ // board's children and nothing is written against the card it was dropped over.
+ const isSorted = api.isColumnSorted(column);
const targetIndex = standing.index - 1;
const targetItems = columnItems || [];
- const targetBranch = targetIndex >= 0 ? targetItems[targetIndex].branch : null;
+ const targetBranch = !isSorted && targetIndex >= 0
+ ? targetItems[targetIndex].branch
+ : null;
await api.changeColumn(noteId, column);
@@ -1011,8 +1056,17 @@ function useDragging({ column, columnIndex, columnItems, isEditing, api, parentN
} else if (targetBranch) {
await branches.moveAfterBranch([ branchId ], targetBranch.branchId);
}
+
+ // The reader dropped the card on the column rather than at a place in it, so the
+ // reveal is what says where the sort put it.
+ if (isSorted) {
+ onLanded(noteId);
+ }
}
- }, [ api, draggedColumn, dropState, columnItems, column, setDropTarget, setDropPosition ]);
+ }, [
+ api, draggedColumn, dropState, columnItems, column, setDropTarget, setDropPosition,
+ onLanded
+ ]);
return { handleColumnDragStart, handleColumnDragEnd, handleDragOver, handleDragLeave, handleDrop };
}
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 ea27953e2d..c64b06ecf5 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -595,6 +595,30 @@ describe("Board item context menu", () => {
item && "uiIcon" in item && item.uiIcon === "bx bx-vertical-top")).toBe(false);
});
+ /**
+ * A sorted column decides where its cards go, so the entries that name a place would promise
+ * something the column would not do.
+ */
+ it("offers no place to insert at, and no move to the head, in a sorted column", () => {
+ const api = {
+ columns: [],
+ isColumnArchived: () => false,
+ getColumnIcon: () => DEFAULT_COLUMN_ICON,
+ getColumnColorClass: () => "",
+ isColumnSorted: () => true,
+ isFirstInColumn: () => false
+ } as unknown as BoardApi;
+
+ const icons = openItemMenu(api)
+ .map(item => (item && "uiIcon" in item ? item.uiIcon : undefined));
+
+ expect(icons).not.toContain("bx bx-list-plus");
+ expect(icons).not.toContain("bx bx-vertical-top");
+ // What the menu still offers, so the gate is about the places alone.
+ expect(icons).toContain("bx bx-rename");
+ expect(icons).toContain("bx bx-outline");
+ });
+
it("copies a card into the board, after the one it was made from", async () => {
const api = {
columns: [ "To Do" ],
@@ -694,13 +718,14 @@ describe("Board item context menu", () => {
pageY: 0
} as ContextMenuEvent;
- // Every item menu asks what the board calls its grouping field; a test says so only when
- // that is what it is about.
+ // Every item menu asks what the board calls its grouping field and whether the column
+ // sorts itself; a test answers only where that is what it is about.
const withDefaults = Object.assign(
{
getStatusLabel: () => "Status",
getColumnTitle: (name: string) => name,
- isFirstInColumn: () => false
+ isFirstInColumn: () => false,
+ isColumnSorted: () => false
},
api);
openNoteContextMenu(
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index d6dba8ee09..d6facbe40d 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -471,6 +471,9 @@ export function openNoteContextMenu(
event.preventDefault();
event.stopPropagation();
+ // A sorted column decides where its cards go, so nothing that names a place is offered.
+ const isSorted = api.isColumnSorted(column);
+
contextMenu.show({
x: event.pageX,
y: event.pageY,
@@ -483,20 +486,22 @@ export function openNoteContextMenu(
handler: () => api.startEditing(branchId)
},
{ kind: "separator" },
- {
- title: t("board_view.insert-above"),
- uiIcon: "bx bx-list-plus",
- shortcut: "Shift+Enter",
- handler: () => onInsert(index)
- },
- {
- title: t("board_view.insert-below"),
- uiIcon: "bx bx-empty",
- shortcut: "Enter",
- handler: () => onInsert(index + 1)
- },
+ ...(isSorted ? [] : [
+ {
+ title: t("board_view.insert-above"),
+ uiIcon: "bx bx-list-plus",
+ shortcut: "Shift+Enter",
+ handler: () => onInsert(index)
+ },
+ {
+ title: t("board_view.insert-below"),
+ uiIcon: "bx bx-empty",
+ shortcut: "Enter",
+ handler: () => onInsert(index + 1)
+ }
+ ]),
// Left out for the card already at the head, which has nowhere to go.
- ...(api.isFirstInColumn(branchId, column) ? [] : [ {
+ ...(isSorted || api.isFirstInColumn(branchId, column) ? [] : [ {
title: t("board_view.move-to-top"),
uiIcon: "bx bx-vertical-top",
shortcut: "Ctrl+Home",
diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsx
index a3b43d4ae6..d4dbe3f903 100644
--- a/apps/client/src/widgets/collections/board/drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx
@@ -91,6 +91,80 @@ describe("Board drag and drop", () => {
expect(columns[0].querySelector(".board-drop-placeholder")).toBeTruthy();
});
+ /**
+ * A sorted column places the card itself, so there is no place to open a gap at. The border
+ * is what says the column would take the card.
+ */
+ it("opens no gap over a sorted column, and marks its border instead", async () => {
+ const { columns } = await renderBoard({ orderBy: "title" });
+
+ await drag(columns[0], "dragover", { types: [ TREE_CLIPBOARD_TYPE ] }, 120);
+
+ expect(columns[0].querySelector(".board-drop-placeholder.show")).toBeNull();
+ expect(columns[0].classList.contains("drag-over")).toBe(true);
+ expect([ ...columns[0].querySelectorAll<HTMLElement>(".board-note") ]
+ .map(card => card.style.transform !== "")).toEqual([ false, false ]);
+ });
+
+ it("adds a note dropped on a sorted column without placing it against a card", async () => {
+ const { columns } = await renderBoard({ orderBy: "title" });
+ const stranger = buildNote({ title: "Stranger" });
+
+ // Over the second card, which is where a manual column would clone it after.
+ await drag(columns[0], "dragover", { types: [ TREE_CLIPBOARD_TYPE ] }, 120);
+ await drag(columns[0], "drop", {
+ types: [ TREE_CLIPBOARD_TYPE ],
+ data: { text: JSON.stringify([ { noteId: stranger.noteId, branchId: "far" } ]) }
+ });
+
+ expect(branches.cloneNoteToParentNote)
+ .toHaveBeenCalledWith(stranger.noteId, expect.any(String));
+ expect(branches.cloneNoteAfter).not.toHaveBeenCalled();
+ });
+
+ /** The reader chose a column, not a place in it, so the card says where it went. */
+ it("reveals the card a sorted column placed", async () => {
+ const { columns, cards } = await renderBoard({ orderBy: "title" });
+ expect(columns[0].querySelector(".board-note.appearing")).toBeNull();
+
+ // A card already on the board, so what is drawn afterwards is the one just dropped.
+ await drag(columns[0], "dragover", { types: [ TREE_CLIPBOARD_TYPE ] }, 120);
+ await drag(columns[0], "drop", {
+ types: [ TREE_CLIPBOARD_TYPE ],
+ data: { text: JSON.stringify([ cards[1] ]) }
+ });
+ await act(async () => { await settle(); });
+
+ expect(columns[0].querySelector(".board-note.appearing")
+ ?.getAttribute("data-note-id")).toBe(cards[1].noteId);
+ });
+
+ /**
+ * The card is taken out of the flow the moment it is picked up. Without the gap, the cards
+ * below it close up and stay closed for the length of the gesture, even though the column
+ * cannot take the card anywhere the reader points it.
+ */
+ it("keeps the hole a card left in the sorted column it was picked up from", async () => {
+ const { columns } = await renderBoard({ orderBy: "title" });
+ await act(async () => { await settle(); });
+
+ const card = columns[0].querySelector<HTMLElement>(".board-note");
+ if (!card) throw new Error("expected a card");
+
+ await pointer(card, "pointerdown", 50, 50);
+ await pointer(columns[0], "pointermove", 50, 300);
+ await act(async () => { await settle(); });
+
+ expect(columns[0].querySelector(".board-drop-placeholder.show")).toBeTruthy();
+ // The card below the hole stands aside for it, as it does over a column sorted by hand.
+ expect([ ...columns[0].querySelectorAll<HTMLElement>(".board-note") ]
+ .map(other => other.style.transform !== "")).toEqual([ false, true ]);
+
+ await pointer(columns[0], "pointerup", 50, 300);
+ await act(async () => { await settle(); });
+ expect(columns[0].querySelector(".board-drop-placeholder.show")).toBeNull();
+ });
+
it("ignores a drag carrying something the board has no use for", async () => {
const { columns } = await renderBoard();
@@ -402,7 +476,8 @@ describe("Board drag and drop", () => {
/** A board of one column of two cards, each given a height the pointer can be placed in. */
async function renderBoard(
- { collapsed, saveConfig }: { collapsed?: boolean, saveConfig?: () => void } = {}
+ { collapsed, saveConfig, orderBy }:
+ { collapsed?: boolean, saveConfig?: () => void, orderBy?: string } = {}
) {
const note = buildNote({
title: "Board",
@@ -426,7 +501,7 @@ describe("Board drag and drop", () => {
notePath={`root/${note.noteId}`}
noteIds={[ ...note.getChildNoteIds() ]}
highlightedTokens={null}
- viewConfig={{ columns: [ { value: "To Do", collapsed } ] }}
+ viewConfig={{ columns: [ { value: "To Do", collapsed, orderBy } ] }}
saveConfig={saveConfig ?? (() => {})}
media="screen"
onReady={() => {}}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index b83bbce3cf..d4cef3a7bd 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -297,6 +297,13 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
const [ draggedCard, setDraggedCard ] = useState<CardDrag | null>(null);
/** The column just added, which is revealed once the board has drawn it. */
const [ createdColumn, setCreatedColumn ] = useState<string>();
+ /**
+ * The card just dropped on a sorted column, which is shown the way a new one is.
+ *
+ * The column places it rather than the reader, so it can land anywhere among the cards, and
+ * the reveal is what says where it went.
+ */
+ const [ landedNoteId, setLandedNoteId ] = useState<string>();
/**
* Where the gap stands, kept out of the board's state so that a step of a drag draws no column
* the gap is not near.
@@ -688,15 +695,29 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// separate frames the reader sees a gap open where nothing is being carried any more.
closeGaps(containerRef.current);
const branchId = byColumn?.get(card.fromColumn)?.[card.index]?.branch.branchId;
+ const isSortedTarget = !!position && columnSorts.has(position.column);
+ // A card let go of over its own sorted column stands where the sort already puts it.
+ if (isSortedTarget && position?.column === card.fromColumn) {
+ setDraggedCard(null);
+ dropState.set({ position: null, target: null });
+ focusCard(card.noteId);
+ return;
+ }
+
if (position && branchId && byColumn && allByColumn) {
// Drawn at once, into `allByColumn` since that is what `byColumn` derives from, at
// the index `unfilteredCardIndex` translates rather than the visible drop index.
+ // A sorted column takes the card at any index: `sortColumnMap` runs afterwards and
+ // places it.
setAllByColumn(applyCardMove(
allByColumn, card.noteId, card.fromColumn, position.column,
unfilteredCardIndex(
byColumn.get(position.column) ?? [],
allByColumn.get(position.column) ?? [],
position.index)));
+ if (isSortedTarget) {
+ setLandedNoteId(card.noteId);
+ }
movesInFlight.current++;
// Any refresh already on its way is about the board as it stood before the drop,
// and would put the card back where it came from as it resolves.
@@ -999,6 +1020,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
onFocusCard={focusCard}
columnItems={byColumn.get(column)}
totalCount={allByColumn?.get(column)?.length}
+ isSorted={columnSorts.has(column)}
+ landedNoteId={landedNoteId}
isNew={column === createdColumn}
/>
</Fragment>
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index 9c696968fc..a7c5f07a73 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -466,6 +466,21 @@ describe("Board keyboard", () => {
.toHaveBeenCalledWith([ branchOf(board, "First") ], branchOf(board, "Second"));
});
+ /** A sorted column decides its own order, so there is nowhere for a card to be sent. */
+ it("does not move a card up or down inside a sorted column", async () => {
+ const board = await renderBoard(undefined, "title");
+ focusCard(board, 0, 1);
+
+ press(board, "ArrowUp", { ctrlKey: true });
+ press(board, "Home", { ctrlKey: true });
+ focusCard(board, 0, 0);
+ press(board, "ArrowDown", { ctrlKey: true });
+ press(board, "End", { ctrlKey: true });
+
+ expect(branches.moveBeforeBranch).not.toHaveBeenCalled();
+ expect(branches.moveAfterBranch).not.toHaveBeenCalled();
+ });
+
it("sends a card to the end of the column beside it, keeping focus", async () => {
const board = await renderBoard();
focusCard(board, 0, 0);
@@ -856,7 +871,7 @@ describe("Board keyboard", () => {
let boardNote: ReturnType<typeof buildNote>;
/** Two columns of cards, one empty column, and the button that adds another. */
- async function renderBoard(collapsed?: string) {
+ async function renderBoard(collapsed?: string, orderBy?: string) {
boardNote = buildNote({
title: "Board",
"#collection": "",
@@ -883,7 +898,8 @@ describe("Board keyboard", () => {
viewConfig={{
columns: [ "To Do", "Doing", "Done" ].map(value => ({
value,
- collapsed: value === collapsed ? true : undefined
+ collapsed: value === collapsed ? true : undefined,
+ orderBy: value === "To Do" ? orderBy : undefined
}))
}}
saveConfig={(config) => saved.push(config)}