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
refactor(views/table): move bulk action implementation in service
Elian Doran0d3de928900f
diff --git a/apps/client/src/services/bulk_action.ts b/apps/client/src/services/bulk_action.tsindex 66922ef629..c4441259fa 100644--- a/apps/client/src/services/bulk_action.ts+++ b/apps/client/src/services/bulk_action.ts@@ -15,6 +15,7 @@ import AddRelationBulkAction from "../widgets/bulk_actions/relation/add_relationimport RenameNoteBulkAction from "../widgets/bulk_actions/note/rename_note.js";import { t } from "./i18n.js";import type FNote from "../entities/fnote.js";+import toast from "./toast.js";const ACTION_GROUPS = [{@@ -89,6 +90,17 @@ function parseActions(note: FNote) {.filter((action) => !!action);}+export async function executeBulkActions(parentNoteId: string, actions: {}[]) {+ await server.post("bulk-action/execute", {+ noteIds: [ parentNoteId ],+ includeDescendants: true,+ actions+ });++ await ws.waitForMaxKnownEntityChangeId();+ toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);+}+export default {addAction,parseActions,diff --git a/apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts b/apps/client/src/widgets/view_widgets/table_view/bulk_actions.tsindex e4f24f4ed0..b0f590c169 100644--- a/apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts+++ b/apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts@@ -1,45 +1,31 @@-import { t } from "i18next";-import server from "../../../services/server";-import toast from "../../../services/toast";-import ws from "../../../services/ws";+import { executeBulkActions } from "../../../services/bulk_action.js";export async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {if (type === "label") {- return executeBulkAction(parentNoteId, {+ return executeBulkActions(parentNoteId, [{name: "renameLabel",oldLabelName: originalName,newLabelName: newName- });+ }]);} else {- return executeBulkAction(parentNoteId, {+ return executeBulkActions(parentNoteId, [{name: "renameRelation",oldRelationName: originalName,newRelationName: newName- });+ }]);}}export async function deleteColumn(parentNoteId: string, type: "label" | "relation", columnName: string) {if (type === "label") {- return executeBulkAction(parentNoteId, {+ return executeBulkActions(parentNoteId, [{name: "deleteLabel",labelName: columnName- });+ }]);} else {- return executeBulkAction(parentNoteId, {+ return executeBulkActions(parentNoteId, [{name: "deleteRelation",relationName: columnName- });+ }]);}}--async function executeBulkAction(parentNoteId: string, action: {}) {- await server.post("bulk-action/execute", {- noteIds: [ parentNoteId ],- includeDescendants: true,- actions: [ action ]- });-- await ws.waitForMaxKnownEntityChangeId();- toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);-}