feat(views/table): delete column definition as well

This commit is contained in:
Elian Doran 2025-07-16 21:40:01 +03:00
parent 66486541fe
commit e7f47a0663
No known key found for this signature in database
4 changed files with 45 additions and 41 deletions

View file

@ -288,6 +288,9 @@ export type CommandMappings = {
referenceColumn?: ColumnComponent;
direction?: "before" | "after";
};
deleteTableColumn: CommandData & {
columnToDelete?: ColumnComponent;
};
buildTouchBar: CommandData & {
TouchBar: typeof TouchBar;

View file

@ -5,7 +5,9 @@ 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";
import { deleteColumn, renameColumn } from "./bulk_actions";
import dialog from "../../../services/dialog";
import { t } from "../../../services/i18n";
export default class TableColumnEditing extends Component {
@ -79,18 +81,40 @@ export default class TableColumnEditing extends Component {
const { name, type, value } = this.newAttribute;
this.api.blockRedraw();
try {
if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== name) {
const oldName = this.existingAttributeToEdit.name.split(":")[1];
const newName = name.split(":")[1];
await renameColumn(this.parentNote.noteId, type, oldName, newName);
}
if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== 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);
if (this.existingAttributeToEdit) {
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
}
} finally {
this.api.restoreRedraw();
}
}
async deleteTableColumnCommand({ columnToDelete }: CommandListenerData<"deleteTableColumn">) {
if (!columnToDelete || !await dialog.confirm(t("table_view.delete_column_confirmation"))) {
return;
}
attributes.setLabel(this.parentNote.noteId, name, value);
if (this.existingAttributeToEdit) {
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
let [ type, name ] = columnToDelete.getField()?.split(".", 2);
if (!type || !name) {
return;
}
type = type.replace("s", "");
this.api.blockRedraw();
try {
await deleteColumn(this.parentNote.noteId, type as "label" | "relation", name);
attributes.removeOwnedLabelByName(this.parentNote, `${type}:${name}`);
} finally {
this.api.restoreRedraw();
}
this.api.restoreRedraw();
}
getNewAttributePosition() {

View file

@ -1,4 +1,4 @@
import { ColumnComponent, MenuSeparator, RowComponent, Tabulator } from "tabulator-tables";
import { ColumnComponent, RowComponent, Tabulator } from "tabulator-tables";
import contextMenu, { MenuItem } from "../../../menus/context_menu.js";
import { TableData } from "./rows.js";
import branches from "../../../services/branches.js";
@ -7,8 +7,6 @@ import link_context_menu from "../../../menus/link_context_menu.js";
import type FNote from "../../../entities/fnote.js";
import froca from "../../../services/froca.js";
import type Component from "../../../components/component.js";
import dialog from "../../../services/dialog.js";
import { deleteColumn } from "./bulk_actions.js";
export function setupContextMenu(tabulator: Tabulator, parentNote: FNote) {
tabulator.on("rowContext", (e, row) => showRowContextMenu(e, row, parentNote, tabulator));
@ -111,19 +109,9 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, parentNote:
title: t("table_view.delete-column"),
uiIcon: "bx bx-trash",
enabled: !!column.getField() && column.getField() !== "title",
handler: async () => {
if (!await dialog.confirm(t("table_view.delete_column_confirmation"))) {
return;
}
let [ type, name ] = column.getField()?.split(".", 2);
if (!type || !name) {
return;
}
type = type.replace("s", "");
deleteColumn(parentNote.noteId, type as "label" | "relation", name);
}
handler: () => getParentComponent(e)?.triggerCommand("deleteTableColumn", {
columnToDelete: column
})
}
],
selectMenuItemHandler() {},

View file

@ -221,22 +221,11 @@ export default class TableView extends ViewMode<StateInfo> {
this.colEditing?.resetNewAttributePosition();
}
addNewRowCommand(e) {
this.rowEditing?.addNewRowCommand(e);
}
addNewTableColumnCommand(e) {
this.colEditing?.addNewTableColumnCommand(e);
}
updateAttributeListCommand(e) {
this.colEditing?.updateAttributeListCommand(e);
}
saveAttributesCommand() {
this.colEditing?.saveAttributesCommand();
}
addNewRowCommand(e) { this.rowEditing?.addNewRowCommand(e); }
addNewTableColumnCommand(e) { this.colEditing?.addNewTableColumnCommand(e); }
deleteTableColumnCommand(e) { this.colEditing?.deleteTableColumnCommand(e); }
updateAttributeListCommand(e) { this.colEditing?.updateAttributeListCommand(e); }
saveAttributesCommand() { this.colEditing?.saveAttributesCommand(); }
async #manageRowsUpdate() {
if (!this.api) {