diff --git a/web/store/cycle_filter.store.ts b/web/store/cycle_filter.store.ts index b610741b9..2c57b5e78 100644 --- a/web/store/cycle_filter.store.ts +++ b/web/store/cycle_filter.store.ts @@ -1,4 +1,4 @@ -import { action, computed, observable, makeObservable, runInAction, autorun } from "mobx"; +import { action, computed, observable, makeObservable, runInAction, reaction } from "mobx"; import { computedFn } from "mobx-utils"; import set from "lodash/set"; // types @@ -49,11 +49,13 @@ export class CycleFilterStore implements ICycleFilterStore { // root store this.rootStore = _rootStore; // initialize display filters of the current project - autorun(() => { - const projectId = this.rootStore.app.router.projectId; - if (!projectId) return; - this.initProjectCycleFilters(projectId); - }); + reaction( + () => this.rootStore.app.router.projectId, + (projectId) => { + if (!projectId) return; + this.initProjectCycleFilters(projectId); + } + ); } /** @@ -97,7 +99,7 @@ export class CycleFilterStore implements ICycleFilterStore { active_tab: displayFilters?.active_tab || "active", layout: displayFilters?.layout || "list", }; - this.filters[projectId] = {}; + this.filters[projectId] = this.filters[projectId] ?? {}; }); }; diff --git a/web/store/module_filter.store.ts b/web/store/module_filter.store.ts index 7ead79e7e..ae5d07135 100644 --- a/web/store/module_filter.store.ts +++ b/web/store/module_filter.store.ts @@ -1,4 +1,4 @@ -import { action, computed, observable, makeObservable, runInAction, autorun } from "mobx"; +import { action, computed, observable, makeObservable, runInAction, reaction } from "mobx"; import { computedFn } from "mobx-utils"; import set from "lodash/set"; // types @@ -49,11 +49,13 @@ export class ModuleFilterStore implements IModuleFilterStore { // root store this.rootStore = _rootStore; // initialize display filters of the current project - autorun(() => { - const projectId = this.rootStore.app.router.projectId; - if (!projectId) return; - this.initProjectModuleFilters(projectId); - }); + reaction( + () => this.rootStore.app.router.projectId, + (projectId) => { + if (!projectId) return; + this.initProjectModuleFilters(projectId); + } + ); } /** @@ -98,7 +100,7 @@ export class ModuleFilterStore implements IModuleFilterStore { layout: displayFilters?.layout || "list", order_by: displayFilters?.order_by || "name", }; - this.filters[projectId] = {}; + this.filters[projectId] = this.filters[projectId] ?? {}; }); }; diff --git a/web/store/project/project_filter.store.ts b/web/store/project/project_filter.store.ts index 013f2dff5..7d6aff96f 100644 --- a/web/store/project/project_filter.store.ts +++ b/web/store/project/project_filter.store.ts @@ -1,4 +1,4 @@ -import { action, computed, observable, makeObservable, runInAction, autorun } from "mobx"; +import { action, computed, observable, makeObservable, runInAction, reaction } from "mobx"; import { computedFn } from "mobx-utils"; import set from "lodash/set"; // types @@ -49,11 +49,13 @@ export class ProjectFilterStore implements IProjectFilterStore { // root store this.rootStore = _rootStore; // initialize display filters of the current workspace - autorun(() => { - const workspaceSlug = this.rootStore.app.router.workspaceSlug; - if (!workspaceSlug) return; - this.initWorkspaceFilters(workspaceSlug); - }); + reaction( + () => this.rootStore.app.router.workspaceSlug, + (workspaceSlug) => { + if (!workspaceSlug) return; + this.initWorkspaceFilters(workspaceSlug); + } + ); } /** @@ -96,7 +98,7 @@ export class ProjectFilterStore implements IProjectFilterStore { this.displayFilters[workspaceSlug] = { order_by: displayFilters?.order_by || "created_at", }; - this.filters[workspaceSlug] = {}; + this.filters[workspaceSlug] = this.filters[workspaceSlug] ?? {}; }); };