refactor(views/table): move bulk action implementation in service

This commit is contained in:
Elian Doran
2025-07-19 12:46:38 +03:00
parent 5d619131ec
commit 0d3de92890
2 changed files with 21 additions and 23 deletions

View File

@@ -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);
}