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
refactor(react/collections/table): move events to dedicated prop
Elian Dorane25c5cc6c732
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsxindex b9f6a8d7aa..e9c8b88021 100644--- a/apps/client/src/widgets/collections/table/index.tsx+++ b/apps/client/src/widgets/collections/table/index.tsx@@ -56,7 +56,7 @@ export default function TableView({ note, viewConfig, saveConfig }: ViewModePropdata={rowData}modules={[ SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, DataTreeModule ]}footerElement={<TableFooter note={note} />}- {...contextMenuEvents}+ events={contextMenuEvents}persistence {...persistenceProps}/><TableFooter note={note} />diff --git a/apps/client/src/widgets/collections/table/tabulator.tsx b/apps/client/src/widgets/collections/table/tabulator.tsxindex 90dee5efba..4ed890aa9e 100644--- a/apps/client/src/widgets/collections/table/tabulator.tsx+++ b/apps/client/src/widgets/collections/table/tabulator.tsx@@ -5,16 +5,17 @@ import "../../../../src/stylesheets/table.css";import { ComponentChildren, RefObject } from "preact";import { ParentComponent, renderReactWidget } from "../../react/react_utils";-interface TableProps<T> extends Partial<EventCallBackMethods>, Pick<Options, "persistence" | "persistenceReaderFunc" | "persistenceWriterFunc"> {+interface TableProps<T> extends Pick<Options, "persistence" | "persistenceReaderFunc" | "persistenceWriterFunc"> {tabulatorRef: RefObject<VanillaTabulator>;className?: string;columns: ColumnDefinition[];data?: T[];modules?: (new (table: VanillaTabulator) => Module)[];footerElement?: ComponentChildren;+ events?: Partial<EventCallBackMethods>;}-export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, persistence, persistenceReaderFunc, persistenceWriterFunc, ...events }: TableProps<T>) {+export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, events, ...restProps }: TableProps<T>) {const parentComponent = useContext(ParentComponent);const containerRef = useRef<HTMLDivElement>(null);const tabulatorRef = useRef<VanillaTabulator>(null);@@ -33,7 +34,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabulacolumns,data,footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined),- persistence, persistenceReaderFunc, persistenceWriterFunc+ ...restProps});tabulatorRef.current = tabulator;@@ -44,7 +45,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabulauseEffect(() => {const tabulator = tabulatorRef.current;- if (!tabulator) return;+ if (!tabulator || !events) return;for (const [ eventName, handler ] of Object.entries(events)) {tabulator.on(eventName as keyof EventCallBackMethods, handler);@@ -55,7 +56,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabulatabulator.off(eventName as keyof EventCallBackMethods, handler);}}- }, Object.values(events));+ }, Object.values(events ?? {}));// Change in data.useEffect(() => { tabulatorRef.current?.setData(data) }, [ data ]);