fix: project, module, cycle filter store infinite loop (#3994)

This commit is contained in:
Lakhan Baheti 2024-03-20 18:06:45 +05:30 committed by GitHub
parent 2f883e4939
commit 901a7703ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 21 deletions

View File

@ -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 { computedFn } from "mobx-utils";
import set from "lodash/set"; import set from "lodash/set";
// types // types
@ -49,11 +49,13 @@ export class CycleFilterStore implements ICycleFilterStore {
// root store // root store
this.rootStore = _rootStore; this.rootStore = _rootStore;
// initialize display filters of the current project // initialize display filters of the current project
autorun(() => { reaction(
const projectId = this.rootStore.app.router.projectId; () => this.rootStore.app.router.projectId,
if (!projectId) return; (projectId) => {
this.initProjectCycleFilters(projectId); if (!projectId) return;
}); this.initProjectCycleFilters(projectId);
}
);
} }
/** /**
@ -97,7 +99,7 @@ export class CycleFilterStore implements ICycleFilterStore {
active_tab: displayFilters?.active_tab || "active", active_tab: displayFilters?.active_tab || "active",
layout: displayFilters?.layout || "list", layout: displayFilters?.layout || "list",
}; };
this.filters[projectId] = {}; this.filters[projectId] = this.filters[projectId] ?? {};
}); });
}; };

View File

@ -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 { computedFn } from "mobx-utils";
import set from "lodash/set"; import set from "lodash/set";
// types // types
@ -49,11 +49,13 @@ export class ModuleFilterStore implements IModuleFilterStore {
// root store // root store
this.rootStore = _rootStore; this.rootStore = _rootStore;
// initialize display filters of the current project // initialize display filters of the current project
autorun(() => { reaction(
const projectId = this.rootStore.app.router.projectId; () => this.rootStore.app.router.projectId,
if (!projectId) return; (projectId) => {
this.initProjectModuleFilters(projectId); if (!projectId) return;
}); this.initProjectModuleFilters(projectId);
}
);
} }
/** /**
@ -98,7 +100,7 @@ export class ModuleFilterStore implements IModuleFilterStore {
layout: displayFilters?.layout || "list", layout: displayFilters?.layout || "list",
order_by: displayFilters?.order_by || "name", order_by: displayFilters?.order_by || "name",
}; };
this.filters[projectId] = {}; this.filters[projectId] = this.filters[projectId] ?? {};
}); });
}; };

View File

@ -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 { computedFn } from "mobx-utils";
import set from "lodash/set"; import set from "lodash/set";
// types // types
@ -49,11 +49,13 @@ export class ProjectFilterStore implements IProjectFilterStore {
// root store // root store
this.rootStore = _rootStore; this.rootStore = _rootStore;
// initialize display filters of the current workspace // initialize display filters of the current workspace
autorun(() => { reaction(
const workspaceSlug = this.rootStore.app.router.workspaceSlug; () => this.rootStore.app.router.workspaceSlug,
if (!workspaceSlug) return; (workspaceSlug) => {
this.initWorkspaceFilters(workspaceSlug); if (!workspaceSlug) return;
}); this.initWorkspaceFilters(workspaceSlug);
}
);
} }
/** /**
@ -96,7 +98,7 @@ export class ProjectFilterStore implements IProjectFilterStore {
this.displayFilters[workspaceSlug] = { this.displayFilters[workspaceSlug] = {
order_by: displayFilters?.order_by || "created_at", order_by: displayFilters?.order_by || "created_at",
}; };
this.filters[workspaceSlug] = {}; this.filters[workspaceSlug] = this.filters[workspaceSlug] ?? {};
}); });
}; };