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/ui/filtering: add support filter-only cards
Adorian Doranbac1140e5dad
diff --git a/apps/client/src/widgets/react/Card.spec.tsx b/apps/client/src/widgets/react/Card.spec.tsxindex 49ec3ff47c..ca8696a2b2 100644--- a/apps/client/src/widgets/react/Card.spec.tsx+++ b/apps/client/src/widgets/react/Card.spec.tsx@@ -202,7 +202,9 @@ describe("under a filter", () => {const setting = renderInto(<FilterProvider query="passphrase">- <OptionCardSection className="secret" label="Password" filterExtraKeywords="passphrase" />+ <OptionCardSection+ className="secret" label="Password" filterExtraKeywords="passphrase"+ /></FilterProvider>);@@ -210,6 +212,15 @@ describe("under a filter", () => {expect(setting.textContent).toBe("Password");});+ it("holds back a card that is there to be found rather than read", () => {+ const actions = <Card filterOnly heading="Related actions">{settings}</Card>;++ expect(renderInto(actions).querySelector(".tn-card")).toBeNull();+ expect(renderInto(+ <FilterProvider query="theme">{actions}</FilterProvider>+ ).querySelector(".tn-card")).not.toBeNull();+ });+it("keeps a section that accompanies the settings instead of being one", () => {const card = (query: string) => renderInto(<FilterProvider query={query}>diff --git a/apps/client/src/widgets/react/Card.tsx b/apps/client/src/widgets/react/Card.tsxindex dedf8eca81..c9d1f1c2b6 100644--- a/apps/client/src/widgets/react/Card.tsx+++ b/apps/client/src/widgets/react/Card.tsx@@ -51,6 +51,12 @@ export interface CardProps {* than inventing words for it: every word in it becomes one the card can be found by.*/filterExtraKeywords?: string;+ /**+ * Shows the card only while a filter is running, for content that is there to be found rather+ * than read: a page's own actions, which a search cannot otherwise reach, named and pointing at+ * the page they are carried out on.+ */+ filterOnly?: boolean;}/**@@ -65,6 +71,8 @@ export function Card(props: {children: ComponentChildren} & CardProps) {const matched = useFilterMatch(props.heading, props.description, props.filterExtraKeywords);const filtering = useIsFiltering();+ if (props.filterOnly && !filtering) return null;+return <div className={clsx("tn-card", props.className,filterRoleClass(filtering && (matched ? "match" : "scope")))}>{(props.heading || props.actions) && <h5 class="tn-card-heading">