From 2cda47dc8a9c4362f89b7751428d23583fe8ecb3 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:25:44 +0530 Subject: [PATCH] refactor: user profile store setup and bug fixes (#2586) * fix: autorun not working when filters are changed * fix: filter/display on overview page * refactor: store implementation & loader in 'created' & 'subscribed' page --- web/components/profile/navbar.tsx | 7 ++- .../profile/profile-issues-filter.tsx | 12 +++- web/layouts/profile-layout/layout.tsx | 7 ++- .../profile/[userId]/assigned.tsx | 6 +- .../profile/[userId]/created.tsx | 61 ++++++++++++++++--- .../profile/[userId]/subscribed.tsx | 61 ++++++++++++++++--- .../profile-issues/issue_filters.store.ts | 2 +- 7 files changed, 126 insertions(+), 30 deletions(-) diff --git a/web/components/profile/navbar.tsx b/web/components/profile/navbar.tsx index 433452536..a1f57e6b5 100644 --- a/web/components/profile/navbar.tsx +++ b/web/components/profile/navbar.tsx @@ -8,6 +8,7 @@ import { ProfileIssuesFilter } from "components/profile"; type Props = { isAuthorized: boolean; + showProfileIssuesFilter?: boolean; }; const viewerTabs = [ @@ -36,7 +37,9 @@ const adminTabs = [ }, ]; -export const ProfileNavbar: React.FC = ({ isAuthorized }) => { +export const ProfileNavbar: React.FC = (props) => { + const { isAuthorized, showProfileIssuesFilter } = props; + const router = useRouter(); const { workspaceSlug, userId } = router.query; @@ -59,7 +62,7 @@ export const ProfileNavbar: React.FC = ({ isAuthorized }) => { ))} - + {showProfileIssuesFilter && } ); }; diff --git a/web/components/profile/profile-issues-filter.tsx b/web/components/profile/profile-issues-filter.tsx index 7acc73c99..28bc2259d 100644 --- a/web/components/profile/profile-issues-filter.tsx +++ b/web/components/profile/profile-issues-filter.tsx @@ -10,8 +10,16 @@ import { ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue"; export const ProfileIssuesFilter = observer(() => { const { workspace: workspaceStore, profileIssueFilters: profileIssueFiltersStore }: RootStore = useMobxStore(); - const handleLayoutChange = (_layout: string) => - profileIssueFiltersStore.handleIssueFilters("userDisplayFilters", { layout: _layout }); + const handleLayoutChange = (_layout: string) => { + const payload = { + layout: _layout, + group_by: profileIssueFiltersStore.userDisplayFilters.group_by + ? profileIssueFiltersStore.userDisplayFilters.group_by + : "state_detail.group", + }; + + profileIssueFiltersStore.handleIssueFilters("userDisplayFilters", payload); + }; const handleFilters = (key: any, value: any) => { let updatesFilters: any = profileIssueFiltersStore?.userFilters; diff --git a/web/layouts/profile-layout/layout.tsx b/web/layouts/profile-layout/layout.tsx index c7e379167..4127530da 100644 --- a/web/layouts/profile-layout/layout.tsx +++ b/web/layouts/profile-layout/layout.tsx @@ -10,12 +10,15 @@ import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys"; type Props = { children: React.ReactNode; className?: string; + showProfileIssuesFilter?: boolean; }; // services const workspaceService = new WorkspaceService(); -export const ProfileAuthWrapper: React.FC = ({ children, className }) => { +export const ProfileAuthWrapper: React.FC = (props) => { + const { children, className, showProfileIssuesFilter } = props; + const router = useRouter(); const { workspaceSlug } = router.query; @@ -30,7 +33,7 @@ export const ProfileAuthWrapper: React.FC = ({ children, className }) =>
- + {isAuthorized ? (
{children}
) : ( diff --git a/web/pages/[workspaceSlug]/profile/[userId]/assigned.tsx b/web/pages/[workspaceSlug]/profile/[userId]/assigned.tsx index e0fde1d25..36d5b47e6 100644 --- a/web/pages/[workspaceSlug]/profile/[userId]/assigned.tsx +++ b/web/pages/[workspaceSlug]/profile/[userId]/assigned.tsx @@ -30,7 +30,7 @@ const ProfileAssignedIssues: NextPage = observer(() => { userId: string; }; - useSWR(`PROFILE_ISSUES_${workspaceSlug}_${userId}`, async () => { + const { isLoading } = useSWR(`PROFILE_ISSUES_${workspaceSlug}_${userId}`, async () => { if (workspaceSlug && userId) { // workspace labels workspaceStore.setWorkspaceSlug(workspaceSlug); @@ -46,8 +46,8 @@ const ProfileAssignedIssues: NextPage = observer(() => { return ( }> - - {profileIssuesStore.loader ? ( + + {isLoading ? (
Loading...
) : (
diff --git a/web/pages/[workspaceSlug]/profile/[userId]/created.tsx b/web/pages/[workspaceSlug]/profile/[userId]/created.tsx index ad6e89dea..4d171e7d4 100644 --- a/web/pages/[workspaceSlug]/profile/[userId]/created.tsx +++ b/web/pages/[workspaceSlug]/profile/[userId]/created.tsx @@ -1,20 +1,61 @@ import React from "react"; - +import { useRouter } from "next/router"; +import useSWR from "swr"; +// store +import { observer } from "mobx-react-lite"; +import { useMobxStore } from "lib/mobx/store-provider"; // layouts import { AppLayout } from "layouts/app-layout"; import { ProfileAuthWrapper } from "layouts/profile-layout"; // components import { UserProfileHeader } from "components/headers"; -import { ProfileIssuesView } from "components/profile"; +import { ProfileIssuesListLayout } from "components/issues/issue-layouts/list/roots/profile-issues-root"; +import { ProfileIssuesKanBanLayout } from "components/issues/issue-layouts/kanban/roots/profile-issues-root"; // types import type { NextPage } from "next"; -const ProfileCreatedIssues: NextPage = () => ( - }> - - - - -); +const ProfileCreatedIssues: NextPage = () => { + const { + workspace: workspaceStore, + project: projectStore, + profileIssueFilters: profileIssueFiltersStore, + profileIssues: profileIssuesStore, + } = useMobxStore(); -export default ProfileCreatedIssues; + const router = useRouter(); + const { workspaceSlug, userId } = router.query; + + const { isLoading } = useSWR(`PROFILE_ISSUES_CREATED_${workspaceSlug}_${userId}`, async () => { + if (workspaceSlug && userId) { + // workspace labels + workspaceStore.setWorkspaceSlug(workspaceSlug.toString()); + await workspaceStore.fetchWorkspaceLabels(workspaceSlug.toString()); + await projectStore.fetchProjects(workspaceSlug.toString()); + + //profile issues + await profileIssuesStore.fetchIssues(workspaceSlug.toString(), userId.toString(), "created"); + } + }); + + const activeLayout = profileIssueFiltersStore.userDisplayFilters.layout; + + return ( + }> + + {isLoading ? ( +
Loading...
+ ) : ( +
+ {activeLayout === "list" ? ( + + ) : activeLayout === "kanban" ? ( + + ) : null} +
+ )} +
+
+ ); +}; + +export default observer(ProfileCreatedIssues); diff --git a/web/pages/[workspaceSlug]/profile/[userId]/subscribed.tsx b/web/pages/[workspaceSlug]/profile/[userId]/subscribed.tsx index 3d3400a80..4efded65b 100644 --- a/web/pages/[workspaceSlug]/profile/[userId]/subscribed.tsx +++ b/web/pages/[workspaceSlug]/profile/[userId]/subscribed.tsx @@ -1,20 +1,61 @@ import React from "react"; - +import { useRouter } from "next/router"; +import useSWR from "swr"; +// store +import { observer } from "mobx-react-lite"; +import { useMobxStore } from "lib/mobx/store-provider"; // layouts import { AppLayout } from "layouts/app-layout"; import { ProfileAuthWrapper } from "layouts/profile-layout"; // components import { UserProfileHeader } from "components/headers"; -import { ProfileIssuesView } from "components/profile"; +import { ProfileIssuesListLayout } from "components/issues/issue-layouts/list/roots/profile-issues-root"; +import { ProfileIssuesKanBanLayout } from "components/issues/issue-layouts/kanban/roots/profile-issues-root"; // types import type { NextPage } from "next"; -const ProfileSubscribedIssues: NextPage = () => ( - }> - - - - -); +const ProfileSubscribedIssues: NextPage = () => { + const { + workspace: workspaceStore, + project: projectStore, + profileIssueFilters: profileIssueFiltersStore, + profileIssues: profileIssuesStore, + } = useMobxStore(); -export default ProfileSubscribedIssues; + const router = useRouter(); + const { workspaceSlug, userId } = router.query; + + const { isLoading } = useSWR(`PROFILE_ISSUES_SUBSCRIBED_${workspaceSlug}_${userId}`, async () => { + if (workspaceSlug && userId) { + // workspace labels + workspaceStore.setWorkspaceSlug(workspaceSlug.toString()); + await workspaceStore.fetchWorkspaceLabels(workspaceSlug.toString()); + await projectStore.fetchProjects(workspaceSlug.toString()); + + //profile issues + await profileIssuesStore.fetchIssues(workspaceSlug.toString(), userId.toString(), "subscribed"); + } + }); + + const activeLayout = profileIssueFiltersStore.userDisplayFilters.layout; + + return ( + }> + + {isLoading ? ( +
Loading...
+ ) : ( +
+ {activeLayout === "list" ? ( + + ) : activeLayout === "kanban" ? ( + + ) : null} +
+ )} +
+
+ ); +}; + +export default observer(ProfileSubscribedIssues); diff --git a/web/store/profile-issues/issue_filters.store.ts b/web/store/profile-issues/issue_filters.store.ts index c1d352564..6573ec447 100644 --- a/web/store/profile-issues/issue_filters.store.ts +++ b/web/store/profile-issues/issue_filters.store.ts @@ -67,7 +67,7 @@ export class ProfileIssueFilterStore implements IProfileIssueFilterStore { if (this.userFilters || this.userDisplayFilters || this.userDisplayProperties) { const workspaceSlug = this.rootStore.workspace.workspaceSlug; const userId = this.rootStore.profileIssues?.userId; - if (workspaceSlug && userId && this.rootStore.profileIssues.currentProfileTab) { + if (workspaceSlug && userId && this.rootStore.profileIssues.currentProfileTab && this.appliedFilters) { console.log("autorun triggered"); this.rootStore.profileIssues.fetchIssues( workspaceSlug,