diff --git a/web/components/issue-layouts/filters-preview/index.tsx b/web/components/issue-layouts/filters-preview/index.tsx index 2ecdc5909..758dbc71c 100644 --- a/web/components/issue-layouts/filters-preview/index.tsx +++ b/web/components/issue-layouts/filters-preview/index.tsx @@ -14,18 +14,19 @@ import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; import { RootStore } from "store/root"; // default data -import { issueFilterVisibilityData } from "store/helpers/issue-data"; +// import { issueFilterVisibilityData } from "store/helpers/issue-data"; export const FilterPreview = observer(() => { const store: RootStore = useMobxStore(); - const { issueFilters: issueFilterStore } = store; + const { issueFilter: issueFilterStore } = store; - const handleFilterSectionVisibility = (section_key: string) => - issueFilterStore?.issueView && - issueFilterStore?.issueLayout && - issueFilterVisibilityData[issueFilterStore?.issueView === "my_issues" ? "my_issues" : "issues"]?.filters?.[ - issueFilterStore?.issueLayout - ]?.includes(section_key); + const handleFilterSectionVisibility = (section_key: string) => { + // issueFilterStore?.issueView && + // issueFilterStore?.issueLayout && + // issueFilterVisibilityData[issueFilterStore?.issueView === "my_issues" ? "my_issues" : "issues"]?.filters?.[ + // issueFilterStore?.issueLayout + // ]?.includes(section_key); + }; const validateFiltersAvailability = issueFilterStore?.userFilters?.filters != null && diff --git a/web/pages/m-store/[workspace_slug]/[project_slug]/issues.tsx b/web/pages/m-store/[workspace_slug]/[project_slug]/issues.tsx index 44f143b22..de4a857bd 100644 --- a/web/pages/m-store/[workspace_slug]/[project_slug]/issues.tsx +++ b/web/pages/m-store/[workspace_slug]/[project_slug]/issues.tsx @@ -6,6 +6,7 @@ import { IssuesRoot } from "components/issue-layouts/root"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; import { RootStore } from "store/root"; +import useSWR from "swr"; const KanBanViewRoot = () => { const router = useRouter(); @@ -14,32 +15,41 @@ const KanBanViewRoot = () => { project_slug: string; }; - const { issue: issueViewStore, workspace: workspaceStore, project: projectStore }: RootStore = useMobxStore(); + const { + issue: issueViewStore, + workspace: workspaceStore, + project: projectStore, + issueFilter: issueFilterStore, + }: RootStore = useMobxStore(); + + useSWR( + workspace_slug && project_slug ? "USER_FILTERS" : null, + workspace_slug && project_slug + ? () => { + console.log("sdad"); + issueFilterStore.fetchUserFilters(workspace_slug.toString(), project_slug.toString()); + } + : null + ); React.useEffect(() => { console.log("request init--->"); const init = async () => { - workspaceStore.setWorkspaceId(workspace_slug); - await workspaceStore.getWorkspaces(); - await workspaceStore.getWorkspaceLabels(workspace_slug); - - projectStore.setProject(project_slug); - await projectStore.getWorkspaceProjects(workspace_slug); - await projectStore.getProjectStates(workspace_slug, project_slug); - await projectStore.getProjectLabels(workspace_slug, project_slug); - await projectStore.getProjectMembers(workspace_slug, project_slug); - - await issueViewStore.getProjectIssuesAsync(workspace_slug, project_slug); + // workspaceStore.setWorkspaceId(workspace_slug); + // await workspaceStore.getWorkspaces(); + // await workspaceStore.getWorkspaceLabels(workspace_slug); + // projectStore.setProject(project_slug); + // await projectStore.getWorkspaceProjects(workspace_slug); + // await projectStore.getProjectStates(workspace_slug, project_slug); + // await projectStore.getProjectLabels(workspace_slug, project_slug); + // await projectStore.getProjectMembers(workspace_slug, project_slug); + // await issueViewStore.getProjectIssuesAsync(workspace_slug, project_slug); }; if (workspace_slug && project_slug) init(); console.log("request completed--->"); }, [workspace_slug, project_slug, issueViewStore, workspaceStore, projectStore]); - return ( -
- -
- ); + return
{/* */}
; }; export default KanBanViewRoot; diff --git a/web/services/issue.service.ts b/web/services/issue.service.ts index 10b4383c6..f14a4eefe 100644 --- a/web/services/issue.service.ts +++ b/web/services/issue.service.ts @@ -12,7 +12,7 @@ import type { } from "types"; import { API_BASE_URL } from "helpers/common.helper"; -export class IssueServices extends APIService { +export class IssueService extends APIService { constructor() { super(API_BASE_URL); } @@ -607,6 +607,6 @@ export class IssueServices extends APIService { } } -const issuesServices = new IssueServices(); +const issueService = new IssueService(); -export default issuesServices; +export default issueService; diff --git a/web/services/project.service.ts b/web/services/project.service.ts index 4a1b4c582..5275349b5 100644 --- a/web/services/project.service.ts +++ b/web/services/project.service.ts @@ -16,7 +16,7 @@ import type { TProjectIssuesSearchParams, } from "types"; -export class ProjectServices extends APIService { +export class ProjectService extends APIService { constructor() { super(API_BASE_URL); } @@ -336,4 +336,4 @@ export class ProjectServices extends APIService { } } -export default new ProjectServices(); +export default new ProjectService(); diff --git a/web/services/project_publish.service.ts b/web/services/project_publish.service.ts index 1304e7924..4be1215aa 100644 --- a/web/services/project_publish.service.ts +++ b/web/services/project_publish.service.ts @@ -6,7 +6,7 @@ import trackEventServices from "services/track_event.service"; import { ICurrentUserResponse } from "types"; import { IProjectPublishSettings } from "store/project_publish"; -class ProjectServices extends APIService { +export class ProjectPublishServices extends APIService { constructor() { super(API_BASE_URL); } @@ -98,4 +98,4 @@ class ProjectServices extends APIService { } } -export default ProjectServices; +export default new ProjectPublishServices(); diff --git a/web/store/cycles.ts b/web/store/cycles.ts index 058e83094..5530548c4 100644 --- a/web/store/cycles.ts +++ b/web/store/cycles.ts @@ -2,8 +2,8 @@ import { action, computed, observable, makeObservable, runInAction } from "mobx" // types import { RootStore } from "./root"; // services -import { ProjectServices } from "services/project.service"; -import { IssueServices } from "services/issue.service"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; export interface ICycleStore { loader: boolean; @@ -40,8 +40,8 @@ class CycleStore implements ICycleStore { }); this.rootStore = _rootStore; - this.projectService = new ProjectServices(); - this.issueService = new IssueServices(); + this.projectService = new ProjectService(); + this.issueService = new IssueService(); } // computed diff --git a/web/store/issue_detail.ts b/web/store/issue_detail.ts index c2c0237a8..352769810 100644 --- a/web/store/issue_detail.ts +++ b/web/store/issue_detail.ts @@ -2,7 +2,7 @@ import { observable, action, makeObservable, runInAction } from "mobx"; // types import { RootStore } from "./root"; // services -import { IssueServices } from "services/issue.service"; +import { IssueService } from "services/issue.service"; export type IPeekMode = "side" | "modal" | "full"; @@ -80,7 +80,7 @@ class IssueViewDetailStore implements IIssueViewDetailStore { }); this.rootStore = _rootStore; - this.issueService = new IssueServices(); + this.issueService = new IssueService(); } setPeekId = (issueId: string | null) => (this.peekId = issueId); diff --git a/web/store/issue_filters.ts b/web/store/issue_filters.ts index ca01e7e9c..35186be56 100644 --- a/web/store/issue_filters.ts +++ b/web/store/issue_filters.ts @@ -1,12 +1,19 @@ import { observable, action, computed, makeObservable, runInAction } from "mobx"; // types import { RootStore } from "./root"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; export interface IIssueFilterStore { loader: boolean; error: any | null; userDisplayProperties: any; userDisplayFilters: any; + userFilters: any; + defaultDisplayFilters: any; + defaultFilters: any; + + fetchUserFilters: (workspaceSlug: string, projectSlug: string) => void; } class IssueFilterStore implements IIssueFilterStore { @@ -15,19 +22,64 @@ class IssueFilterStore implements IIssueFilterStore { // observables userDisplayProperties: any = {}; userDisplayFilters: any = {}; + userFilters: any = {}; + defaultDisplayFilters: any = {}; + defaultFilters: any = {}; + defaultDisplayProperties: any = { + assignee: true, + due_date: true, + key: true, + labels: true, + priority: true, + start_date: true, + state: true, + sub_issue_count: true, + }; // root store rootStore; + projectService; + issueService; + constructor(_rootStore: RootStore) { makeObservable(this, { loader: observable.ref, error: observable.ref, + defaultDisplayFilters: observable.ref, + defaultFilters: observable.ref, userDisplayProperties: observable.ref, userDisplayFilters: observable.ref, + userFilters: observable.ref, + fetchUserFilters: action, }); this.rootStore = _rootStore; + + this.projectService = new ProjectService(); + this.issueService = new IssueService(); } + + fetchUserFilters = async (workspaceSlug: string, projectId: string) => { + try { + const memberResponse = await this.projectService.projectMemberMe(workspaceSlug, projectId); + const issueProperties = await this.issueService.getIssueProperties(workspaceSlug, projectId); + + console.log("memberResponse", memberResponse); + + console.log("issueProperties", issueProperties); + + runInAction(() => { + this.userFilters = memberResponse?.view_props?.filters; + this.userDisplayFilters = memberResponse?.view_props?.display_filters; + this.userDisplayProperties = issueProperties?.properties || this.defaultDisplayProperties; + // default props from api + this.defaultFilters = memberResponse.default_props.filters; + this.defaultDisplayFilters = memberResponse.default_props.display_filters; + }); + } catch (error) { + console.log("Failed to fetch user filters in issue filter store", error); + } + }; } export default IssueFilterStore; diff --git a/web/store/modules.ts b/web/store/modules.ts index 42fe102a3..c0ef31ee1 100644 --- a/web/store/modules.ts +++ b/web/store/modules.ts @@ -2,8 +2,8 @@ import { action, computed, observable, makeObservable, runInAction } from "mobx" // types import { RootStore } from "./root"; // services -import { ProjectServices } from "services/project.service"; -import { IssueServices } from "services/issue.service"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; export interface IModuleStore { loader: boolean; @@ -40,8 +40,8 @@ class ModuleStore implements IModuleStore { }); this.rootStore = _rootStore; - this.projectService = new ProjectServices(); - this.issueService = new IssueServices(); + this.projectService = new ProjectService(); + this.issueService = new IssueService(); } // computed diff --git a/web/store/project.ts b/web/store/project.ts index 31cceb387..6fbf1d647 100644 --- a/web/store/project.ts +++ b/web/store/project.ts @@ -3,10 +3,10 @@ import { observable, action, computed, makeObservable, runInAction } from "mobx" import { RootStore } from "./root"; import { IProject, IIssueLabels, IProjectMember, IStateResponse, IState, ICycle, IModule, IView, IPage } from "types"; // services -import { ProjectServices } from "services/project.service"; -import { IssueServices } from "services/issue.service"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; import { ProjectStateServices } from "services/project_state.service"; -import CycleService from "services/cycles.service"; +import { CycleService } from "services/cycles.service"; import { ModuleService } from "services/modules.service"; import { ViewService } from "services/views.service"; import { PageService } from "services/page.service"; @@ -110,6 +110,7 @@ class ProjectStore implements IProjectStore { moduleService; viewService; pageService; + cycleService; constructor(_rootStore: RootStore) { makeObservable(this, { @@ -148,12 +149,13 @@ class ProjectStore implements IProjectStore { }); this.rootStore = _rootStore; - this.projectService = new ProjectServices(); - this.issueService = new IssueServices(); + this.projectService = new ProjectService(); + this.issueService = new IssueService(); this.stateService = new ProjectStateServices(); this.moduleService = new ModuleService(); this.viewService = new ViewService(); this.pageService = new PageService(); + this.cycleService = new CycleService(); } get projectStatesByGroups() { @@ -307,7 +309,7 @@ class ProjectStore implements IProjectStore { this.loader = true; this.error = null; - const cyclesResponse = await CycleService.getCyclesWithParams(workspaceSlug, projectSlug, "all"); + const cyclesResponse = await this.cycleService.getCyclesWithParams(workspaceSlug, projectSlug, "all"); runInAction(() => { this.cycles = { diff --git a/web/store/project_publish.ts b/web/store/project_publish.ts index 6ce8dbc5b..593200712 100644 --- a/web/store/project_publish.ts +++ b/web/store/project_publish.ts @@ -2,7 +2,7 @@ import { observable, action, computed, makeObservable, runInAction } from "mobx" // types import { RootStore } from "./root"; // services -import ProjectServices from "services/project_publish.service"; +import { ProjectPublishServices } from "services/project_publish.service"; export type TProjectPublishViews = "list" | "gantt" | "kanban" | "calendar" | "spreadsheet"; @@ -87,7 +87,7 @@ class ProjectPublishStore implements IProjectPublishStore { }); this.rootStore = _rootStore; - this.projectPublishService = new ProjectServices(); + this.projectPublishService = new ProjectPublishServices(); } handleProjectModal = (project_id: string | null = null) => { diff --git a/web/store/views.ts b/web/store/views.ts index 7edabf6a8..0748a5456 100644 --- a/web/store/views.ts +++ b/web/store/views.ts @@ -2,8 +2,8 @@ import { action, computed, observable, makeObservable, runInAction } from "mobx" // types import { RootStore } from "./root"; // services -import { ProjectServices } from "services/project.service"; -import { IssueServices } from "services/issue.service"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; export interface IViewStore { loader: boolean; @@ -40,8 +40,8 @@ class ViewStore implements IViewStore { }); this.rootStore = _rootStore; - this.projectService = new ProjectServices(); - this.issueService = new IssueServices(); + this.projectService = new ProjectService(); + this.issueService = new IssueService(); } // computed diff --git a/web/store/workspace.ts b/web/store/workspace.ts index 50928cad3..5f27ab2f7 100644 --- a/web/store/workspace.ts +++ b/web/store/workspace.ts @@ -4,8 +4,8 @@ import { RootStore } from "./root"; import { IIssueLabels, IProject, IWorkspace } from "types"; // services import { WorkspaceService } from "services/workspace.service"; -import { ProjectServices } from "services/project.service"; -import { IssueServices } from "services/issue.service"; +import { ProjectService } from "services/project.service"; +import { IssueService } from "services/issue.service"; export interface IWorkspaceStore { loader: boolean; @@ -64,8 +64,8 @@ class WorkspaceStore implements IWorkspaceStore { this.rootStore = _rootStore; this.workspaceService = new WorkspaceService(); - this.projectService = new ProjectServices(); - this.issueService = new IssueServices(); + this.projectService = new ProjectService(); + this.issueService = new IssueService(); } /**