feat(views/table): basic renaming of fields

This commit is contained in:
Elian Doran 2025-07-15 21:48:09 +03:00
parent 14cdc52670
commit 504a19275c
No known key found for this signature in database
4 changed files with 45 additions and 2 deletions

View File

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

View File

@ -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() {

View File

@ -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 ?? ""))

View File

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