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(search): show the full search's error in the same titled card
Elian Doran355dd898255b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 48028bcfdf..c9491ab61f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1533,7 +1533,7 @@"label_rock_or_pop": "only one of the labels must be present","label_year_comparison": "numerical comparison (also >, >=, <).","label_date_created": "notes created in the last month",- "error": "Search error: {{error}}",+ "error_title": "Search error","search_prefix": "Search:","hints": {"title": "Search string",@@ -2761,8 +2761,7 @@"to_results": "Move to the results","page": "Move a page through the results","close": "Close the results"- },- "error": "Search error"+ }},"note_tree": {"collapse-title": "Collapse note tree",diff --git a/apps/client/src/widgets/quick_search.spec.tsx b/apps/client/src/widgets/quick_search.spec.tsxindex cf2a387f0e..9d3abe01be 100644--- a/apps/client/src/widgets/quick_search.spec.tsx+++ b/apps/client/src/widgets/quick_search.spec.tsx@@ -123,7 +123,7 @@ describe("QuickSearch", () => {// A caution card titled as an error, with the server's message as its body.expect(error?.classList.contains("extended-admonition")).toBe(true);expect(error?.classList.contains("caution")).toBe(true);- expect(error?.querySelector(".admonition-title")?.textContent).toBe("quick-search.error");+ expect(error?.querySelector(".admonition-title")?.textContent).toBe("search_string.error_title");expect(error?.querySelector(".admonition-body")?.textContent).toBe("Note content can be searched only with operators");expect(placeholderItems()).toEqual([]);diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsxindex c8f53881fa..6d43820e43 100644--- a/apps/client/src/widgets/quick_search.tsx+++ b/apps/client/src/widgets/quick_search.tsx@@ -299,7 +299,7 @@ function QuickSearchResults({ searchState, onOpenResult }: {<ExtendedAdmonitiontype="caution"icon="bx bx-error-circle"- title={t("quick-search.error")}+ title={t("search_string.error_title")}className="quick-search-error">{searchState.error}diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsx b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsxindex 21036ef026..e7824972dd 100644--- a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsx+++ b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.spec.tsx@@ -7,6 +7,12 @@ import attributes from "../../services/attributes";import { renderInto } from "../../test/render";import { SEARCH_OPTIONS } from "./SearchDefinitionOptions";+// Echoes the key, so a spec can tell which string a title shows.+vi.mock("../../services/i18n", async (importOriginal) => ({+ ...(await importOriginal<typeof import("../../services/i18n")>()),+ t: (key: string) => key+}));+// Stands in for the CodeMirror editor, which loads on demand and is covered by its own spec.let editorProps: { noteId: string, currentValue: string, onChange(value: string): void } | undefined;vi.mock("./SearchStringEditor", () => ({@@ -55,6 +61,19 @@ describe("the search string option", () => {expect(attributes.setLabel).toHaveBeenCalledTimes(1);expect(attributes.setLabel).toHaveBeenCalledWith("search2", "searchString", "#author = tolkien");});++ it("shows the error the search ran into as a titled caution card", () => {+ const container = renderOption(noteWith("search1", "note.content > 3"), undefined, {+ message: "Note content can be searched only with operators"+ });++ const card = container.querySelector(".admonition");+ expect(card?.classList.contains("extended-admonition")).toBe(true);+ expect(card?.classList.contains("caution")).toBe(true);+ expect(card?.querySelector(".admonition-title")?.textContent).toBe("search_string.error_title");+ expect(card?.querySelector(".admonition-body")?.textContent)+ .toBe("Note content can be searched only with operators");+ });});function noteWith(noteId: string, searchString: string) {@@ -67,7 +86,7 @@ function noteWith(noteId: string, searchString: string) {} as unknown as FNote;}-function renderOption(note: FNote, container?: HTMLDivElement) {+function renderOption(note: FNote, container?: HTMLDivElement, error?: { message: string }) {const option = SEARCH_OPTIONS.find(({ attributeName }) => attributeName === "searchString");if (!option) {throw new Error("The search string option is missing from SEARCH_OPTIONS.");@@ -79,6 +98,7 @@ function renderOption(note: FNote, container?: HTMLDivElement) {<Componentnote={note}refreshResults={() => {}}+ error={error}attributeName="searchString"attributeType="label"/>diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsxindex 584c4c9a33..c69c18b4dc 100644--- a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx+++ b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx@@ -10,7 +10,7 @@ import { t } from "../../services/i18n";import server from "../../services/server";import SpacedUpdate from "../../services/spaced_update";import { openInAppHelpFromUrl } from "../../services/utils";-import Admonition from "../react/Admonition";+import { ExtendedAdmonition } from "../react/Admonition";import FormSelect from "../react/FormSelect";import FormTextBox from "../react/FormTextBox";import HelpRemoveButtons from "../react/HelpRemoveButtons";@@ -219,7 +219,13 @@ function SearchStringOption({ note, refreshResults, error, ...restProps }: Searc{error?.message && (<tr><td colspan={3}>- <Admonition type="caution">{error.message}</Admonition>+ <ExtendedAdmonition+ type="caution"+ icon="bx bx-error-circle"+ title={t("search_string.error_title")}+ >+ {error.message}+ </ExtendedAdmonition></td></tr>)}diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.htmlindex 69690baeeb..f181a8713c 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html@@ -147,6 +147,10 @@<li>Search errors which are checked by the server, without indicating theexact place the error occurred.</li></ul>+<p>An error the search only runs into while running, such as an operator+ that note content cannot be searched with, is shown in a <em>Search error</em> card+ instead: below the search string, or at the top of the <a class="reference-link"+ href="#root/_help_Ms1nauBra7gq">Quick search</a> results.</p><h3>Multiline</h3><p>Long or complicated searches can be formatted by using newlines, similarto SQL queries. Newlines are treated just like spaces.</p>diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.mdindex 5d482b0425..7357d57fa8 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md@@ -80,6 +80,8 @@ The search is also checked for errors in two phases, which will be displayed as* Linter errors which identify common error patterns and also provide a way to fix them.* Search errors which are checked by the server, without indicating the exact place the error occurred.+An error the search only runs into while running, such as an operator that note content cannot be searched with, is shown in a _Search error_ card instead: below the search string, or at the top of the <a class="reference-link" href="Quick%20search.md">Quick search</a> results.+### MultilineLong or complicated searches can be formatted by using newlines, similar to SQL queries. Newlines are treated just like spaces.