Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): put the search parameters on a card

Elian Doran72476763b2b3
diff --git a/apps/client/src/widgets/layout/NoteTitleActions.tsx b/apps/client/src/widgets/layout/NoteTitleActions.tsx
index c8555bf625..438d7c96b2 100644
--- a/apps/client/src/widgets/layout/NoteTitleActions.tsx
+++ b/apps/client/src/widgets/layout/NoteTitleActions.tsx
@@ -37,6 +37,7 @@ function SearchProperties({ note, ntxId }: { note: FNote | null | undefined, ntx
return (note &&
<Collapsible
title={t("search_definition.search_parameters")}
+ card
initiallyExpanded={note.isInHiddenSubtree()} // not saved searches
>
<SearchDefinition note={note} ntxId={ntxId} />
diff --git a/apps/client/src/widgets/layout/PinnedAttachments.css b/apps/client/src/widgets/layout/PinnedAttachments.css
index 51401304ac..28982a823b 100644
--- a/apps/client/src/widgets/layout/PinnedAttachments.css
+++ b/apps/client/src/widgets/layout/PinnedAttachments.css
@@ -1,14 +1,6 @@
.collapsible.pinned-attachment {
margin-bottom: 1rem;
- .collapsible-inner-body {
- margin-top: 0.5em;
- padding: 0;
- overflow: hidden;
- border-radius: var(--card-border-radius, 8px);
- background: var(--card-background-color, var(--accented-background-color));
- }
-
.transcript {
height: auto;
max-height: 40vh;
diff --git a/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx b/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx
index 6de9638447..77dd833ebc 100644
--- a/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx
+++ b/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx
@@ -40,6 +40,7 @@ describe("PinnedAttachments", () => {
const sections = container.querySelectorAll(".pinned-attachment");
expect(sections).toHaveLength(1);
const [ section ] = sections;
+ expect(section.classList.contains("collapsible-card")).toBe(true);
expect(section.textContent).toContain("Transcript");
expect(section.querySelector("[aria-expanded]")?.getAttribute("aria-expanded")).toBe("true");
expect(section.querySelector(".transcript-stub")?.textContent).toBe("transcript1");
diff --git a/apps/client/src/widgets/layout/PinnedAttachments.tsx b/apps/client/src/widgets/layout/PinnedAttachments.tsx
index b6cdd65d2f..27b4ae119b 100644
--- a/apps/client/src/widgets/layout/PinnedAttachments.tsx
+++ b/apps/client/src/widgets/layout/PinnedAttachments.tsx
@@ -42,6 +42,7 @@ export default function PinnedAttachments({ note }: { note: FNote }) {
className="pinned-attachment"
title={attachment.title}
headerActions={HeaderActions && <HeaderActions attachment={attachment} />}
+ card
initiallyExpanded
>
<View attachment={attachment} />
diff --git a/apps/client/src/widgets/react/Collapsible.css b/apps/client/src/widgets/react/Collapsible.css
index ade23d1ab8..8f44b2efad 100644
--- a/apps/client/src/widgets/react/Collapsible.css
+++ b/apps/client/src/widgets/react/Collapsible.css
@@ -32,6 +32,14 @@
opacity: 0;
}
+ &.collapsible-card .collapsible-inner-body {
+ margin-top: 0.5em;
+ padding: 0;
+ overflow: hidden;
+ border-radius: var(--card-border-radius, 8px);
+ background: var(--card-background-color, var(--accented-background-color));
+ }
+
&.expanded {
.collapsible-title .arrow {
transform: rotate(90deg);
diff --git a/apps/client/src/widgets/react/Collapsible.spec.tsx b/apps/client/src/widgets/react/Collapsible.spec.tsx
new file mode 100644
index 0000000000..6eb314af49
--- /dev/null
+++ b/apps/client/src/widgets/react/Collapsible.spec.tsx
@@ -0,0 +1,36 @@
+import type { ComponentChild } from "preact";
+import { act } from "preact/test-utils";
+import { describe, expect, it } from "vitest";
+
+import { renderInto } from "../../test/render";
+import Collapsible from "./Collapsible";
+
+async function render(vnode: ComponentChild) {
+ let container: HTMLElement | undefined;
+ await act(async () => {
+ container = renderInto(vnode);
+ });
+ if (!container) {
+ throw new Error("nothing rendered");
+ }
+ return container;
+}
+
+describe("Collapsible", () => {
+ it("shows its body from the title's toggle", async () => {
+ const container = await render(<Collapsible title="Options" initiallyExpanded={false}>body</Collapsible>);
+ const title = container.querySelector<HTMLButtonElement>(".collapsible-title");
+
+ expect(title?.getAttribute("aria-expanded")).toBe("false");
+ act(() => title?.click());
+ expect(title?.getAttribute("aria-expanded")).toBe("true");
+ });
+
+ it("puts the body on a card only when asked", async () => {
+ const plain = await render(<Collapsible title="Plain">body</Collapsible>);
+ const card = await render(<Collapsible title="Card" card>body</Collapsible>);
+
+ expect(plain.querySelector(".collapsible")?.classList.contains("collapsible-card")).toBe(false);
+ expect(card.querySelector(".collapsible")?.classList.contains("collapsible-card")).toBe(true);
+ });
+});
diff --git a/apps/client/src/widgets/react/Collapsible.tsx b/apps/client/src/widgets/react/Collapsible.tsx
index 90950d8475..b97c5c0fdc 100644
--- a/apps/client/src/widgets/react/Collapsible.tsx
+++ b/apps/client/src/widgets/react/Collapsible.tsx
@@ -13,6 +13,8 @@ interface CollapsibleProps extends Pick<HTMLAttributes<HTMLDivElement>, "classNa
initiallyExpanded?: boolean;
/** Shown beside the title, also while collapsed; not part of the button that toggles. */
headerActions?: ComponentChildren;
+ /** Draws the expanded body on a card of its own, apart from what surrounds it. */
+ card?: boolean;
}
export default function Collapsible({ initiallyExpanded, ...restProps }: CollapsibleProps) {
@@ -21,7 +23,7 @@ export default function Collapsible({ initiallyExpanded, ...restProps }: Collaps
}
export function ExternallyControlledCollapsible({
- title, children, className, expanded, setExpanded, headerActions
+ title, children, className, expanded, setExpanded, headerActions, card
}: Omit<CollapsibleProps, "initiallyExpanded"> & {
expanded: boolean | undefined;
setExpanded: (expanded: boolean) => void
@@ -73,7 +75,8 @@ export function ExternallyControlledCollapsible({
return (
<div className={clsx("collapsible", className, {
expanded,
- "with-transition": transitionEnabled
+ "with-transition": transitionEnabled,
+ "collapsible-card": card
})}>
{headerActions ? (
<div className="collapsible-header">