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(views/table): basic renaming of fields
Elian Doran504a19275c3a
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.tsnew file mode 100644index 0000000000..c930b79e4c--- /dev/null+++ b/apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts@@ -0,0 +1,32 @@+import { t } from "i18next";+import attributes from "../../../services/attributes";+import froca from "../../../services/froca";+import server from "../../../services/server";+import toast from "../../../services/toast";+import ws from "../../../services/ws";++export async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {+ const bulkActionNote = await froca.getNote("_bulkAction");+ if (!bulkActionNote) {+ console.warn("Bulk action note not found");+ return;+ }++ if (type === "label") {+ attributes.setLabel("_bulkAction", "action", JSON.stringify({+ name: "renameLabel",+ oldLabelName: originalName,+ newLabelName: newName+ }));+ await server.post("bulk-action/execute", {+ noteIds: [ parentNoteId ],+ includeDescendants: true+ });++ await ws.waitForMaxKnownEntityChangeId();+ toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);+ } else {+ console.warn("Renaming relation columns is not supported yet");+ return;+ }+}diff --git a/apps/client/src/widgets/view_widgets/table_view/col_editing.ts b/apps/client/src/widgets/view_widgets/table_view/col_editing.tsindex 7cb8c4f541..2d0120fd31 100644--- a/apps/client/src/widgets/view_widgets/table_view/col_editing.ts+++ b/apps/client/src/widgets/view_widgets/table_view/col_editing.ts@@ -5,6 +5,7 @@ import Component from "../../../components/component";import { CommandListenerData, EventData } from "../../../components/app_context";import attributes from "../../../services/attributes";import FNote from "../../../entities/fnote";+import { renameColumn } from "./bulk_actions";export default class TableColumnEditing extends Component {@@ -73,13 +74,20 @@ export default class TableColumnEditing extends Component {return;}- const { name, value } = this.newAttribute;+ const { name, type, value } = this.newAttribute;++ this.api.blockRedraw();if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== name) {attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);++ const oldName = this.existingAttributeToEdit.name.split(":")[1];+ const newName = name.split(":")[1];+ await renameColumn(this.parentNote.noteId, type, oldName, newName);}attributes.setLabel(this.parentNote.noteId, name, value);+ this.api.restoreRedraw();}getNewAttributePosition() {diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.tsindex 2d3a9b9287..c2f5271087 100644--- a/apps/client/src/widgets/view_widgets/table_view/index.ts+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts@@ -197,8 +197,8 @@ export default class TableView extends ViewMode<StateInfo> {attr.type === "label" &&(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&attributes.isAffecting(attr, this.parentNote))) {- console.log("Col update");this.#manageColumnUpdate();+ return await this.#manageRowsUpdate();}if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))diff --git a/apps/server/src/routes/api/bulk_action.ts b/apps/server/src/routes/api/bulk_action.tsindex d2b35dd20b..9a3a9ce1c4 100644--- a/apps/server/src/routes/api/bulk_action.ts+++ b/apps/server/src/routes/api/bulk_action.ts@@ -4,6 +4,9 @@ import bulkActionService from "../../services/bulk_actions.js";function execute(req: Request) {const { noteIds, includeDescendants } = req.body;+ if (!Array.isArray(noteIds)) {+ throw new Error("noteIds must be an array");+ }const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);