Skip to content

Build your personal knowledge base with Trilium Notes

client/search: use a card section for each entry from the Search Parameters section

Adorian Dorana969d82c84bb
diff --git a/apps/client/src/widgets/bulk_actions/BulkAction.css b/apps/client/src/widgets/bulk_actions/BulkAction.css
index 3d44c89e5c..be86e3faee 100644
--- a/apps/client/src/widgets/bulk_actions/BulkAction.css
+++ b/apps/client/src/widgets/bulk_actions/BulkAction.css
@@ -96,56 +96,25 @@ body[dir=rtl] .bulk-action-arrow {
transform: scaleX(-1);
}
-/* A list of actions, shown whole in the bulk-actions dialog and in the search parameters. */
-.bulk-existing-action-list {
- width: 100%;
-
- tr:not(:last-child) {
- border-bottom: 1px solid var(--main-border-color);
- }
-
- td {
- padding: 8px 12px;
- }
-
- .title-column {
- width: 1%;
- white-space: nowrap;
- }
+.bulk-action {
+ display: grid;
+ grid-template-columns: var(--bulk-action-title-column, 12em) minmax(0, 1fr) auto;
+ align-items: center;
+ column-gap: 12px;
+ row-gap: 4px;
.bulk-action-fields :is(.form-control, .form-select, .input-group-text) {
padding-block: 0.25rem;
}
-
- .button-column {
- width: 1%;
- padding-inline-start: 0;
- }
}
@container (width < 560px) {
- .bulk-existing-action-list {
- tr {
- display: grid;
- grid-template-columns: 1fr auto;
- }
-
- .title-column {
- width: auto;
- white-space: normal;
- }
+ .bulk-action {
+ grid-template-columns: minmax(0, 1fr) auto;
- .bulk-action-fields-column {
+ > .bulk-action-fields {
grid-column: 1 / -1;
grid-row: 2;
- padding-top: 0;
- }
-
- .button-column {
- width: auto;
- }
-
- .bulk-action-fields {
flex-wrap: wrap;
> :not(.bulk-action-name, .bulk-action-arrow) {
diff --git a/apps/client/src/widgets/bulk_actions/BulkAction.tsx b/apps/client/src/widgets/bulk_actions/BulkAction.tsx
index 5cb925cf6e..7886457457 100644
--- a/apps/client/src/widgets/bulk_actions/BulkAction.tsx
+++ b/apps/client/src/widgets/bulk_actions/BulkAction.tsx
@@ -7,6 +7,7 @@ import { useCallback, useEffect, useRef } from "preact/hooks";
import { t } from "../../services/i18n";
import { AttributeNameSuggestion, fetchAttributeNames } from "../attribute_widgets/attribute_detail";
import { useLabelValueSuggestions } from "../attribute_widgets/label_value_input";
+import { CardSection } from "../react/Card";
import FormAutocomplete from "../react/FormAutocomplete";
import { useSpacedUpdate } from "../react/hooks";
import HelpRemoveButtons from "../react/HelpRemoveButtons";
@@ -22,22 +23,19 @@ const BulkAction = memo(({ children, bulkAction }: BulkActionProps) => {
const { actionIcon, actionTitle, actionDescription } = bulkAction.constructor as typeof AbstractBulkAction;
return (
- <tr>
- <td className="title-column">
+ <CardSection className="bulk-action">
+ <span className="bulk-action-title">
{actionIcon && <Icon icon={actionIcon} className="bulk-action-icon" />}{actionTitle}
- </td>
- <td className="bulk-action-fields-column">
- <div className="bulk-action-fields">
- {children ?? <span className="bulk-action-description">{actionDescription}</span>}
- </div>
- </td>
- <td className="button-column">
- <HelpRemoveButtons
- removeText={t("bulk_actions.remove_action")}
- onRemove={() => bulkAction?.deleteAction()}
- />
- </td>
- </tr>
+ </span>
+ <div className="bulk-action-fields">
+ {children ?? <span className="bulk-action-description">{actionDescription}</span>}
+ </div>
+ <HelpRemoveButtons
+ className="bulk-action-actions"
+ removeText={t("bulk_actions.remove_action")}
+ onRemove={() => bulkAction?.deleteAction()}
+ />
+ </CardSection>
);
});
diff --git a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
index 0844fdcac3..d437a3fdd9 100644
--- a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
+++ b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
@@ -78,7 +78,13 @@ describe("BulkActionsDialog", () => {
}
function labelNameInputs() {
- return [ ...container.querySelectorAll<HTMLInputElement>(".bulk-existing-action-list input.bulk-action-name") ];
+ return [ ...container.querySelectorAll<HTMLInputElement>(".bulk-action input.bulk-action-name") ];
+ }
+
+ /** The chosen actions, each a segment of the actions card. */
+ function chosenActionRows() {
+ return [ ...container.querySelectorAll<HTMLElement>(
+ ".bulk-actions-chosen-actions > .tn-card-body > .tn-card-section.bulk-action") ];
}
/** Types `value` into `input`, lets the debounced lookup run and returns the suggestion rows. Needs fake timers. */
@@ -146,15 +152,15 @@ describe("BulkActionsDialog", () => {
it("marks each chosen action with its icon", async () => {
buildNote({ id: "_bulkAction", title: "Bulk action", "#action": JSON.stringify({ name: "deleteNote" }) });
await open([ "n1" ]);
- expect(container.querySelectorAll(".bulk-existing-action-list tr")).toHaveLength(1);
+ expect(chosenActionRows()).toHaveLength(1);
- const icon = container.querySelector(".bulk-existing-action-list .bulk-action-icon");
+ const icon = container.querySelector(".bulk-action .bulk-action-icon");
expect(icon?.classList.contains("bx-note")).toBe(true);
expect(icon?.classList.contains("bulk-action-marker-delete")).toBe(true);
expect(icon?.classList.contains("destructive-action-icon")).toBe(true);
- expect(container.querySelector(".bulk-existing-action-list .tn-chip-remove, .bulk-existing-action-list .search-option-del"))
+ expect(container.querySelector(".bulk-action .tn-chip-remove, .bulk-action .search-option-del"))
.not.toBeNull();
- expect(container.querySelector(".bulk-existing-action-list .help-dropdown")).toBeNull();
+ expect(container.querySelector(".bulk-action .help-dropdown")).toBeNull();
});
it("names each chosen action by its menu title alone, with an arrow only between two fields", async () => {
@@ -164,12 +170,12 @@ describe("BulkActionsDialog", () => {
"#action": bulk_action.ACTION_CLASSES.map(({ actionName }) => JSON.stringify({ name: actionName }))
});
await open([ "n1" ]);
- const rows = [ ...container.querySelectorAll<HTMLTableRowElement>(".bulk-existing-action-list tr") ];
+ const rows = chosenActionRows();
expect(rows).toHaveLength(bulk_action.ACTION_CLASSES.length);
for (const [ index, ActionClass ] of bulk_action.ACTION_CLASSES.entries()) {
const row = rows[index];
- const content = row.cells[0].cloneNode(true) as HTMLElement;
+ const content = row.children[0].cloneNode(true) as HTMLElement;
for (const field of content.querySelectorAll("select, .template-field")) field.remove();
expect(content.textContent?.trim(), ActionClass.actionName).toBe(ActionClass.actionTitle);
expect(row.querySelectorAll(".tn-icon:not(.bulk-action-arrow)"), ActionClass.actionName).toHaveLength(1);
@@ -205,22 +211,28 @@ describe("BulkActionsDialog", () => {
"#action": bulk_action.ACTION_CLASSES.map(({ actionName }) => JSON.stringify({ name: actionName }))
});
await open([ "n1" ]);
- const rows = [ ...container.querySelectorAll<HTMLTableRowElement>(".bulk-existing-action-list tr") ];
+ const rows = chosenActionRows();
expect(rows).toHaveLength(bulk_action.ACTION_CLASSES.length);
for (const [ index, ActionClass ] of bulk_action.ACTION_CLASSES.entries()) {
const { actionName, actionDescription } = ActionClass;
const row = rows[index];
- expect([ ...row.cells ].map((cell) => cell.className), actionName)
- .toStrictEqual([ "title-column", "bulk-action-fields-column", "button-column" ]);
-
- const fields = [ ...row.cells[1].querySelectorAll<HTMLInputElement>("input:not([type=hidden]), select") ];
+ expect([ ...row.children ].map((child) => child.className), actionName)
+ .toStrictEqual([
+ "bulk-action-title",
+ "bulk-action-fields",
+ "help-remove-buttons bulk-action-actions"
+ ]);
+
+ const fields = [
+ ...row.children[1].querySelectorAll<HTMLInputElement>("input:not([type=hidden]), select")
+ ];
expect(fields.map((field) => field.required), actionName).toStrictEqual(expected[actionName].required);
expect(fields.map((field) => field.classList.contains("bulk-action-name")), actionName)
.toStrictEqual(expected[actionName].names);
expect(row.querySelector("[style*='flex-shrink']"), actionName).toBeNull();
- const hasFields = row.cells[1].querySelector(".bulk-action-fields > *:not(.bulk-action-description)");
+ const hasFields = row.querySelector(".bulk-action-fields > *:not(.bulk-action-description)");
expect(row.querySelector(".bulk-action-description")?.textContent, actionName)
.toBe(hasFields ? undefined : actionDescription);
}
@@ -339,7 +351,7 @@ describe("BulkActionsDialog", () => {
await open([ "n1" ]);
const valueInput = container.querySelector<HTMLInputElement>(
- ".bulk-existing-action-list .bulk-action-fields input:not(.bulk-action-name)");
+ ".bulk-action .bulk-action-fields input:not(.bulk-action-name)");
const suggestions = await typeAndSuggest(valueInput ?? undefined, "doi");
expect(suggestions.map((li) => li.textContent)).toStrictEqual([ "doing" ]);
expect(await savedAction()).toStrictEqual({ name: "updateLabelValue", labelName: "status", labelValue: "doi" });
@@ -375,7 +387,7 @@ describe("BulkActionsDialog", () => {
input.value = "ab";
input.dispatchEvent(new Event("input", { bubbles: true }));
});
- const remove = container.querySelector<HTMLElement>(".bulk-existing-action-list .search-option-del");
+ const remove = container.querySelector<HTMLElement>(".bulk-action .search-option-del");
expect(remove).not.toBeNull();
await act(async () => remove?.click());
expect(server.remove).toHaveBeenCalledWith(`notes/_bulkAction/attributes/${attributeId}`);
@@ -398,7 +410,7 @@ describe("BulkActionsDialog", () => {
await open([ "n1" ]);
server.remove.mockRejectedValueOnce(new Error("offline"));
- await act(async () => container.querySelector<HTMLElement>(".bulk-existing-action-list .search-option-del")?.click());
+ await act(async () => container.querySelector<HTMLElement>(".bulk-action .search-option-del")?.click());
expect(server.remove).toHaveBeenCalledOnce();
const [ input ] = labelNameInputs();
diff --git a/apps/client/src/widgets/dialogs/bulk_actions.tsx b/apps/client/src/widgets/dialogs/bulk_actions.tsx
index 779fbf75b5..92f651f164 100644
--- a/apps/client/src/widgets/dialogs/bulk_actions.tsx
+++ b/apps/client/src/widgets/dialogs/bulk_actions.tsx
@@ -178,15 +178,9 @@ function ExistingActionsList({ existingActions }: { existingActions: AbstractBul
);
}
- return (
- <CardSection noPadding>
- <table class="bulk-existing-action-list">
- <tbody>
- {existingActions.map((action) => (
- <Fragment key={action.attribute.attributeId}>{action.doRender()}</Fragment>
- ))}
- </tbody>
- </table>
- </CardSection>
- );
+ return <>
+ {existingActions.map((action) => (
+ <Fragment key={action.attribute.attributeId}>{action.doRender()}</Fragment>
+ ))}
+ </>;
}
diff --git a/apps/client/src/widgets/search/SearchDefinition.css b/apps/client/src/widgets/search/SearchDefinition.css
index 443a3fd8ba..356cbdabda 100644
--- a/apps/client/src/widgets/search/SearchDefinition.css
+++ b/apps/client/src/widgets/search/SearchDefinition.css
@@ -1,5 +1,6 @@
.search-definition-widget {
--search-title-column: 12em;
+ --bulk-action-title-column: var(--search-title-column);
.search-definition-add {
display: flex;
@@ -9,15 +10,6 @@
gap: 8px;
}
- .search-definition-options > * {
- padding: 8px 12px;
- border-bottom: 1px solid var(--main-border-color);
- }
-
- .search-definition-rows > .search-definition-options:last-child > :last-child {
- border-bottom: 0;
- }
-
.search-option {
display: grid;
grid-template-columns: var(--search-title-column) minmax(0, 1fr) auto;
@@ -79,12 +71,6 @@
flex: 1 1 16rem;
}
- /* The bulk action rows share the option rows' title column. */
- .bulk-existing-action-list .title-column {
- width: calc(var(--search-title-column) + 12px);
- white-space: normal;
- }
-
.search-option-field-label {
white-space: nowrap;
}
@@ -143,10 +129,6 @@ body.mobile .search-definition-widget {
grid-row: 2;
}
}
-
- .search-definition-widget .bulk-existing-action-list .title-column {
- width: auto;
- }
}
@media (max-width: 720px) {
diff --git a/apps/client/src/widgets/search/SearchDefinition.spec.tsx b/apps/client/src/widgets/search/SearchDefinition.spec.tsx
index 4dda0155e8..0ef663b978 100644
--- a/apps/client/src/widgets/search/SearchDefinition.spec.tsx
+++ b/apps/client/src/widgets/search/SearchDefinition.spec.tsx
@@ -1,6 +1,7 @@
import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import FAttribute from "../../entities/fattribute";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
import bulk_action from "../../services/bulk_action";
@@ -8,6 +9,8 @@ import search from "../../services/search";
import server from "../../services/server";
import toast from "../../services/toast";
import { renderInto } from "../../test/render";
+import { ActionDefinition } from "../bulk_actions/abstract_bulk_action";
+import DeleteNoteBulkAction from "../bulk_actions/note/delete_note";
import SearchDefinition from "./SearchDefinition";
// Echoes the key, so a spec can find a button by its label.
@@ -44,16 +47,35 @@ afterEach(() => {
});
describe("the search definition", () => {
- it("lays the parameters out as rows of a card, as the bulk actions dialog does", () => {
+ it("lays each parameter and bulk action out as a segment of the card", () => {
+ vi.spyOn(bulk_action, "parseActions").mockReturnValue([
+ new DeleteNoteBulkAction({ attributeId: "action1" } as FAttribute, {} as ActionDefinition)
+ ]);
+ const container = renderDefinition([ "searchString", "fastSearch" ]);
+ const segments = [
+ ...container.querySelectorAll(".search-definition-widget > .tn-card > .tn-card-body > *")
+ ];
+
+ expect(segments.map((segment) => segment.matches(".tn-card-section")))
+ .toStrictEqual([ true, true, true, true ]);
+ expect(segments[0]?.matches(".search-option.searchString")).toBe(true);
+ expect(segments[1]?.matches(".search-option.fastSearch")).toBe(true);
+ expect(segments[2]?.matches(".bulk-action")).toBe(true);
+ expect(segments[3]?.matches(".search-definition-actions")).toBe(true);
+ expect(segments[3]?.querySelector(".search-definition-add")).not.toBeNull();
+ expect(segments[3]?.querySelector(".tn-split-button")).not.toBeNull();
+ });
+
+ it("shows a search error as a segment under the search string", async () => {
+ vi.spyOn(search, "runSearchNote").mockResolvedValue({ error: "Unexpected token" });
const container = renderDefinition();
- const card = container.querySelector(".search-definition-widget > .tn-card");
- expect(card).not.toBeNull();
- expect(card?.querySelector(".search-definition-options .search-option.searchString")).not.toBeNull();
+ act(() => editorProps?.onEnter());
+ await settle();
- const actionsRow = card?.querySelector(".tn-card-section.search-definition-actions");
- expect(actionsRow?.querySelector(".search-definition-add")).not.toBeNull();
- expect(actionsRow?.querySelector(".tn-split-button")).not.toBeNull();
+ const error = container.querySelector(
+ ".search-option.searchString + .tn-card-section.search-definition-error");
+ expect(error?.textContent).toContain("Unexpected token");
});
it("describes an option that configures nothing instead of offering help", () => {
diff --git a/apps/client/src/widgets/search/SearchDefinition.tsx b/apps/client/src/widgets/search/SearchDefinition.tsx
index bf75013e48..35f513a42d 100644
--- a/apps/client/src/widgets/search/SearchDefinition.tsx
+++ b/apps/client/src/widgets/search/SearchDefinition.tsx
@@ -85,27 +85,23 @@ export default function SearchDefinition({ note, ntxId }: {
<div className="search-definition-widget">
{note && (
<Card className="search-definition-card">
- {(searchOptions?.activeOptions.length || bulkActions.length > 0) && (
- <CardSection noPadding className="search-definition-rows">
- <div className="search-definition-options">
- {searchOptions?.activeOptions.map(({ attributeType, attributeName, component, additionalAttributesToDelete, defaultValue }) => {
- const Component = component;
- return <Component
- attributeName={attributeName}
- attributeType={attributeType}
- note={note}
- refreshResults={refreshResults}
- flushRef={flushRef}
- error={error}
- additionalAttributesToDelete={additionalAttributesToDelete}
- defaultValue={defaultValue}
- />;
- })}
- </div>
-
- {bulkActions.length > 0 && <BulkActionsTable bulkActions={bulkActions} />}
- </CardSection>
- )}
+ {searchOptions?.activeOptions.map(({ attributeType, attributeName, component, additionalAttributesToDelete, defaultValue }) => {
+ const Component = component;
+ return <Component
+ attributeName={attributeName}
+ attributeType={attributeType}
+ note={note}
+ refreshResults={refreshResults}
+ flushRef={flushRef}
+ error={error}
+ additionalAttributesToDelete={additionalAttributesToDelete}
+ defaultValue={defaultValue}
+ />;
+ })}
+
+ {bulkActions.map((bulkAction) => (
+ <Fragment key={bulkAction.attribute.attributeId}>{bulkAction.doRender()}</Fragment>
+ ))}
<CardSection className="search-definition-actions">
<AddSearchOptionButton note={note} options={searchOptions?.availableOptions ?? []} />
@@ -176,18 +172,6 @@ function useBulkActions(note: FNote | null | undefined) {
return bulkActions;
}
-function BulkActionsTable({ bulkActions }: { bulkActions: RenameNoteBulkAction[] }) {
- return (
- <table className="bulk-existing-action-list">
- <tbody>
- {bulkActions.map((bulkAction) => (
- <Fragment key={bulkAction.attribute.attributeId}>{bulkAction.doRender()}</Fragment>
- ))}
- </tbody>
- </table>
- );
-}
-
/** A menu of the search options the note does not use yet, and of the bulk actions it can add. */
function AddSearchOptionButton({ note, options }: { note: FNote; options: SearchOption[] }) {
const items: MenuItem<unknown>[] = options.map(({ icon, label, tooltip, attributeName, attributeType, defaultValue }) => ({
diff --git a/apps/client/src/widgets/search/SearchDefinitionOptions.tsx b/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
index 6af351f239..22d3a54baf 100644
--- a/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
+++ b/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
@@ -11,6 +11,7 @@ import server from "../../services/server";
import SpacedUpdate from "../../services/spaced_update";
import { openInAppHelpFromUrl } from "../../services/utils";
import { ExtendedAdmonition } from "../react/Admonition";
+import { CardSection } from "../react/Card";
import FormSelect from "../react/FormSelect";
import FormTextBox from "../react/FormTextBox";
import HelpRemoveButtons from "../react/HelpRemoveButtons";
@@ -125,7 +126,7 @@ function SearchOption({ note, className, title, titleIcon, children, description
additionalAttributesToDelete?: { type: "label" | "relation", name: string }[]
}) {
return (
- <div className={clsx("search-option", attributeName, className)}>
+ <CardSection className={clsx("search-option", attributeName, className)}>
<span className="search-option-label">
{titleIcon && <Icon icon={titleIcon} />}
{title}
@@ -147,7 +148,7 @@ function SearchOption({ note, className, title, titleIcon, children, description
}
}}
/>
- </div>
+ </CardSection>
);
}
@@ -231,7 +232,7 @@ function SearchStringOption({ note, refreshResults, flushRef, error, ...restProp
/>
</SearchOption>
{error?.message && (
- <div className="search-definition-error">
+ <CardSection className="search-definition-error">
<ExtendedAdmonition
type="caution"
icon="bx bx-error-circle"
@@ -239,7 +240,7 @@ function SearchStringOption({ note, refreshResults, flushRef, error, ...restProp
>
{error.message}
</ExtendedAdmonition>
- </div>
+ </CardSection>
)}
</>;
}