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
refactor(client): remove the ribbon's search parameters tab
Elian Doran21d11fba8da8
diff --git a/apps/client/src/widgets/collections/collection_filter.tsx b/apps/client/src/widgets/collections/collection_filter.tsxindex 0a8c833c65..febda90e9e 100644--- a/apps/client/src/widgets/collections/collection_filter.tsx+++ b/apps/client/src/widgets/collections/collection_filter.tsx@@ -11,7 +11,7 @@ import type LoadResults from "../../services/load_results";import searchService from "../../services/search";import ActionButton from "../react/ActionButton";import { useNoteContext, useTriliumEvent } from "../react/hooks";-import SearchStringEditor from "../ribbon/SearchStringEditor";+import SearchStringEditor from "../search/SearchStringEditor";/** How long to wait after a change before re-running the active filter. */const RERUN_DEBOUNCE_MS = 300;diff --git a/apps/client/src/widgets/layout/NoteTitleActions.tsx b/apps/client/src/widgets/layout/NoteTitleActions.tsxindex 33d36aabe4..1a64873a4c 100644--- a/apps/client/src/widgets/layout/NoteTitleActions.tsx+++ b/apps/client/src/widgets/layout/NoteTitleActions.tsx@@ -11,7 +11,7 @@ import Collapsible, { ExternallyControlledCollapsible } from "../react/Collapsibimport { useNoteContext, useNoteLabel, useNoteProperty, useTriliumEvent, useTriliumOptionBool } from "../react/hooks";import { NewNoteLink } from "../react/NoteLink";import { useEditedNotes } from "../ribbon/EditedNotesTab";-import SearchDefinitionTab from "../ribbon/SearchDefinitionTab";+import SearchDefinition from "../search/SearchDefinition";import NoteTypeSwitcher from "./NoteTypeSwitcher";export default function NoteTitleActions() {@@ -34,7 +34,7 @@ function SearchProperties({ note, ntxId }: { note: FNote | null | undefined, ntxtitle={t("search_definition.search_parameters")}initiallyExpanded={note.isInHiddenSubtree()} // not saved searches>- <SearchDefinitionTab note={note} ntxId={ntxId} hidden={false} />+ <SearchDefinition note={note} ntxId={ntxId} /></Collapsible>);}diff --git a/apps/client/src/widgets/quick_search.spec.tsx b/apps/client/src/widgets/quick_search.spec.tsxindex 6a3c74f057..172eb001bf 100644--- a/apps/client/src/widgets/quick_search.spec.tsx+++ b/apps/client/src/widgets/quick_search.spec.tsx@@ -11,7 +11,7 @@ import server from "../services/server";import { renderInto } from "../test/render";import QuickSearch from "./quick_search";import { ParentComponent } from "./react/react_utils";-import type { SearchCompletion } from "./ribbon/search_completions";+import type { SearchCompletion } from "./search/search_completions";// The completions fetch attribute names and values through the server, so a spec that opens them// supplies its own.@@ -24,7 +24,7 @@ vi.mock("../services/i18n", async (importOriginal) => ({t: (key: string, options?: object) => (options ? `${key} ${JSON.stringify(options)}` : key)}));-vi.mock("./ribbon/search_completions", () => ({+vi.mock("./search/search_completions", () => ({searchCompletionAt: (before: string, explicit: boolean) => completions.at?.(before, explicit) ?? null}));diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsxindex bfff1ef458..23200bacce 100644--- a/apps/client/src/widgets/quick_search.tsx+++ b/apps/client/src/widgets/quick_search.tsx@@ -23,7 +23,7 @@ import { pointerMoved } from "./react/menu_context";import OverlayControlGroup from "./react/OverlayControlGroup";import Popup from "./react/Popup";import RawHtml, { RawHtmlBlock } from "./react/RawHtml";-import SearchStringEditor from "./ribbon/SearchStringEditor";+import SearchStringEditor from "./search/SearchStringEditor";import { ShortcutHintOverlayButton } from "./shortcut_hints/shortcut_hint_button";/** The keys the results answer, beside the field's own, for the shortcut-hints pane. */diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.tsindex 79144d555a..6bdd22c54e 100644--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts@@ -4,16 +4,8 @@ import EditedNotesTab from "./EditedNotesTab";import ImagePropertiesTab from "./ImagePropertiesTab";import NotePropertiesTab from "./NotePropertiesTab";import { TabConfiguration } from "./ribbon-interface";-import SearchDefinitionTab from "./SearchDefinitionTab";export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [- {- title: t("search_definition.search_parameters"),- icon: "bx bx-search",- content: SearchDefinitionTab,- activate: true,- show: ({ note }) => note?.type === "search"- },{title: t("edited_notes.title"),icon: "bx bx-calendar-edit",diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionTab.css b/apps/client/src/widgets/search/SearchDefinition.csssimilarity index 100%rename from apps/client/src/widgets/ribbon/SearchDefinitionTab.cssrename to apps/client/src/widgets/search/SearchDefinition.cssdiff --git a/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx b/apps/client/src/widgets/search/SearchDefinition.tsxsimilarity index 97%rename from apps/client/src/widgets/ribbon/SearchDefinitionTab.tsxrename to apps/client/src/widgets/search/SearchDefinition.tsxindex c34c149122..f964606925 100644--- a/apps/client/src/widgets/ribbon/SearchDefinitionTab.tsx+++ b/apps/client/src/widgets/search/SearchDefinition.tsx@@ -1,4 +1,4 @@-import "./SearchDefinitionTab.css";+import "./SearchDefinition.css";import { SaveSearchNoteResponse } from "@triliumnext/commons";import { useContext, useEffect, useState } from "preact/hooks";@@ -22,10 +22,12 @@ import { useTriliumEvent } from "../react/hooks";import Icon from "../react/Icon";import { ParentComponent } from "../react/react_utils";import ResponsiveContainer from "../react/ResponsiveContainer";-import { TabContext } from "./ribbon-interface";import { SEARCH_OPTIONS, SearchOption } from "./SearchDefinitionOptions";-export default function SearchDefinitionTab({ note, ntxId, hidden }: Pick<TabContext, "note" | "ntxId" | "hidden">) {+export default function SearchDefinition({ note, ntxId }: {+ note: FNote | null | undefined;+ ntxId: string | null | undefined;+}) {const parentComponent = useContext(ParentComponent);const [ searchOptions, setSearchOptions ] = useState<{ availableOptions: SearchOption[], activeOptions: SearchOption[] }>();const [ error, setError ] = useState<{ message: string }>();@@ -71,7 +73,7 @@ export default function SearchDefinitionTab({ note, ntxId, hidden }: Pick<TabConreturn (<div className="search-definition-widget"><div className="search-settings">- {note && !hidden && (+ {note && (<table className="search-setting-table"><tbody><tr>diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsx b/apps/client/src/widgets/search/SearchDefinitionOptions.spec.tsxsimilarity index 100%rename from apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsxrename to apps/client/src/widgets/search/SearchDefinitionOptions.spec.tsxdiff --git a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx b/apps/client/src/widgets/search/SearchDefinitionOptions.tsxsimilarity index 99%rename from apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsxrename to apps/client/src/widgets/search/SearchDefinitionOptions.tsxindex 56a0d52b9c..d23b56075c 100644--- a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx+++ b/apps/client/src/widgets/search/SearchDefinitionOptions.tsx@@ -165,7 +165,7 @@ function SearchStringOption({ note, refreshResults, error, ...restProps }: Searc}const spacedUpdate = spacedUpdateRef.current;- // The ribbon reuses this component across note switches, so rebind on every render: `rebind`+ // `SearchDefinition` stays mounted across note switches, so rebind on every render: `rebind`// snapshots a still-pending change against the previous note rather than the new one (#9614).useEffect(() => {spacedUpdate.rebind(note.noteId, prepare, commit);diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx b/apps/client/src/widgets/search/SearchStringEditor.spec.tsxsimilarity index 97%rename from apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsxrename to apps/client/src/widgets/search/SearchStringEditor.spec.tsxindex 0d2dab620c..dcdcc9731f 100644--- a/apps/client/src/widgets/ribbon/SearchStringEditor.spec.tsx+++ b/apps/client/src/widgets/search/SearchStringEditor.spec.tsx@@ -14,7 +14,7 @@ vi.mock("./search_completions", () => ({}));describe("SearchStringEditor", () => {- it("replaces the document when the ribbon switches notes, focused or not", async () => {+ it("replaces the document when the search definition switches notes, focused or not", async () => {const onChange = vi.fn();const { container, editor } = await mount({ noteId: "search1", currentValue: "#book", onChange });diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.tsx b/apps/client/src/widgets/search/SearchStringEditor.tsxsimilarity index 100%rename from apps/client/src/widgets/ribbon/SearchStringEditor.tsxrename to apps/client/src/widgets/search/SearchStringEditor.tsxdiff --git a/apps/client/src/widgets/ribbon/search_completions.spec.ts b/apps/client/src/widgets/search/search_completions.spec.tssimilarity index 100%rename from apps/client/src/widgets/ribbon/search_completions.spec.tsrename to apps/client/src/widgets/search/search_completions.spec.tsdiff --git a/apps/client/src/widgets/ribbon/search_completions.ts b/apps/client/src/widgets/search/search_completions.tssimilarity index 100%rename from apps/client/src/widgets/ribbon/search_completions.tsrename to apps/client/src/widgets/search/search_completions.tsdiff --git a/apps/client/src/widgets/search_field_editor.tsx b/apps/client/src/widgets/search_field_editor.tsxindex 08cfd38d1b..ae440f7b7e 100644--- a/apps/client/src/widgets/search_field_editor.tsx+++ b/apps/client/src/widgets/search_field_editor.tsx@@ -13,7 +13,7 @@ import server from "../services/server";import { AttributeNameSuggestion, fetchAttributeNames } from "./attribute_widgets/attribute_detail";import { AutocompleteList } from "./react/FormAutocomplete";import { CommandMentionList, createHostedList, filterCommandEntries, NoteMentionList } from "./react/NoteAutocomplete";-import { type SearchCompletion, searchCompletionAt, type SearchEntry } from "./ribbon/search_completions";+import { type SearchCompletion, searchCompletionAt, type SearchEntry } from "./search/search_completions";/** The class the styles in `search_field_editor.css` are scoped under. */export const SEARCH_FIELD_EDITOR_CLASS = "search-string-editor";