mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
feat(views/table): delete column definition as well
This commit is contained in:
parent
66486541fe
commit
e7f47a0663
@ -288,6 +288,9 @@ export type CommandMappings = {
|
|||||||
referenceColumn?: ColumnComponent;
|
referenceColumn?: ColumnComponent;
|
||||||
direction?: "before" | "after";
|
direction?: "before" | "after";
|
||||||
};
|
};
|
||||||
|
deleteTableColumn: CommandData & {
|
||||||
|
columnToDelete?: ColumnComponent;
|
||||||
|
};
|
||||||
|
|
||||||
buildTouchBar: CommandData & {
|
buildTouchBar: CommandData & {
|
||||||
TouchBar: typeof TouchBar;
|
TouchBar: typeof TouchBar;
|
||||||
|
@ -5,7 +5,9 @@ import Component from "../../../components/component";
|
|||||||
import { CommandListenerData, EventData } from "../../../components/app_context";
|
import { CommandListenerData, EventData } from "../../../components/app_context";
|
||||||
import attributes from "../../../services/attributes";
|
import attributes from "../../../services/attributes";
|
||||||
import FNote from "../../../entities/fnote";
|
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 {
|
export default class TableColumnEditing extends Component {
|
||||||
|
|
||||||
@ -79,18 +81,40 @@ export default class TableColumnEditing extends Component {
|
|||||||
const { name, type, value } = this.newAttribute;
|
const { name, type, value } = this.newAttribute;
|
||||||
|
|
||||||
this.api.blockRedraw();
|
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) {
|
attributes.setLabel(this.parentNote.noteId, name, value);
|
||||||
const oldName = this.existingAttributeToEdit.name.split(":")[1];
|
if (this.existingAttributeToEdit) {
|
||||||
const newName = name.split(":")[1];
|
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
|
||||||
await renameColumn(this.parentNote.noteId, type, oldName, newName);
|
}
|
||||||
|
} 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);
|
let [ type, name ] = columnToDelete.getField()?.split(".", 2);
|
||||||
if (this.existingAttributeToEdit) {
|
if (!type || !name) {
|
||||||
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.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() {
|
getNewAttributePosition() {
|
||||||
|
@ -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 contextMenu, { MenuItem } from "../../../menus/context_menu.js";
|
||||||
import { TableData } from "./rows.js";
|
import { TableData } from "./rows.js";
|
||||||
import branches from "../../../services/branches.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 type FNote from "../../../entities/fnote.js";
|
||||||
import froca from "../../../services/froca.js";
|
import froca from "../../../services/froca.js";
|
||||||
import type Component from "../../../components/component.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) {
|
export function setupContextMenu(tabulator: Tabulator, parentNote: FNote) {
|
||||||
tabulator.on("rowContext", (e, row) => showRowContextMenu(e, row, parentNote, tabulator));
|
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"),
|
title: t("table_view.delete-column"),
|
||||||
uiIcon: "bx bx-trash",
|
uiIcon: "bx bx-trash",
|
||||||
enabled: !!column.getField() && column.getField() !== "title",
|
enabled: !!column.getField() && column.getField() !== "title",
|
||||||
handler: async () => {
|
handler: () => getParentComponent(e)?.triggerCommand("deleteTableColumn", {
|
||||||
if (!await dialog.confirm(t("table_view.delete_column_confirmation"))) {
|
columnToDelete: column
|
||||||
return;
|
})
|
||||||
}
|
|
||||||
|
|
||||||
let [ type, name ] = column.getField()?.split(".", 2);
|
|
||||||
if (!type || !name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
type = type.replace("s", "");
|
|
||||||
deleteColumn(parentNote.noteId, type as "label" | "relation", name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
selectMenuItemHandler() {},
|
selectMenuItemHandler() {},
|
||||||
|
@ -221,22 +221,11 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
this.colEditing?.resetNewAttributePosition();
|
this.colEditing?.resetNewAttributePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewRowCommand(e) {
|
addNewRowCommand(e) { this.rowEditing?.addNewRowCommand(e); }
|
||||||
this.rowEditing?.addNewRowCommand(e);
|
addNewTableColumnCommand(e) { this.colEditing?.addNewTableColumnCommand(e); }
|
||||||
}
|
deleteTableColumnCommand(e) { this.colEditing?.deleteTableColumnCommand(e); }
|
||||||
|
updateAttributeListCommand(e) { this.colEditing?.updateAttributeListCommand(e); }
|
||||||
addNewTableColumnCommand(e) {
|
saveAttributesCommand() { this.colEditing?.saveAttributesCommand(); }
|
||||||
this.colEditing?.addNewTableColumnCommand(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateAttributeListCommand(e) {
|
|
||||||
this.colEditing?.updateAttributeListCommand(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveAttributesCommand() {
|
|
||||||
this.colEditing?.saveAttributesCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async #manageRowsUpdate() {
|
async #manageRowsUpdate() {
|
||||||
if (!this.api) {
|
if (!this.api) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user