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/search & filtering: fix some issues
Adorian Doranb4a981796a6f
diff --git a/apps/client/src/widgets/collections/board/data.ts b/apps/client/src/widgets/collections/board/data.tsindex 6b3a071ff9..73819a159c 100644--- a/apps/client/src/widgets/collections/board/data.ts+++ b/apps/client/src/widgets/collections/board/data.ts@@ -44,10 +44,7 @@ export function applyCardMove(/*** The columns with only the cards in `matchedNoteIds`, keeping their order relative to each other.- *- * A filter narrows what is drawn, nothing else: every column stays, and the full map is what column- * discovery, the config write-back and bulk operations keep reading, so filtering cannot rewrite- * the board's columns or reach fewer cards than an operation means to.+ * Every column is kept, since a filter narrows what is drawn and nothing else.*/export function filterColumnMap(byColumn: ColumnMap, matchedNoteIds: Set<string> | null@@ -66,10 +63,6 @@ export function filterColumnMap(/*** Where a card dropped among the cards on screen goes in the full column.*- * A drop is measured against the cards a filter leaves showing, and the move is written against the- * visible card it was dropped before. That card decides the place in the full column too, so the- * cards a filter hides keep their order around it.- ** @param shown the target column as it is drawn, counting the moved card where it stays in place.* @param all the same column with every card it holds.* @param index where the card goes among the ones drawn.diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 2dd46aa09d..bbef1acb7f 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -201,9 +201,8 @@ export const BoardDragStateContext = createContext<BoardDragState>({});/**- * The tokens the active filter matched by, which the cards highlight in their titles. Null while- * no filter is active. A context for the same reason the promoted attributes use one: a card is- * memoized, and the tokens change only when a query is submitted.+ * The tokens the active filter matched by, which the cards highlight in their titles. A context+ * rather than a prop, so a memoized card is not redrawn for it during a drag.*/export const BoardHighlightTokensContext = createContext<HighlightedTokenInfo[] | null>(null);@@ -350,10 +349,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveConQueryChanged: persistFilterQuery,collectionNoteIds: noteIds});- // The cards as drawn. Derived rather than held, so that what is shown cannot fall behind what- // the filter matches: a card move and a search resolving in the same moment both land here.- // Withheld until a query stored in `board.json` has said what it matches, so a filtered board- // is not drawn whole and then narrowed.+ // The cards as drawn. Derived rather than held, so what is shown cannot fall behind what the+ // filter matches, and withheld until a query stored in `board.json` has said what it matches.const byColumn = useMemo(() => (allByColumn && !filter.isResolvingStoredQuery? filterColumnMap(allByColumn, filter.matchedNoteIds)diff --git a/apps/client/src/widgets/collections/collection_filter.spec.tsx b/apps/client/src/widgets/collections/collection_filter.spec.tsxindex 86c0a230d1..3d9045abe0 100644--- a/apps/client/src/widgets/collections/collection_filter.spec.tsx+++ b/apps/client/src/widgets/collections/collection_filter.spec.tsx@@ -393,6 +393,12 @@ describe("CollectionFilterInput", () => {expect(container.querySelector(".collection-filter")?.classList.contains("active")).toBe(true);});+ // The tooltip opens on hover alone, so the name has to be on the element itself.+ it("names the box for assistive technology", () => {+ const { input } = mountInput();+ expect(input.getAttribute("aria-label")).toBe("collection_filter.placeholder");+ });+it("shows the query error under the box", () => {mountInput({ error: "broken" });expect(container.querySelector(".collection-filter-error")?.textContent).toBe("broken");diff --git a/apps/client/src/widgets/collections/collection_filter.tsx b/apps/client/src/widgets/collections/collection_filter.tsxindex d87b616fba..8e53e9bb09 100644--- a/apps/client/src/widgets/collections/collection_filter.tsx+++ b/apps/client/src/widgets/collections/collection_filter.tsx@@ -51,10 +51,7 @@ const NO_MATCHES: FilterMatches = { matchedNoteIds: null, highlightedTokens: nul/*** Narrows a collection to the notes matching a search query, using the full search syntax.- *- * The result is a membership set, not an order: a view keeps its own enumeration and leaves out- * the notes the set does not name. A search result is a snapshot, so an active filter re-runs- * when an entity change touches the collection.+ * The result is a membership set, not an order: a view keeps its own enumeration.*/export function useCollectionFilter(note: FNote, {persistedQuery, onQueryChanged, collectionNoteIds@@ -121,9 +118,8 @@ export function useCollectionFilter(note: FNote, {useEffect(() => {setQuery(persistedQuery ?? "");- // Another collection brings its own stored query, and this instance is reused across them,- // so the wait is armed again here rather than only at mount. Not for a query submitted in- // this collection, which also arrives as a new `persistedQuery`.+ // A different collection brings its own stored query, so the wait is armed again for it.+ // Not for a query submitted here, which also arrives as a new `persistedQuery`.if (previousNoteIdRef.current !== note.noteId) {previousNoteIdRef.current = note.noteId;setIsResolvingStoredQuery(!!persistedQuery?.trim());@@ -168,11 +164,8 @@ export function useCollectionFilter(note: FNote, {}/**- * The filter box for a collection header, styled after the quick search box. Enter or the search- * button submits what is typed, and the clear button beside it drops the filter.- *- * What is typed is held here until it is submitted, so an unrelated redraw cannot apply a- * half-typed query.+ * The filter box for a collection header. Enter or the search button submits what is typed, which+ * is held here until then so an unrelated redraw cannot apply a half-typed query.*/export function CollectionFilterInput({ filter, placeholder }: {filter: CollectionFilter;@@ -194,6 +187,9 @@ export function CollectionFilterInput({ filter, placeholder }: {inputRef={inputRef}currentValue={typed}placeholder={placeholder ?? t("collection_filter.placeholder")}+ // The tooltip opens on hover alone, so it cannot carry the name to a reader who+ // arrives by keyboard.+ aria-label={placeholder ?? t("collection_filter.placeholder")}onChange={setTyped}onKeyDown={(e: KeyboardEvent) => {if (e.key === "Enter") {