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: fix an issue
Adorian Doran070cc1fa5302
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 4f5b907daa..cfe3a175e7 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -27,15 +27,6 @@ import { useScrollFade } from "../../react/scroll_fade";*/const FOOTER_QUIET_MS = 5000;-/**- * How long the card just made is still the one the column opens out for.- *- * Long enough to cover a write that never answers, as `FOOTER_QUIET_MS` is. `created` names the- * card until another is made, and the card itself is not marked in any way, so without this a card- * dragged out of the column and back opens out again on the drop.- */-const CREATED_GROW_MS = 5000;-/** How long an open takes. Matches `--board-expand-duration` in the board's own rules. */const EXPAND_MS = 200;import NoteLink from "../../react/NoteLink";@@ -102,8 +93,15 @@ export default function Column({onFocusCard: (noteId: string) => void} & DragContext) {const [ isCreatingNewItem, setIsCreatingNewItem ] = useState(false);- const [ created, setCreated ] =- useState<{ noteId?: string, takesFocus: boolean, at: number }>();+ const [ created, setCreated ] = useState<{ noteId?: string, takesFocus: boolean }>();+ /**+ * The cards this column has opened out, each of which it opens out once.+ *+ * `created` names the card until another is made, and the card itself is marked in no way, so+ * a card dragged out of the column and back would arrive as the one just made and open out+ * again on the drop.+ */+ const grown = useRef(new Set<string>());// `isNew` stays true until another column is added, so the reveal is recorded here rather than// replayed on every redraw of the board.const [ isRevealed, setIsRevealed ] = useState(false);@@ -119,15 +117,14 @@ export default function Column({// An inserted card is left focused, since that is where the work is; a card from the footer is// not, or it would take focus from the editor being typed in.const cardInserted = useCallback(- (noteId: string | undefined) =>- setCreated({ noteId, takesFocus: true, at: Date.now() }), []);+ (noteId: string | undefined) => setCreated({ noteId, takesFocus: true }), []);const addingFromFooter = useCallback(() => {// Long enough for a write that never answers; `cardAdded` shortens it when one does.footerQuietUntil.current = Date.now() + FOOTER_QUIET_MS;}, []);const cardAdded = useCallback((noteId: string | undefined) => {footerQuietUntil.current = Date.now() + FLIP_SETTLE_MS;- setCreated({ noteId, takesFocus: false, at: Date.now() });+ setCreated({ noteId, takesFocus: false });}, []);const { setColumnNameToEdit, setColumnLimitToEdit, setActiveColumn } =useContext(BoardActionsContext);@@ -143,9 +140,16 @@ export default function Column({// `footerQuietUntil`: the scroll to the end and the fade already show it.useFlip(contentRef, {selector: ".board-note",- grow: (card) => !!created && card.getAttribute("data-note-id") === created.noteId- && Date.now() - created.at < CREATED_GROW_MS- && Date.now() > footerQuietUntil.current+ grow: (card) => {+ const noteId = card.getAttribute("data-note-id");+ if (!noteId || noteId !== created?.noteId || grown.current.has(noteId)+ || Date.now() <= footerQuietUntil.current) {+ return false;+ }++ grown.current.add(noteId);+ return true;+ }});const { handleDragOver, handleDragLeave, handleDrop } = useDragging({column, columnIndex, columnItems, isEditing, api, parentNotediff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex bf2d6159fe..0249dd4e87 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -103,6 +103,13 @@ function addCard(board: ReturnType<typeof buildNote>, status: string) {return fileCard(board, buildNote({ title: "Added", "#status": status }));}+/** Takes a card off the board, the way carrying it to another one does. */+function unfileCard(board: ReturnType<typeof buildNote>, card: ReturnType<typeof buildNote>) {+ delete froca.branches[`${board.noteId}_${card.noteId}`];+ delete board.childToBranch[card.noteId];+ board.children = board.children.filter(noteId => noteId !== card.noteId);+}+/** Puts a note the test already holds under the board, for one made before it is filed. */function fileCard(board: ReturnType<typeof buildNote>, card: ReturnType<typeof buildNote>) {const branchId = `${board.noteId}_${card.noteId}`;@@ -1440,45 +1447,50 @@ describe("Board column rename", () => {});/**- * The column names the card it just made until it makes another, so what opens out is bounded- * in time as well: a card dragged out of the column and back is not the one just made, however- * long it has been the last.+ * The column names the card it just made until it makes another, so what opens out is counted+ * as well: a card dragged out of the column and back is a card coming back, not one just made.*/- it("opens out the card it just made, and not that card once it is old", async () => {- for (const [ passed, height ] of [ [ 0, "0px" ], [ 6000, "" ] ] as const) {- const { note, container } = await setup();- withBoxes();-- try {- const card = buildNote({ title: "Made", "#status": "Doing" });- vi.spyOn(BoardApi.prototype, "insertRowAtPosition")- .mockResolvedValue({ noteId: card.noteId } as never);-- // Made here, and drawn only by the refresh that follows.- const standIn = container.querySelectorAll<HTMLElement>(".board-column")[1]- .querySelector<HTMLElement>(".board-note");- await act(async () => {- standIn?.dispatchEvent(new KeyboardEvent("keydown",- { key: "Enter", bubbles: true }));- await flush();- });-- vi.setSystemTime(Date.now() + passed);- fileCard(note, card);- await redraw(note, container);-- const arrived = [ ...container.querySelectorAll<HTMLElement>(".board-note") ]- .find(element => element.getAttribute("data-note-id") === card.noteId);- if (!arrived) throw new Error("expected the card just made to be drawn");- expect(arrived.style.height).toBe(height);- } finally {- vi.useRealTimers();- dropBoxes();- render(null, container);- }+ it("opens out the card it just made once, and not when it comes back", async () => {+ const { note, container } = await setup();+ withBoxes();++ try {+ const card = buildNote({ title: "Made", "#status": "Doing" });+ vi.spyOn(BoardApi.prototype, "insertRowAtPosition")+ .mockResolvedValue({ noteId: card.noteId } as never);++ // Made here, and drawn only by the refresh that follows.+ const standIn = container.querySelectorAll<HTMLElement>(".board-column")[1]+ .querySelector<HTMLElement>(".board-note");+ await act(async () => {+ standIn?.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));+ await flush();+ });++ fileCard(note, card);+ await redraw(note, container);+ expect(drawn(container, card.noteId).style.height).toBe("0px");++ // Carried off the column and dropped back on it, which draws it afresh both times.+ unfileCard(note, card);+ await redraw(note, container);+ fileCard(note, card);+ await redraw(note, container);++ expect(drawn(container, card.noteId).style.height).toBe("");+ } finally {+ dropBoxes();}});+ /** The element standing for a note, which a move draws afresh. */+ function drawn(container: HTMLElement, noteId: string) {+ const element = [ ...container.querySelectorAll<HTMLElement>(".board-note") ]+ .find(card => card.getAttribute("data-note-id") === noteId);+ if (!element) throw new Error(`expected ${noteId} to be drawn`);+ return element;+ }+/*** A card that arrives from somewhere else, a move between columns above all, mounts as a new* element in the column that draws it. Only the card the column itself made opens out of