From 504a19275c3a82867459632a0a116368bb95bb94 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 15 Jul 2025 21:48:09 +0300 Subject: [PATCH] feat(views/table): basic renaming of fields --- .../view_widgets/table_view/bulk_actions.ts | 32 +++++++++++++++++++ .../view_widgets/table_view/col_editing.ts | 10 +++++- .../widgets/view_widgets/table_view/index.ts | 2 +- apps/server/src/routes/api/bulk_action.ts | 3 ++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts 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.ts new file mode 100644 index 000000000..c930b79e4 --- /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.ts index 7cb8c4f54..2d0120fd3 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.ts index 2d3a9b928..c2f527108 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 { 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.ts index d2b35dd20..9a3a9ce1c 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);