Skip to content

Build your personal knowledge base with Trilium Notes

feat(bulk_actions): align action rows and require their fields

Elian Doranb00d3c18a8db
diff --git a/apps/client/src/widgets/bulk_actions/BulkAction.css b/apps/client/src/widgets/bulk_actions/BulkAction.css
index c71632a751..266494c377 100644
--- a/apps/client/src/widgets/bulk_actions/BulkAction.css
+++ b/apps/client/src/widgets/bulk_actions/BulkAction.css
@@ -52,18 +52,42 @@
content: "\ec0e"; /* bx-shuffle */
}
-.bulk-action-row {
+.bulk-action-fields {
display: flex;
align-items: center;
gap: 10px;
+
+ > * {
+ flex: 1 1 0;
+ min-width: 0;
+ }
+
+ > .bulk-action-name {
+ flex: 0 1 16ch;
+ }
+
+ > .bulk-action-arrow {
+ flex: none;
+ }
+
+ :is(input, select):user-invalid {
+ border-color: var(--dropdown-item-icon-destructive-color);
+ }
+}
+
+.bulk-action-description {
+ color: var(--muted-text-color);
+}
+
+.bulk-action-icon {
+ margin-inline-end: 8px;
}
-.bulk-action-label {
- white-space: nowrap;
+.bulk-action-icon.destructive-action-icon {
+ color: var(--dropdown-item-icon-destructive-color);
}
.bulk-action-arrow {
- flex-shrink: 0;
font-size: 1.2em;
color: var(--muted-text-color);
}
diff --git a/apps/client/src/widgets/bulk_actions/BulkAction.tsx b/apps/client/src/widgets/bulk_actions/BulkAction.tsx
index 1257f52f91..7fee11fc43 100644
--- a/apps/client/src/widgets/bulk_actions/BulkAction.tsx
+++ b/apps/client/src/widgets/bulk_actions/BulkAction.tsx
@@ -13,17 +13,16 @@ interface BulkActionProps {
}
const BulkAction = memo(({ children, bulkAction }: BulkActionProps) => {
- const { actionIcon, actionTitle } = bulkAction.constructor as typeof AbstractBulkAction;
+ const { actionIcon, actionTitle, actionDescription } = bulkAction.constructor as typeof AbstractBulkAction;
return (
<tr>
- <td colSpan={2}>
- <div className="bulk-action-row">
- <div className="bulk-action-label">
- {actionIcon && <Icon icon={actionIcon} className="bulk-action-icon" />}{" "}{actionTitle}
- </div>
-
- {children}
+ <td className="title-column">
+ {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>
<HelpRemoveButtons
diff --git a/apps/client/src/widgets/bulk_actions/execute_script.tsx b/apps/client/src/widgets/bulk_actions/execute_script.tsx
index e869daa507..f585d2ddc0 100644
--- a/apps/client/src/widgets/bulk_actions/execute_script.tsx
+++ b/apps/client/src/widgets/bulk_actions/execute_script.tsx
@@ -16,6 +16,7 @@ function ExecuteScriptBulkActionComponent({ bulkAction, actionDef }: { bulkActio
>
<FormTextBox
placeholder="note.title = note.title + '- suffix';"
+ required
currentValue={script} onChange={setScript}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/label/add_label.tsx b/apps/client/src/widgets/bulk_actions/label/add_label.tsx
index 3694fe0708..f5b4664753 100644
--- a/apps/client/src/widgets/bulk_actions/label/add_label.tsx
+++ b/apps/client/src/widgets/bulk_actions/label/add_label.tsx
@@ -19,6 +19,7 @@ function AddLabelBulkActionComponent({ bulkAction, actionDef }: { bulkAction: Ab
placeholder={t("add_label.label_name_placeholder")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("add_label.label_name_title")}
+ className="bulk-action-name" required
currentValue={labelName} onChange={setLabelName}
/>
<BulkActionArrow />
diff --git a/apps/client/src/widgets/bulk_actions/label/delete_label.tsx b/apps/client/src/widgets/bulk_actions/label/delete_label.tsx
index 5501a952dc..789d9ad20a 100644
--- a/apps/client/src/widgets/bulk_actions/label/delete_label.tsx
+++ b/apps/client/src/widgets/bulk_actions/label/delete_label.tsx
@@ -18,6 +18,7 @@ function DeleteLabelBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
pattern="[\\p{L}\\p{N}_:]+"
title={t("delete_label.label_name_title")}
placeholder={t("delete_label.label_name_placeholder")}
+ className="bulk-action-name" required
currentValue={labelName} onChange={setLabelName}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/label/rename_label.tsx b/apps/client/src/widgets/bulk_actions/label/rename_label.tsx
index c4531ffc25..241dde6482 100644
--- a/apps/client/src/widgets/bulk_actions/label/rename_label.tsx
+++ b/apps/client/src/widgets/bulk_actions/label/rename_label.tsx
@@ -19,6 +19,7 @@ function RenameLabelBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
placeholder={t("rename_label.old_name_placeholder")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("rename_label.name_title")}
+ className="bulk-action-name" required
currentValue={oldLabelName} onChange={setOldLabelName}
/>
@@ -28,6 +29,7 @@ function RenameLabelBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
placeholder={t("rename_label.new_name_placeholder")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("rename_label.name_title")}
+ className="bulk-action-name" required
currentValue={newLabelName} onChange={setNewLabelName}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/label/update_label_value.tsx b/apps/client/src/widgets/bulk_actions/label/update_label_value.tsx
index e5ecbc1a81..dabfd03e8a 100644
--- a/apps/client/src/widgets/bulk_actions/label/update_label_value.tsx
+++ b/apps/client/src/widgets/bulk_actions/label/update_label_value.tsx
@@ -19,6 +19,7 @@ function UpdateLabelValueComponent({ bulkAction, actionDef }: { bulkAction: Abst
placeholder={t("update_label_value.label_name_placeholder")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("update_label_value.label_name_title")}
+ className="bulk-action-name" required
currentValue={labelName} onChange={setLabelName}
/>
<BulkActionArrow />
diff --git a/apps/client/src/widgets/bulk_actions/note/convert_note.tsx b/apps/client/src/widgets/bulk_actions/note/convert_note.tsx
index 5a0047643f..02979961fc 100644
--- a/apps/client/src/widgets/bulk_actions/note/convert_note.tsx
+++ b/apps/client/src/widgets/bulk_actions/note/convert_note.tsx
@@ -32,6 +32,7 @@ function ConvertNoteBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
values={conversionOptions}
keyProperty="value"
titleProperty="title"
+ required
currentValue={conversion}
onChange={onChange}
/>
diff --git a/apps/client/src/widgets/bulk_actions/note/move_note.tsx b/apps/client/src/widgets/bulk_actions/note/move_note.tsx
index 66312ff214..4bd0a606a9 100644
--- a/apps/client/src/widgets/bulk_actions/note/move_note.tsx
+++ b/apps/client/src/widgets/bulk_actions/note/move_note.tsx
@@ -19,6 +19,7 @@ function MoveNoteBulkActionComponent({ bulkAction }: { bulkAction: AbstractBulkA
<NoteAutocomplete
placeholder={t("move_note.target_parent_note")}
+ required
noteId={targetParentNoteId} noteIdChanged={setTargetParentNoteId}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx b/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx
index 4f9ad91d66..5f23aa96d5 100644
--- a/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx
+++ b/apps/client/src/widgets/bulk_actions/relation/add_relation.tsx
@@ -16,11 +16,11 @@ function AddRelationBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
<BulkAction
bulkAction={bulkAction}
>
- <FormTextBox
+ <FormTextBox
placeholder={t("add_relation.relation_name")}
pattern="[\\p{L}\\p{N}_:]+"
- style={{ flexShrink: 3 }}
title={t("add_relation.allowed_characters")}
+ className="bulk-action-name" required
currentValue={relationName} onChange={setRelationName}
/>
@@ -28,6 +28,7 @@ function AddRelationBulkActionComponent({ bulkAction, actionDef }: { bulkAction:
<NoteAutocomplete
placeholder={t("add_relation.target_note")}
+ required
noteId={targetNoteId} noteIdChanged={setTargetNoteId}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/relation/delete_relation.tsx b/apps/client/src/widgets/bulk_actions/relation/delete_relation.tsx
index 682673d3dc..9114d8d637 100644
--- a/apps/client/src/widgets/bulk_actions/relation/delete_relation.tsx
+++ b/apps/client/src/widgets/bulk_actions/relation/delete_relation.tsx
@@ -18,6 +18,7 @@ function DeleteRelationBulkActionComponent({ bulkAction, actionDef }: { bulkActi
pattern="[\\p{L}\\p{N}_:]+"
placeholder={t("delete_relation.relation_name")}
title={t("delete_relation.allowed_characters")}
+ className="bulk-action-name" required
currentValue={relationName} onChange={setRelationName}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx b/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx
index 171c575b6f..18e244426c 100644
--- a/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx
+++ b/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx
@@ -19,6 +19,7 @@ function RenameRelationBulkActionComponent({ bulkAction, actionDef }: { bulkActi
placeholder={t("rename_relation.old_name")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("rename_relation.allowed_characters")}
+ className="bulk-action-name" required
currentValue={oldRelationName} onChange={setOldRelationName}
/>
@@ -28,6 +29,7 @@ function RenameRelationBulkActionComponent({ bulkAction, actionDef }: { bulkActi
placeholder={t("rename_relation.new_name")}
pattern="[\\p{L}\\p{N}_:]+"
title={t("rename_relation.allowed_characters")}
+ className="bulk-action-name" required
currentValue={newRelationName} onChange={setNewRelationName}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx b/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx
index c0b9c547f2..29d952038c 100644
--- a/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx
+++ b/apps/client/src/widgets/bulk_actions/relation/update_relation_target.tsx
@@ -19,8 +19,8 @@ function UpdateRelationTargetComponent({ bulkAction, actionDef }: { bulkAction:
<FormTextBox
placeholder={t("update_relation_target.relation_name")}
pattern="[\\p{L}\\p{N}_:]+"
- style={{ flexShrink: 3 }}
title={t("update_relation_target.allowed_characters")}
+ className="bulk-action-name" required
currentValue={relationName} onChange={setRelationName}
/>
@@ -28,7 +28,7 @@ function UpdateRelationTargetComponent({ bulkAction, actionDef }: { bulkAction:
<NoteAutocomplete
placeholder={t("update_relation_target.target_note")}
- containerStyle={{ flexShrink: 2 }}
+ required
noteId={targetNoteId} noteIdChanged={setTargetNoteId}
/>
</BulkAction>
diff --git a/apps/client/src/widgets/dialogs/bulk_actions.css b/apps/client/src/widgets/dialogs/bulk_actions.css
index a0df1bdaec..83ffca2ae3 100644
--- a/apps/client/src/widgets/dialogs/bulk_actions.css
+++ b/apps/client/src/widgets/dialogs/bulk_actions.css
@@ -41,6 +41,11 @@
padding: 8px 12px;
}
+ .title-column {
+ width: 1%;
+ white-space: nowrap;
+ }
+
.button-column {
width: 50px;
white-space: nowrap;
@@ -49,9 +54,41 @@
> * {
vertical-align: middle;
}
+ }
+ }
+
+ .bulk-actions-chosen-actions {
+ container-type: inline-size;
+ }
+
+ @container (width < 560px) {
+ .bulk-existing-action-list {
+ tr {
+ display: grid;
+ grid-template-columns: 1fr auto;
+ }
+
+ .title-column {
+ width: auto;
+ white-space: normal;
+ }
+
+ .bulk-action-fields-column {
+ grid-column: 1 / -1;
+ grid-row: 2;
+ padding-top: 0;
+ }
+
+ .button-column {
+ width: auto;
+ }
+
+ .bulk-action-fields {
+ flex-wrap: wrap;
- .help-dropdown {
- display: inline-block !important;
+ > :not(.bulk-action-name, .bulk-action-arrow) {
+ flex-basis: 14ch;
+ }
}
}
}
diff --git a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
index eb476dc8a3..1fbe655cc8 100644
--- a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
+++ b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
@@ -132,6 +132,54 @@ describe("BulkActionsDialog", () => {
}
});
+ it("lays each row out as title, fields and remove button, with the fields it needs marked required", async () => {
+ // For each action, its fields in order: whether each is required, and whether it holds a name.
+ const expected: Record<string, { required: boolean[]; names: boolean[] }> = {
+ addLabel: { required: [ true, false ], names: [ true, false ] },
+ updateLabelValue: { required: [ true, false ], names: [ true, false ] },
+ renameLabel: { required: [ true, true ], names: [ true, true ] },
+ deleteLabel: { required: [ true ], names: [ true ] },
+ addRelation: { required: [ true, true ], names: [ true, false ] },
+ updateRelationTarget: { required: [ true, true ], names: [ true, false ] },
+ renameRelation: { required: [ true, true ], names: [ true, true ] },
+ deleteRelation: { required: [ true ], names: [ true ] },
+ renameNote: { required: [], names: [] },
+ moveNote: { required: [ true ], names: [ false ] },
+ convertNote: { required: [ true ], names: [ false ] },
+ deleteNote: { required: [], names: [] },
+ saveRevision: { required: [ false ], names: [ false ] },
+ deleteRevisions: { required: [], names: [] },
+ executeScript: { required: [ true ], names: [ false ] }
+ };
+ buildNote({
+ id: "_bulkAction",
+ title: "Bulk action",
+ "#action": bulk_action.ACTION_CLASSES.map(({ actionName }) => JSON.stringify({ name: actionName }))
+ });
+ await open([ "n1" ]);
+ const rows = [ ...container.querySelectorAll<HTMLTableRowElement>(".bulk-existing-action-list tr") ];
+ 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(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)");
+ expect(row.querySelector(".bulk-action-description")?.textContent, actionName)
+ .toBe(hasFields ? undefined : actionDescription);
+ }
+
+ expect(container.querySelector("form")?.checkValidity()).toBe(false);
+ });
+
it("names the note count on the execute button and enables it only with actions and notes to run on", async () => {
function executeButton() {
const button = container.querySelector<HTMLButtonElement>(".modal-footer button[name='execute-bulk-actions']");
diff --git a/apps/client/src/widgets/react/FormSelect.tsx b/apps/client/src/widgets/react/FormSelect.tsx
index 82fc01dde3..4433500723 100644
--- a/apps/client/src/widgets/react/FormSelect.tsx
+++ b/apps/client/src/widgets/react/FormSelect.tsx
@@ -24,14 +24,16 @@ interface FormSelectProps<T, Q> extends ValueConfig<T, Q> {
style?: CSSProperties;
className?: string;
disabled?: boolean;
+ /** Keeps an enclosing form from submitting while the option with an empty value is chosen. */
+ required?: boolean;
}
/**
* Combobox component that takes in any object array as data. Each item of the array is rendered as an item, and the key and values are obtained by looking into the object by a specified key.
*/
-export default function FormSelect<T>({ name, id, onChange, style, className, disabled, ...restProps }: FormSelectProps<T, T>) {
+export default function FormSelect<T>({ name, id, onChange, style, className, disabled, required, ...restProps }: FormSelectProps<T, T>) {
return (
- <FormSelectBody name={name} id={id} onChange={onChange} style={style} className={className} disabled={disabled}>
+ <FormSelectBody name={name} id={id} onChange={onChange} style={style} className={className} disabled={disabled} required={required}>
<FormSelectGroup {...restProps} />
</FormSelectBody>
);
@@ -61,7 +63,7 @@ export function FormSelectWithGroups<T>({ name, id, values, keyProperty, titlePr
)
}
-function FormSelectBody({ id, name, children, onChange, style, className, disabled }: { id?: string, name?: string, children: ComponentChildren, onChange: OnChangeListener, style?: CSSProperties, className?: string, disabled?: boolean }) {
+function FormSelectBody({ id, name, children, onChange, style, className, disabled, required }: { id?: string, name?: string, children: ComponentChildren, onChange: OnChangeListener, style?: CSSProperties, className?: string, disabled?: boolean, required?: boolean }) {
return (
<select
id={id}
@@ -70,6 +72,7 @@ function FormSelectBody({ id, name, children, onChange, style, className, disabl
style={style}
className={`form-select ${className ?? ""}`}
disabled={disabled}
+ required={required}
>
{children}
</select>
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx
index 713c5db277..606b2bcafb 100644
--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx
+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx
@@ -50,6 +50,8 @@ export interface NoteAutocompleteProps {
noteId?: string;
/** Shows the selected note without allowing a different one to be picked. */
readOnly?: boolean;
+ /** Keeps an enclosing form from submitting while the field is empty. */
+ required?: boolean;
/** Places the input in the tab order of a host that orders its fields with `tabIndex`. */
tabIndex?: number;
/** Receives the functions that drive the field from outside it. */
@@ -81,7 +83,7 @@ export interface NoteAutocompleteHandle {
clear(): void;
}
-export default function NoteAutocomplete({ id, inputRef: externalInputRef, text, placeholder, container, containerStyle, opts, onChange, onTextChange, onKeyDown, onBlur, noteIdChanged, noteId, readOnly, tabIndex, handleRef, anchorRef, searchFooter, onHighlight }: NoteAutocompleteProps) {
+export default function NoteAutocomplete({ id, inputRef: externalInputRef, text, placeholder, container, containerStyle, opts, onChange, onTextChange, onKeyDown, onBlur, noteIdChanged, noteId, readOnly, required, tabIndex, handleRef, anchorRef, searchFooter, onHighlight }: NoteAutocompleteProps) {
const inputRef = useSyncedRef<HTMLInputElement>(externalInputRef);
const groupRef = useRef<HTMLDivElement>(null);
const [ value, setValue ] = useState("");
@@ -290,6 +292,7 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,
className="note-autocomplete form-control note-autocomplete-input"
value={value}
readOnly={readOnly}
+ required={required}
tabIndex={tabIndex}
placeholder={placeholder ?? t("add_link.search_note")}
autoComplete="off"
diff --git a/apps/client/src/widgets/search/SearchDefinition.css b/apps/client/src/widgets/search/SearchDefinition.css
index 3e6decd9f4..722222b2d3 100644
--- a/apps/client/src/widgets/search/SearchDefinition.css
+++ b/apps/client/src/widgets/search/SearchDefinition.css
@@ -47,7 +47,7 @@
margin-bottom: 0;
}
-.search-definition-widget input:invalid {
+.search-definition-widget input:user-invalid {
border: 3px solid red;
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Bulk Actions.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Bulk Actions.html
index f690856208..25bdce5f39 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Bulk Actions.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Bulk Actions.html
@@ -45,7 +45,12 @@
</li>
<li>When all the actions are defined, press the <em>Apply to N notes</em> button
to trigger all of them at once. The button names the number of notes that
- will be affected, and stays disabled until at least one action is added.</li>
+ will be affected, and stays disabled until at least one action is added.
+ <ul>
+ <li>If an action is missing a field it needs, such as the name of the label
+ to rename, the dialog does not run and points out the empty field instead.</li>
+ </ul>
+ </li>
<li>For convenience, the last bulk action configuration is saved for further
use and will be restored when entering the dialog again.</li>
</ul>
diff --git a/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md b/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md
index 1068396571..d813051b79 100644
--- a/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md
+++ b/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md
@@ -17,6 +17,7 @@ The _Bulk Actions_ dialog makes it easy to apply changes to multiple notes at on
* To remove an action, simply press the X button to the right of it.
* It is possible to apply multiple actions of the same type, such as adding multiple types.
* When all the actions are defined, press the _Apply to N notes_ button to trigger all of them at once. The button names the number of notes that will be affected, and stays disabled until at least one action is added.
+ * If an action is missing a field it needs, such as the name of the label to rename, the dialog does not run and points out the empty field instead.
* For convenience, the last bulk action configuration is saved for further use and will be restored when entering the dialog again.
## Actions