From cd67299b1d7f95a8b46a57db69057de9a7072c02 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Sep 2025 21:08:32 +0300 Subject: [PATCH] chore(react/collections/table): bring back footer --- .../src/widgets/collections/table/index.tsx | 38 ++++++++++++++----- .../widgets/collections/table/tabulator.tsx | 12 ++++-- .../widgets/view_widgets/table_view/footer.ts | 22 ----------- 3 files changed, 37 insertions(+), 35 deletions(-) delete mode 100644 apps/client/src/widgets/view_widgets/table_view/footer.ts diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx index c887b4fec..b162cbfa4 100644 --- a/apps/client/src/widgets/collections/table/index.tsx +++ b/apps/client/src/widgets/collections/table/index.tsx @@ -1,6 +1,5 @@ import { useContext, useEffect, useRef, useState } from "preact/hooks"; import { ViewModeProps } from "../interface"; -import "./index.css"; import { buildColumnDefinitions } from "./columns"; import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows"; import { useNoteLabelInt } from "../../react/hooks"; @@ -9,6 +8,11 @@ import Tabulator from "./tabulator"; import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule} from 'tabulator-tables'; import { useContextMenu } from "./context_menu"; import { ParentComponent } from "../../react/react_utils"; +import FNote from "../../../entities/fnote"; +import { t } from "../../../services/i18n"; +import Button from "../../react/Button"; +import "./index.css"; + interface TableConfig { tableData?: { columns?: ColumnDefinition[]; @@ -42,15 +46,31 @@ export default function TableView({ note, viewConfig }: ViewModeProps {columnDefs && ( - + <> + } + {...contextMenuEvents} + /> + + )} ) } + +function TableFooter({ note }: { note: FNote }) { + return (note.type !== "search" && +
+
+
+
+ ) +} diff --git a/apps/client/src/widgets/collections/table/tabulator.tsx b/apps/client/src/widgets/collections/table/tabulator.tsx index ff1d6556f..22b453110 100644 --- a/apps/client/src/widgets/collections/table/tabulator.tsx +++ b/apps/client/src/widgets/collections/table/tabulator.tsx @@ -1,8 +1,9 @@ -import { useEffect, useLayoutEffect, useRef } from "preact/hooks"; +import { useContext, useEffect, useLayoutEffect, useRef } from "preact/hooks"; import { ColumnDefinition, EventCallBackMethods, Module, Tabulator as VanillaTabulator } from "tabulator-tables"; import "tabulator-tables/dist/css/tabulator.css"; import "../../../../src/stylesheets/table.css"; -import { RefObject } from "preact"; +import { ComponentChildren, RefObject } from "preact"; +import { ParentComponent, renderReactWidget } from "../../react/react_utils"; interface TableProps extends Partial { tabulatorRef: RefObject; @@ -10,9 +11,11 @@ interface TableProps extends Partial { columns: ColumnDefinition[]; data?: T[]; modules?: (new (table: VanillaTabulator) => Module)[]; + footerElement?: ComponentChildren; } -export default function Tabulator({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, ...events }: TableProps) { +export default function Tabulator({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, ...events }: TableProps) { + const parentComponent = useContext(ParentComponent); const containerRef = useRef(null); const tabulatorRef = useRef(null); @@ -28,7 +31,8 @@ export default function Tabulator({ className, columns, data, modules, tabula const tabulator = new VanillaTabulator(containerRef.current, { columns, - data + data, + footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined) }); tabulatorRef.current = tabulator; diff --git a/apps/client/src/widgets/view_widgets/table_view/footer.ts b/apps/client/src/widgets/view_widgets/table_view/footer.ts deleted file mode 100644 index 858b792c4..000000000 --- a/apps/client/src/widgets/view_widgets/table_view/footer.ts +++ /dev/null @@ -1,22 +0,0 @@ -import FNote from "../../../entities/fnote.js"; -import { t } from "../../../services/i18n.js"; - -function shouldDisplayFooter(parentNote: FNote) { - return (parentNote.type !== "search"); -} - -export default function buildFooter(parentNote: FNote) { - if (!shouldDisplayFooter(parentNote)) { - return undefined; - } - - return /*html*/`\ - - - - `.trimStart(); -}