From ab6fc9303bdf46774ad33c17c44e80dfbb53b730 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 9 Sep 2025 18:56:53 +0300 Subject: [PATCH] chore(react/collections/table) reintroduce delete/rename --- .../widgets/collections/table/col_editing.ts | 53 ++++++++++++++++++- .../widgets/collections/table/tabulator.tsx | 4 +- .../view_widgets/table_view/bulk_actions.ts | 31 ----------- .../view_widgets/table_view/col_editing.ts | 20 ------- 4 files changed, 54 insertions(+), 54 deletions(-) delete mode 100644 apps/client/src/widgets/view_widgets/table_view/bulk_actions.ts diff --git a/apps/client/src/widgets/collections/table/col_editing.ts b/apps/client/src/widgets/collections/table/col_editing.ts index ca5636040..8e15677d9 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, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote) { @@ -84,8 +86,57 @@ export default function useColTableEditing(api: RefObject, 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.tsx index 3481c471f..9191f22da 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 extends Omit { 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.ts deleted file mode 100644 index 010bd1c48..000000000 --- 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.ts index cf520303d..1a6939b3c 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; }