chore(react/collections/table): react to external data changes

This commit is contained in:
Elian Doran 2025-09-09 19:34:22 +03:00
parent 9758632bf0
commit 3046cfd6ee
No known key found for this signature in database
3 changed files with 10 additions and 12 deletions

View File

@ -135,13 +135,22 @@ function useData(note: FNote, noteIds: string[], viewConfig: TableConfig | undef
useEffect(refresh, [ note, noteIds, maxDepth, movableRows ]);
// React to column changes.
useTriliumEvent("entitiesReloaded", ({ loadResults}) => {
// React to column changes.
if (loadResults.getAttributeRows().find(attr =>
attr.type === "label" &&
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
attributes.isAffecting(attr, note))) {
refresh();
return;
}
// React to external row updates.
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === note.noteId || noteIds.includes(branch.parentNoteId ?? ""))
|| loadResults.getNoteIds().some(noteId => noteIds.includes(noteId))
|| loadResults.getAttributeRows().some(attr => noteIds.includes(attr.noteId!))) {
refresh();
return;
}
});

View File

@ -6,7 +6,6 @@ import { RefObject } from "preact";
import { setAttribute, setLabel } from "../../../services/attributes";
import froca from "../../../services/froca";
import server from "../../../services/server";
import FNote from "../../../entities/fnote";
import branches from "../../../services/branches";
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";

View File

@ -60,16 +60,6 @@ export default class TableView extends ViewMode<StateInfo> {
setupContextMenu(this.api, this.parentNote);
}
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|| loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId))
|| loadResults.getAttributeRows().some(attr => this.noteIds.includes(attr.noteId!))) {
return await this.#manageRowsUpdate();
}
return false;
}
#manageColumnUpdate() {
if (!this.api) {
return;