Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react/collections/table) reintroduce delete/rename
Elian Doranab6fc9303bdf
diff --git a/apps/client/src/widgets/collections/table/col_editing.ts b/apps/client/src/widgets/collections/table/col_editing.tsindex ca5636040f..8e15677d9f 100644--- a/apps/client/src/widgets/collections/table/col_editing.ts+++ b/apps/client/src/widgets/collections/table/col_editing.ts@@ -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);+ }+}diff --git a/apps/client/src/widgets/collections/table/tabulator.tsx b/apps/client/src/widgets/collections/table/tabulator.tsxindex 3481c471f7..9191f22da7 100644--- a/apps/client/src/widgets/collections/table/tabulator.tsx+++ b/apps/client/src/widgets/collections/table/tabulator.tsx@@ -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"> {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.tsdeleted file mode 100644index 010bd1c488..0000000000--- a/apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts+++ /dev/null@@ -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);- }-}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.tsindex cf520303d0..1a6939b3cf 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@@ -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;}