Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): lay the parameters out as bordered rows

Elian Dorancbb3a0b72dae
diff --git a/apps/client/src/widgets/search/SearchDefinition.css b/apps/client/src/widgets/search/SearchDefinition.css
index 22617141ed..8c81322cad 100644
--- a/apps/client/src/widgets/search/SearchDefinition.css
+++ b/apps/client/src/widgets/search/SearchDefinition.css
@@ -7,16 +7,23 @@
gap: 8px;
}
- /* An option row lines up like the bulk actions below it: a title column, the controls, and the
- row's buttons at the trailing edge. */
- .search-option.tn-card-option {
+ .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: 12em minmax(0, 1fr) auto;
align-items: center;
column-gap: 12px;
row-gap: 4px;
- > .tn-card-option-label {
+ > .search-option-label {
grid-column: 1;
min-width: 0;
}
@@ -35,6 +42,13 @@
}
}
+ .search-option-label {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ min-width: 0;
+ }
+
.search-option-fields > * {
min-width: 0;
}
@@ -96,10 +110,10 @@ body.mobile .search-definition-widget {
}
@container (width < 560px) {
- .search-option.tn-card-option {
+ .search-option {
grid-template-columns: minmax(0, 1fr) auto;
- > .tn-card-option-label {
+ > .search-option-label {
grid-column: 1;
grid-row: 1;
}
diff --git a/apps/client/src/widgets/search/SearchDefinition.spec.tsx b/apps/client/src/widgets/search/SearchDefinition.spec.tsx
index c04e0bbab0..0d4bd74751 100644
--- a/apps/client/src/widgets/search/SearchDefinition.spec.tsx
+++ b/apps/client/src/widgets/search/SearchDefinition.spec.tsx
@@ -44,12 +44,12 @@ afterEach(() => {
});
describe("the search definition", () => {
- it("lays the parameters out as segments of a card, as the bulk actions dialog does", () => {
+ it("lays the parameters out as rows of a card, as the bulk actions dialog does", () => {
const container = renderDefinition();
const card = container.querySelector(".search-definition-widget > .tn-card");
expect(card).not.toBeNull();
- expect(card?.querySelector(".tn-card-section.tn-card-option.searchString")).not.toBeNull();
+ expect(card?.querySelector(".search-definition-options .search-option.searchString")).not.toBeNull();
const actionsRow = card?.querySelector(".tn-card-section.search-definition-actions");
expect(actionsRow?.querySelector(".search-definition-add")).not.toBeNull();
diff --git a/apps/client/src/widgets/search/SearchDefinition.tsx b/apps/client/src/widgets/search/SearchDefinition.tsx
index adbb78d269..bf75013e48 100644
--- a/apps/client/src/widgets/search/SearchDefinition.tsx
+++ b/apps/client/src/widgets/search/SearchDefinition.tsx
@@ -34,6 +34,7 @@ export default function SearchDefinition({ note, ntxId }: {
const [ searchOptions, setSearchOptions ] = useState<{ availableOptions: SearchOption[], activeOptions: SearchOption[] }>();
const [ error, setError ] = useState<{ message: string }>();
const flushRef = useRef<() => Promise<void>>(null);
+ const bulkActions = useBulkActions(note);
// The server reads the search options from the note's attributes, so a value still waiting
// in a `SpacedUpdate` is saved first.
@@ -84,21 +85,27 @@ export default function SearchDefinition({ note, ntxId }: {
<div className="search-definition-widget">
{note && (
<Card className="search-definition-card">
- {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}
- />;
- })}
-
- <BulkActionsList note={note} />
+ {(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>
+ )}
<CardSection className="search-definition-actions">
<AddSearchOptionButton note={note} options={searchOptions?.availableOptions ?? []} />
@@ -151,37 +158,33 @@ function SearchButtonBar({ note, refreshResults, savePendingOptions }: {
);
}
-function BulkActionsList({ note }: { note: FNote }) {
- const [ bulkActions, setBulkActions ] = useState<RenameNoteBulkAction[]>();
+function useBulkActions(note: FNote | null | undefined) {
+ const [ bulkActions, setBulkActions ] = useState<RenameNoteBulkAction[]>([]);
function refreshBulkActions() {
- if (note) {
- setBulkActions(bulk_action.parseActions(note));
- }
+ setBulkActions(note ? bulk_action.parseActions(note) : []);
}
// React to changes.
useEffect(refreshBulkActions, [ note ]);
useTriliumEvent("entitiesReloaded", ({loadResults}) => {
- if (loadResults.getAttributeRows().find(attr => attr.type === "label" && attr.name === "action" && attributes.isAffecting(attr, note))) {
+ if (note && loadResults.getAttributeRows().find(attr => attr.type === "label" && attr.name === "action" && attributes.isAffecting(attr, note))) {
refreshBulkActions();
}
});
- if (!bulkActions?.length) {
- return null;
- }
+ return bulkActions;
+}
+function BulkActionsTable({ bulkActions }: { bulkActions: RenameNoteBulkAction[] }) {
return (
- <CardSection noPadding className="search-definition-bulk-actions">
- <table className="bulk-existing-action-list">
- <tbody>
- {bulkActions.map((bulkAction) => (
- <Fragment key={bulkAction.attribute.attributeId}>{bulkAction.doRender()}</Fragment>
- ))}
- </tbody>
- </table>
- </CardSection>
+ <table className="bulk-existing-action-list">
+ <tbody>
+ {bulkActions.map((bulkAction) => (
+ <Fragment key={bulkAction.attribute.attributeId}>{bulkAction.doRender()}</Fragment>
+ ))}
+ </tbody>
+ </table>
);
}
diff --git a/apps/client/src/widgets/search/SearchDefinitionOptions.tsx b/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
index d4ca6157f6..3f9668f3fd 100644
--- a/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
+++ b/apps/client/src/widgets/search/SearchDefinitionOptions.tsx
@@ -11,7 +11,6 @@ import server from "../../services/server";
import SpacedUpdate from "../../services/spaced_update";
import { openInAppHelpFromUrl } from "../../services/utils";
import { ExtendedAdmonition } from "../react/Admonition";
-import { CardSection, OptionCardSection } from "../react/Card";
import FormSelect from "../react/FormSelect";
import FormTextBox from "../react/FormTextBox";
import HelpRemoveButtons from "../react/HelpRemoveButtons";
@@ -124,10 +123,11 @@ function SearchOption({ note, className, title, titleIcon, children, help, attri
additionalAttributesToDelete?: { type: "label" | "relation", name: string }[]
}) {
return (
- <OptionCardSection
- className={clsx("search-option", attributeName, className)}
- label={titleIcon ? <><Icon icon={titleIcon} />{" "}{title}</> : title}
- >
+ <div className={clsx("search-option", attributeName, className)}>
+ <span className="search-option-label">
+ {titleIcon && <Icon icon={titleIcon} />}
+ {title}
+ </span>
<div className="search-option-fields">
{children}
</div>
@@ -144,7 +144,7 @@ function SearchOption({ note, className, title, titleIcon, children, help, attri
}
}}
/>
- </OptionCardSection>
+ </div>
);
}
@@ -228,7 +228,7 @@ function SearchStringOption({ note, refreshResults, flushRef, error, ...restProp
/>
</SearchOption>
{error?.message && (
- <CardSection className="search-definition-error">
+ <div className="search-definition-error">
<ExtendedAdmonition
type="caution"
icon="bx bx-error-circle"
@@ -236,7 +236,7 @@ function SearchStringOption({ note, refreshResults, flushRef, error, ...restProp
>
{error.message}
</ExtendedAdmonition>
- </CardSection>
+ </div>
)}
</>;
}