mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
chore(react/collections/table): refresh columns
This commit is contained in:
parent
49c4776dbd
commit
1e654fbcd6
@ -2,7 +2,7 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "p
|
||||
import { ViewModeProps } from "../interface";
|
||||
import { buildColumnDefinitions } from "./columns";
|
||||
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
||||
import { useLegacyWidget, useNoteLabelInt, useSpacedUpdate } from "../../react/hooks";
|
||||
import { useLegacyWidget, useNoteLabelInt, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";
|
||||
import Tabulator from "./tabulator";
|
||||
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
|
||||
import { useContextMenu } from "./context_menu";
|
||||
@ -14,6 +14,8 @@ import "./index.css";
|
||||
import useRowTableEditing, { canReorderRows } from "./row_editing";
|
||||
import useColTableEditing from "./col_editing";
|
||||
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
|
||||
import attributes from "../../../services/attributes";
|
||||
import { refreshTextDimensions } from "@excalidraw/excalidraw/element/newElement";
|
||||
|
||||
interface TableConfig {
|
||||
tableData?: {
|
||||
@ -30,7 +32,7 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveCon
|
||||
const tabulatorRef = useRef<VanillaTabulator>(null);
|
||||
const parentComponent = useContext(ParentComponent);
|
||||
|
||||
useEffect(() => {
|
||||
function refresh() {
|
||||
const info = getAttributeDefinitionInformation(note);
|
||||
buildRowDefinitions(note, info, maxDepth).then(({ definitions: rowData, hasSubtree: hasChildren, rowNumber }) => {
|
||||
const movableRows = canReorderRows(note) && !hasChildren;
|
||||
@ -45,7 +47,19 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveCon
|
||||
setMovableRows(movableRows);
|
||||
setHasChildren(hasChildren);
|
||||
});
|
||||
}, [ note, noteIds ]);
|
||||
}
|
||||
|
||||
useEffect(refresh, [ note, noteIds ]);
|
||||
|
||||
// React to column changes.
|
||||
useTriliumEvent("entitiesReloaded", ({ loadResults}) => {
|
||||
if (loadResults.getAttributeRows().find(attr =>
|
||||
attr.type === "label" &&
|
||||
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
||||
attributes.isAffecting(attr, note))) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
const [ attributeDetailWidgetEl, attributeDetailWidget ] = useLegacyWidget(() => new AttributeDetailWidget().contentSized());
|
||||
const contextMenuEvents = useContextMenu(note, parentComponent, tabulatorRef);
|
||||
|
@ -58,7 +58,8 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
|
||||
}, Object.values(events ?? {}));
|
||||
|
||||
// Change in data.
|
||||
useEffect(() => { console.log("Got data ", data); tabulatorRef.current?.setData(data) }, [ data ]);
|
||||
useEffect(() => { tabulatorRef.current?.setData(data) }, [ data ]);
|
||||
useEffect(() => { columns && tabulatorRef.current?.setColumns(columns)}, [ data]);
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className={className} />
|
||||
|
@ -88,7 +88,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
||||
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
||||
attributes.isAffecting(attr, this.parentNote))) {
|
||||
this.#manageColumnUpdate();
|
||||
return await this.#manageRowsUpdate();
|
||||
//return await this.#manageRowsUpdate();
|
||||
}
|
||||
|
||||
// Refresh max depth
|
||||
|
Loading…
x
Reference in New Issue
Block a user