mirror of
https://github.com/zadam/trilium.git
synced 2025-10-31 19:49:01 +01:00
feat(views/table): force a refresh if data tree changes
This commit is contained in:
parent
38fce25b86
commit
fcbbc21a80
@ -390,7 +390,7 @@ export default class CalendarView extends ViewMode<{}> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
|
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
// Refresh note IDs if they got changed.
|
// Refresh note IDs if they got changed.
|
||||||
if (loadResults.getBranchRows().some((branch) => branch.parentNoteId === this.parentNote.noteId)) {
|
if (loadResults.getBranchRows().some((branch) => branch.parentNoteId === this.parentNote.noteId)) {
|
||||||
this.noteIds = this.parentNote.getChildNoteIds();
|
this.noteIds = this.parentNote.getChildNoteIds();
|
||||||
|
|||||||
@ -251,7 +251,7 @@ export default class GeoView extends ViewMode<MapData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">): boolean | void {
|
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">): boolean | void {
|
||||||
// If any of the children branches are altered.
|
// If any of the children branches are altered.
|
||||||
if (loadResults.getBranchRows().find((branch) => branch.parentNoteId === this.parentNote.noteId)) {
|
if (loadResults.getBranchRows().find((branch) => branch.parentNoteId === this.parentNote.noteId)) {
|
||||||
this.#reloadMarkers();
|
this.#reloadMarkers();
|
||||||
|
|||||||
@ -136,7 +136,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
const viewStorage = await this.viewStorage.restore();
|
const viewStorage = await this.viewStorage.restore();
|
||||||
this.persistentData = viewStorage?.tableData || {};
|
this.persistentData = viewStorage?.tableData || {};
|
||||||
|
|
||||||
const { definitions: rowData, hasChildren } = await buildRowDefinitions(this.parentNote, info);
|
const { definitions: rowData, hasSubtree: hasChildren } = await buildRowDefinitions(this.parentNote, info);
|
||||||
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
|
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
|
||||||
const columnDefs = buildColumnDefinitions(info, movableRows);
|
const columnDefs = buildColumnDefinitions(info, movableRows);
|
||||||
let opts: Options = {
|
let opts: Options = {
|
||||||
@ -242,7 +242,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">): boolean | void {
|
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
if (!this.api) {
|
if (!this.api) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -258,7 +258,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|
||||||
|| loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)
|
|| loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)
|
||||||
|| loadResults.getAttributeRows().some(attr => this.noteIds.includes(attr.noteId!)))) {
|
|| loadResults.getAttributeRows().some(attr => this.noteIds.includes(attr.noteId!)))) {
|
||||||
this.#manageRowsUpdate();
|
return await this.#manageRowsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -280,8 +280,15 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const info = getAttributeDefinitionInformation(this.parentNote);
|
const info = getAttributeDefinitionInformation(this.parentNote);
|
||||||
const { definitions } = await buildRowDefinitions(this.parentNote, info);
|
const { definitions, hasSubtree } = await buildRowDefinitions(this.parentNote, info);
|
||||||
|
|
||||||
|
// Force a refresh if the data tree needs enabling/disabling.
|
||||||
|
if (this.api.options.dataTree !== hasSubtree) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
await this.api.replaceData(definitions);
|
await this.api.replaceData(definitions);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
focusOnBranch(branchId: string) {
|
focusOnBranch(branchId: string) {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export type TableData = {
|
|||||||
|
|
||||||
export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[]) {
|
export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[]) {
|
||||||
const definitions: TableData[] = [];
|
const definitions: TableData[] = [];
|
||||||
let hasChildren = false;
|
let hasSubtree = false;
|
||||||
for (const branch of parentNote.getChildBranches()) {
|
for (const branch of parentNote.getChildBranches()) {
|
||||||
const note = await branch.getNote();
|
const note = await branch.getNote();
|
||||||
if (!note) {
|
if (!note) {
|
||||||
@ -42,7 +42,7 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDef
|
|||||||
|
|
||||||
if (note.hasChildren()) {
|
if (note.hasChildren()) {
|
||||||
def._children = (await buildRowDefinitions(note, infos)).definitions;
|
def._children = (await buildRowDefinitions(note, infos)).definitions;
|
||||||
hasChildren = true;
|
hasSubtree = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
definitions.push(def);
|
definitions.push(def);
|
||||||
@ -50,7 +50,7 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDef
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
definitions,
|
definitions,
|
||||||
hasChildren
|
hasSubtree
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,16 +43,16 @@ export default abstract class ViewMode<T extends object> extends Component {
|
|||||||
* @param e the event data.
|
* @param e the event data.
|
||||||
* @return {@code true} if the view should be re-rendered, a falsy value otherwise.
|
* @return {@code true} if the view should be re-rendered, a falsy value otherwise.
|
||||||
*/
|
*/
|
||||||
onEntitiesReloaded(e: EventData<"entitiesReloaded">): boolean | void {
|
async onEntitiesReloaded(e: EventData<"entitiesReloaded">): Promise<boolean | void> {
|
||||||
// Do nothing by default.
|
// Do nothing by default.
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent(e: EventData<"entitiesReloaded">) {
|
async entitiesReloadedEvent(e: EventData<"entitiesReloaded">) {
|
||||||
if (e.loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))) {
|
if (e.loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))) {
|
||||||
this.#refreshNoteIds();
|
this.#refreshNoteIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.onEntitiesReloaded(e)) {
|
if (await this.onEntitiesReloaded(e)) {
|
||||||
appContext.triggerEvent("refreshNoteList", { noteId: this.parentNote.noteId });
|
appContext.triggerEvent("refreshNoteList", { noteId: this.parentNote.noteId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user