fix(filter): ensure proper initialization of filter components

- Add null check and default return value in getFilterState method
- Call onload() in modal and popover to ensure component initialization
- Prevents potential runtime errors when filter state is not initialized
This commit is contained in:
Quorafind 2025-09-24 13:28:46 +08:00
parent 2b1018ec46
commit 78cdf77c1f
3 changed files with 10 additions and 2 deletions

View file

@ -1079,6 +1079,13 @@ export class TaskFilterComponent extends Component {
// Public method to get current filter state
public getFilterState(): RootFilterState {
// Handle case where rootFilterState might not be initialized
if (!this.rootFilterState) {
return {
rootCondition: "any",
filterGroups: [],
};
}
return JSON.parse(JSON.stringify(this.rootFilterState));
}

View file

@ -29,6 +29,8 @@ export class ViewTaskFilterModal extends Modal {
this.leafId,
this.plugin
);
// Ensure the component is properly loaded
this.taskFilterComponent.onload();
}
onClose() {

View file

@ -53,8 +53,7 @@ export class ViewTaskFilterPopover
this.leafId,
this.plugin
);
// Initialize editor and display task
// Ensure the component is properly loaded
this.taskFilterComponent.onload();
// Create the popover