mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
chore(react/collections/table) reintroduce delete/rename
This commit is contained in:
parent
4e37a5f08e
commit
ab6fc9303b
@ -6,9 +6,11 @@ import { useRef, useState } from "preact/hooks";
|
||||
import { CommandListenerData, EventData } from "../../../components/app_context";
|
||||
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
|
||||
import attributes from "../../../services/attributes";
|
||||
import { renameColumn } from "../../view_widgets/table_view/bulk_actions";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import { getAttributeFromField } from "./utils";
|
||||
import dialog from "../../../services/dialog";
|
||||
import { t } from "i18next";
|
||||
import { executeBulkActions } from "../../../services/bulk_action";
|
||||
|
||||
export default function useColTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote) {
|
||||
|
||||
@ -84,8 +86,57 @@ export default function useColTableEditing(api: RefObject<Tabulator>, attributeD
|
||||
} finally {
|
||||
api.current.restoreRedraw();
|
||||
}
|
||||
},
|
||||
async deleteTableColumnCommand({ columnToDelete }: CommandListenerData<"deleteTableColumn">) {
|
||||
if (!api.current || !columnToDelete || !await dialog.confirm(t("table_view.delete_column_confirmation"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
let [ type, name ] = columnToDelete.getField()?.split(".", 2);
|
||||
if (!type || !name) {
|
||||
return;
|
||||
}
|
||||
type = type.replace("s", "");
|
||||
|
||||
api.current.blockRedraw();
|
||||
try {
|
||||
await deleteColumn(parentNote.noteId, type as "label" | "relation", name);
|
||||
attributes.removeOwnedLabelByName(parentNote, `${type}:${name}`);
|
||||
} finally {
|
||||
api.current.restoreRedraw();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return { newAttributePosition };
|
||||
}
|
||||
|
||||
async function deleteColumn(parentNoteId: string, type: "label" | "relation", columnName: string) {
|
||||
if (type === "label") {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "deleteLabel",
|
||||
labelName: columnName
|
||||
}], true);
|
||||
} else {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "deleteRelation",
|
||||
relationName: columnName
|
||||
}], true);
|
||||
}
|
||||
}
|
||||
|
||||
async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {
|
||||
if (type === "label") {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "renameLabel",
|
||||
oldLabelName: originalName,
|
||||
newLabelName: newName
|
||||
}], true);
|
||||
} else {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "renameRelation",
|
||||
oldRelationName: originalName,
|
||||
newRelationName: newName
|
||||
}], true);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { useContext, useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||
import { ColumnDefinition, EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator } from "tabulator-tables";
|
||||
import { EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator } from "tabulator-tables";
|
||||
import "tabulator-tables/dist/css/tabulator.css";
|
||||
import "../../../../src/stylesheets/table.css";
|
||||
import { ComponentChildren, RefObject } from "preact";
|
||||
import { RefObject } from "preact";
|
||||
import { ParentComponent, renderReactWidget } from "../../react/react_utils";
|
||||
|
||||
interface TableProps<T> extends Omit<Options, "data" | "footerElement" | "index"> {
|
||||
|
@ -1,31 +0,0 @@
|
||||
import { executeBulkActions } from "../../../services/bulk_action.js";
|
||||
|
||||
export async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {
|
||||
if (type === "label") {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "renameLabel",
|
||||
oldLabelName: originalName,
|
||||
newLabelName: newName
|
||||
}], true);
|
||||
} else {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "renameRelation",
|
||||
oldRelationName: originalName,
|
||||
newRelationName: newName
|
||||
}], true);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteColumn(parentNoteId: string, type: "label" | "relation", columnName: string) {
|
||||
if (type === "label") {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "deleteLabel",
|
||||
labelName: columnName
|
||||
}], true);
|
||||
} else {
|
||||
return executeBulkActions([parentNoteId], [{
|
||||
name: "deleteRelation",
|
||||
relationName: columnName
|
||||
}], true);
|
||||
}
|
||||
}
|
@ -22,26 +22,6 @@ export default class TableColumnEditing extends Component {
|
||||
this.parentNote = parentNote;
|
||||
}
|
||||
|
||||
async deleteTableColumnCommand({ columnToDelete }: CommandListenerData<"deleteTableColumn">) {
|
||||
if (!columnToDelete || !await dialog.confirm(t("table_view.delete_column_confirmation"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
getNewAttributePosition() {
|
||||
return this.newAttributePosition;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user