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
feat(bulk_actions): pick actions from an "Add action" menu
Elian Doran69d103ab3f42
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 2685060c9d..481982f4d1 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -90,11 +90,11 @@"affected_note_count_one": "The actions apply to {{count}} note.","affected_note_count_other": "The actions apply to {{count}} notes.","include_descendants": "Include descendants of the selected notes",- "available_actions": "Available actions",+ "add_action": "Add action","chosen_actions": "Chosen actions","execute_bulk_actions": "Execute bulk actions","bulk_actions_executed": "Bulk actions have been executed successfully.",- "none_yet": "None yet... add an action by clicking one of the available ones above.",+ "none_yet": "No actions yet. Use Add action below to choose one.","labels": "Labels","relations": "Relations","notes": "Notes",diff --git a/apps/client/src/widgets/bulk_actions/AddBulkActionButton.tsx b/apps/client/src/widgets/bulk_actions/AddBulkActionButton.tsxnew file mode 100644index 0000000000..f9ecf777f5--- /dev/null+++ b/apps/client/src/widgets/bulk_actions/AddBulkActionButton.tsx@@ -0,0 +1,41 @@+import type { ComponentChildren } from "preact";+import { Fragment } from "preact/jsx-runtime";++import bulk_action, { ACTION_GROUPS } from "../../services/bulk_action";+import Dropdown from "../react/Dropdown";+import { FormListHeader, FormListItem } from "../react/FormList";++interface AddBulkActionButtonProps {+ /** The note the chosen action is stored on, as an `#action` label. */+ noteId: string;+ text: ComponentChildren;+ buttonClassName?: string;+}++/**+ * A menu of every bulk action, grouped as in {@link ACTION_GROUPS}, that adds the picked one to the+ * note's actions.+ */+export default function AddBulkActionButton({ noteId, text, buttonClassName }: AddBulkActionButtonProps) {+ return (+ <Dropdown+ buttonClassName={buttonClassName}+ dropdownContainerClassName="action-add-menu"+ text={text}+ noSelectButtonStyle+ mobileBottomSheet+ >+ {ACTION_GROUPS.map(({ actions, title }, index) => (+ <Fragment key={index}>+ <FormListHeader text={title} />++ <div>+ {actions.map(({ actionName, actionTitle }) => (+ <FormListItem key={actionName} onClick={() => bulk_action.addAction(noteId, actionName)}>{actionTitle}</FormListItem>+ ))}+ </div>+ </Fragment>+ ))}+ </Dropdown>+ );+}diff --git a/apps/client/src/widgets/dialogs/bulk_actions.css b/apps/client/src/widgets/dialogs/bulk_actions.cssindex ba98e45341..a0df1bdaec 100644--- a/apps/client/src/widgets/dialogs/bulk_actions.css+++ b/apps/client/src/widgets/dialogs/bulk_actions.css@@ -25,22 +25,9 @@}}- .bulk-available-action-group {+ .bulk-actions-add-action {display: flex;- align-items: baseline;- gap: 12px;- }-- .bulk-available-action-group-title {- flex-shrink: 0;- width: 6rem;- color: var(--muted-text-color);- }-- .bulk-available-action-group-actions {- display: flex;- flex-wrap: wrap;- gap: 6px;+ justify-content: flex-end;}.bulk-existing-action-list {diff --git a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsxindex 628fecceee..475104cfbb 100644--- a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx+++ b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx@@ -71,6 +71,24 @@ describe("BulkActionsDialog", () => {.toBe("bulk_actions.none_yet");});+ it("adds the action picked from the add menu at the foot of the actions card", async () => {+ await open([ "n1" ]);+ const toggle = container.querySelector<HTMLButtonElement>(".bulk-actions-chosen-actions .tn-card-section:last-child .dropdown button");+ expect(toggle?.textContent).toContain("bulk_actions.add_action");+ await act(async () => toggle?.click());++ const item = [ ...document.querySelectorAll<HTMLElement>(".action-add-menu .dropdown-item") ]+ .find((el) => el.textContent?.includes("move_note.move_note"));+ expect(item).toBeDefined();+ await act(async () => item?.click());++ expect(server.post).toHaveBeenCalledWith("notes/_bulkAction/attributes", {+ type: "label",+ name: "action",+ value: JSON.stringify({ name: "moveNote" })+ });+ });+it("drops a removed chip from the notes the actions apply to, keeping the last one", async () => {await open([ "n1", "n2" ]);expect(lastAffectedNotesRequest()).toStrictEqual({ noteIds: [ "n1", "n2" ], includeDescendants: false });diff --git a/apps/client/src/widgets/dialogs/bulk_actions.tsx b/apps/client/src/widgets/dialogs/bulk_actions.tsxindex 340f538a2f..2f20bec14c 100644--- a/apps/client/src/widgets/dialogs/bulk_actions.tsx+++ b/apps/client/src/widgets/dialogs/bulk_actions.tsx@@ -9,6 +9,8 @@ import { Card, CardSection } from "../react/Card";import NoItems from "../react/NoItems";import { OptionsRowWithToggle } from "../type_widgets/options/components/OptionsRow";import bulk_action from "../../services/bulk_action";+import AddBulkActionButton from "../bulk_actions/AddBulkActionButton";+import Icon from "../react/Icon";import dialog from "../../services/dialog";import toast from "../../services/toast";import AbstractBulkAction from "../bulk_actions/abstract_bulk_action";@@ -114,12 +116,15 @@ export default function BulkActionsDialog() {</CardSection></Card>- <Card heading={t("bulk_actions.available_actions")}>- <AvailableActionsList />- </Card>-<Card className="bulk-actions-chosen-actions" heading={t("bulk_actions.chosen_actions")}><ExistingActionsList existingActions={existingActions} />+ <CardSection className="bulk-actions-add-action">+ <AddBulkActionButton+ noteId="_bulkAction"+ buttonClassName="btn-secondary btn-micro"+ text={<><Icon icon="bx bx-plus" />{" "}{t("bulk_actions.add_action")}</>}+ />+ </CardSection></Card></Modal>);@@ -153,26 +158,6 @@ function SelectedNotes({ noteIds, onChange }: { noteIds: string[]; onChange(note);}-function AvailableActionsList() {- return <>- {bulk_action.ACTION_GROUPS.map((actionGroup) => (- <CardSection key={actionGroup.title} className="bulk-available-action-group">- <span className="bulk-available-action-group-title">{actionGroup.title}</span>- <div className="bulk-available-action-group-actions">- {actionGroup.actions.map(({ actionName, actionTitle }) => (- <Button- key={actionName}- size="small"- text={actionTitle}- onClick={() => bulk_action.addAction("_bulkAction", actionName)}- />- ))}- </div>- </CardSection>- ))}- </>;-}-function ExistingActionsList({ existingActions }: { existingActions: AbstractBulkAction[] }) {if (!existingActions.length) {return (diff --git a/apps/client/src/widgets/search/SearchDefinition.css b/apps/client/src/widgets/search/SearchDefinition.cssindex 7b4916f1e3..3e6decd9f4 100644--- a/apps/client/src/widgets/search/SearchDefinition.css+++ b/apps/client/src/widgets/search/SearchDefinition.css@@ -55,10 +55,6 @@margin: 3px;}-.action-add-menu .dropdown-header {- background-color: var(--accented-background-color);-}-.search-actions-container {display: flex;justify-content: space-evenly;diff --git a/apps/client/src/widgets/search/SearchDefinition.tsx b/apps/client/src/widgets/search/SearchDefinition.tsxindex 961d28ff0f..6d57971c37 100644--- a/apps/client/src/widgets/search/SearchDefinition.tsx+++ b/apps/client/src/widgets/search/SearchDefinition.tsx@@ -2,22 +2,22 @@ import "./SearchDefinition.css";import { SaveSearchNoteResponse } from "@triliumnext/commons";import { useContext, useEffect, useRef, useState } from "preact/hooks";-import { Fragment } from "preact/jsx-runtime";import appContext from "../../components/app_context";import FNote from "../../entities/fnote";import attributes from "../../services/attributes";-import bulk_action, { ACTION_GROUPS } from "../../services/bulk_action";+import bulk_action from "../../services/bulk_action";import { t } from "../../services/i18n";import search from "../../services/search";import server from "../../services/server";import toast from "../../services/toast";import tree from "../../services/tree";import ws from "../../services/ws";+import AddBulkActionButton from "../bulk_actions/AddBulkActionButton";import RenameNoteBulkAction from "../bulk_actions/note/rename_note";import Button, { SplitButton } from "../react/Button";import Dropdown from "../react/Dropdown";-import { FormListHeader, FormListItem } from "../react/FormList";+import { FormListItem } from "../react/FormList";import { useTriliumEvent } from "../react/hooks";import Icon from "../react/Icon";import { ParentComponent } from "../react/react_utils";@@ -114,7 +114,11 @@ export default function SearchDefinition({ note, ntxId }: {}/>- <AddBulkActionButton note={note} />+ <AddBulkActionButton+ noteId={note.noteId}+ buttonClassName="action-add-toggle btn btn-sm"+ text={<><Icon icon="bx bxs-zap" />{" "}{t("search_definition.action")}</>}+ /></td></tr></tbody>@@ -223,27 +227,3 @@ function BulkActionsList({ note }: { note: FNote }) {</tbody>);}--function AddBulkActionButton({ note }: { note: FNote }) {- return (- <Dropdown- buttonClassName="action-add-toggle btn btn-sm"- dropdownContainerClassName="action-add-menu"- text={<><Icon icon="bx bxs-zap" />{" "}{t("search_definition.action")}</>}- noSelectButtonStyle- mobileBottomSheet- >- {ACTION_GROUPS.map(({ actions, title }, index) => (- <Fragment key={index}>- <FormListHeader text={title} />-- <div>- {actions.map(({ actionName, actionTitle }) => (- <FormListItem key={actionName} onClick={() => bulk_action.addAction(note.noteId, actionName)}>{actionTitle}</FormListItem>- ))}- </div>- </Fragment>- ))}- </Dropdown>- );-}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.htmlindex 194dd57a9f..2404988d47 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@@ -31,11 +31,12 @@all the descendants of the notes, turn on <em>Include descendants of the selected notes</em>.The number of affected notes, shown below that option, updates to reflectthe change.</li>- <li>Click on which action to apply from the <em>Available actions</em> section.- A detailed description of each is available in the next section.+ <li>To add an action, click <em>Add action</em> at the bottom of the <em>Chosen actions</em> section+ and pick one from the menu. A detailed description of each is available+ in the next section.<ul>- <li>For each action selected, the <em>Chosen actions</em> section will update- to reveal the entry. Each action will have its own configuration.</li>+ <li>Each chosen action appears as an entry in the <em>Chosen actions</em> section,+ with its own configuration.</li><li>To remove an action, simply press the X button to the right of it.</li><li>It is possible to apply multiple actions of the same type, such as addingmultiple types.</li>diff --git a/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md b/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.mdindex 7bce908dfb..5fb24d3452 100644--- a/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md+++ b/docs/User Guide/User Guide/Advanced Usage/Bulk Actions.md@@ -12,8 +12,8 @@ The _Bulk Actions_ dialog makes it easy to apply changes to multiple notes at on* The _Selected notes_ section at the top of the dialog lists the notes the actions apply to. When many notes are selected, only the first few are shown; click _+N more_ to show the rest.* To leave a note out without changing the selection in the note tree, press the X button on its entry. The last remaining note cannot be removed.* By default, only the selected notes will be affected. To also include all the descendants of the notes, turn on _Include descendants of the selected notes_. The number of affected notes, shown below that option, updates to reflect the change.-* Click on which action to apply from the _Available actions_ section. A detailed description of each is available in the next section.- * For each action selected, the _Chosen actions_ section will update to reveal the entry. Each action will have its own configuration.+* To add an action, click _Add action_ at the bottom of the _Chosen actions_ section and pick one from the menu. A detailed description of each is available in the next section.+ * Each chosen action appears as an entry in the _Chosen actions_ section, with its own configuration.* 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 _Execute bulk actions_ to trigger all of them at once.