mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +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 { ViewModeProps } from "../interface";
|
||||||
import { buildColumnDefinitions } from "./columns";
|
import { buildColumnDefinitions } from "./columns";
|
||||||
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
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 from "./tabulator";
|
||||||
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
|
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
|
||||||
import { useContextMenu } from "./context_menu";
|
import { useContextMenu } from "./context_menu";
|
||||||
@ -14,6 +14,8 @@ import "./index.css";
|
|||||||
import useRowTableEditing, { canReorderRows } from "./row_editing";
|
import useRowTableEditing, { canReorderRows } from "./row_editing";
|
||||||
import useColTableEditing from "./col_editing";
|
import useColTableEditing from "./col_editing";
|
||||||
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
|
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
|
||||||
|
import attributes from "../../../services/attributes";
|
||||||
|
import { refreshTextDimensions } from "@excalidraw/excalidraw/element/newElement";
|
||||||
|
|
||||||
interface TableConfig {
|
interface TableConfig {
|
||||||
tableData?: {
|
tableData?: {
|
||||||
@ -30,7 +32,7 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveCon
|
|||||||
const tabulatorRef = useRef<VanillaTabulator>(null);
|
const tabulatorRef = useRef<VanillaTabulator>(null);
|
||||||
const parentComponent = useContext(ParentComponent);
|
const parentComponent = useContext(ParentComponent);
|
||||||
|
|
||||||
useEffect(() => {
|
function refresh() {
|
||||||
const info = getAttributeDefinitionInformation(note);
|
const info = getAttributeDefinitionInformation(note);
|
||||||
buildRowDefinitions(note, info, maxDepth).then(({ definitions: rowData, hasSubtree: hasChildren, rowNumber }) => {
|
buildRowDefinitions(note, info, maxDepth).then(({ definitions: rowData, hasSubtree: hasChildren, rowNumber }) => {
|
||||||
const movableRows = canReorderRows(note) && !hasChildren;
|
const movableRows = canReorderRows(note) && !hasChildren;
|
||||||
@ -45,7 +47,19 @@ export default function TableView({ note, noteIds, notePath, viewConfig, saveCon
|
|||||||
setMovableRows(movableRows);
|
setMovableRows(movableRows);
|
||||||
setHasChildren(hasChildren);
|
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 [ attributeDetailWidgetEl, attributeDetailWidget ] = useLegacyWidget(() => new AttributeDetailWidget().contentSized());
|
||||||
const contextMenuEvents = useContextMenu(note, parentComponent, tabulatorRef);
|
const contextMenuEvents = useContextMenu(note, parentComponent, tabulatorRef);
|
||||||
|
@ -58,7 +58,8 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
|
|||||||
}, Object.values(events ?? {}));
|
}, Object.values(events ?? {}));
|
||||||
|
|
||||||
// Change in data.
|
// 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 (
|
return (
|
||||||
<div ref={containerRef} className={className} />
|
<div ref={containerRef} className={className} />
|
||||||
|
@ -88,7 +88,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
||||||
attributes.isAffecting(attr, this.parentNote))) {
|
attributes.isAffecting(attr, this.parentNote))) {
|
||||||
this.#manageColumnUpdate();
|
this.#manageColumnUpdate();
|
||||||
return await this.#manageRowsUpdate();
|
//return await this.#manageRowsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh max depth
|
// Refresh max depth
|
||||||
|
Loading…
x
Reference in New Issue
Block a user