forked from github/plane
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
This commit is contained in:
parent
7f3dbe298c
commit
2cda47dc8a
@ -8,6 +8,7 @@ import { ProfileIssuesFilter } from "components/profile";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isAuthorized: boolean;
|
isAuthorized: boolean;
|
||||||
|
showProfileIssuesFilter?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewerTabs = [
|
const viewerTabs = [
|
||||||
@ -36,7 +37,9 @@ const adminTabs = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ProfileNavbar: React.FC<Props> = ({ isAuthorized }) => {
|
export const ProfileNavbar: React.FC<Props> = (props) => {
|
||||||
|
const { isAuthorized, showProfileIssuesFilter } = props;
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, userId } = router.query;
|
const { workspaceSlug, userId } = router.query;
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ export const ProfileNavbar: React.FC<Props> = ({ isAuthorized }) => {
|
|||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<ProfileIssuesFilter />
|
{showProfileIssuesFilter && <ProfileIssuesFilter />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -10,8 +10,16 @@ import { ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue";
|
|||||||
export const ProfileIssuesFilter = observer(() => {
|
export const ProfileIssuesFilter = observer(() => {
|
||||||
const { workspace: workspaceStore, profileIssueFilters: profileIssueFiltersStore }: RootStore = useMobxStore();
|
const { workspace: workspaceStore, profileIssueFilters: profileIssueFiltersStore }: RootStore = useMobxStore();
|
||||||
|
|
||||||
const handleLayoutChange = (_layout: string) =>
|
const handleLayoutChange = (_layout: string) => {
|
||||||
profileIssueFiltersStore.handleIssueFilters("userDisplayFilters", { layout: _layout });
|
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) => {
|
const handleFilters = (key: any, value: any) => {
|
||||||
let updatesFilters: any = profileIssueFiltersStore?.userFilters;
|
let updatesFilters: any = profileIssueFiltersStore?.userFilters;
|
||||||
|
@ -10,12 +10,15 @@ import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys";
|
|||||||
type Props = {
|
type Props = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
showProfileIssuesFilter?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// services
|
// services
|
||||||
const workspaceService = new WorkspaceService();
|
const workspaceService = new WorkspaceService();
|
||||||
|
|
||||||
export const ProfileAuthWrapper: React.FC<Props> = ({ children, className }) => {
|
export const ProfileAuthWrapper: React.FC<Props> = (props) => {
|
||||||
|
const { children, className, showProfileIssuesFilter } = props;
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug } = router.query;
|
const { workspaceSlug } = router.query;
|
||||||
|
|
||||||
@ -30,7 +33,7 @@ export const ProfileAuthWrapper: React.FC<Props> = ({ children, className }) =>
|
|||||||
<div className="h-full w-full md:flex md:flex-row-reverse md:overflow-hidden">
|
<div className="h-full w-full md:flex md:flex-row-reverse md:overflow-hidden">
|
||||||
<ProfileSidebar />
|
<ProfileSidebar />
|
||||||
<div className="md:h-full w-full flex flex-col md:overflow-hidden">
|
<div className="md:h-full w-full flex flex-col md:overflow-hidden">
|
||||||
<ProfileNavbar isAuthorized={isAuthorized} />
|
<ProfileNavbar isAuthorized={isAuthorized} showProfileIssuesFilter={showProfileIssuesFilter} />
|
||||||
{isAuthorized ? (
|
{isAuthorized ? (
|
||||||
<div className={`md:h-full w-full overflow-hidden ${className}`}>{children}</div>
|
<div className={`md:h-full w-full overflow-hidden ${className}`}>{children}</div>
|
||||||
) : (
|
) : (
|
||||||
|
@ -30,7 +30,7 @@ const ProfileAssignedIssues: NextPage = observer(() => {
|
|||||||
userId: string;
|
userId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
useSWR(`PROFILE_ISSUES_${workspaceSlug}_${userId}`, async () => {
|
const { isLoading } = useSWR(`PROFILE_ISSUES_${workspaceSlug}_${userId}`, async () => {
|
||||||
if (workspaceSlug && userId) {
|
if (workspaceSlug && userId) {
|
||||||
// workspace labels
|
// workspace labels
|
||||||
workspaceStore.setWorkspaceSlug(workspaceSlug);
|
workspaceStore.setWorkspaceSlug(workspaceSlug);
|
||||||
@ -46,8 +46,8 @@ const ProfileAssignedIssues: NextPage = observer(() => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AppLayout header={<UserProfileHeader />}>
|
<AppLayout header={<UserProfileHeader />}>
|
||||||
<ProfileAuthWrapper>
|
<ProfileAuthWrapper showProfileIssuesFilter>
|
||||||
{profileIssuesStore.loader ? (
|
{isLoading ? (
|
||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="w-full h-full relative overflow-auto -z-1">
|
<div className="w-full h-full relative overflow-auto -z-1">
|
||||||
|
@ -1,20 +1,61 @@
|
|||||||
import React from "react";
|
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
|
// layouts
|
||||||
import { AppLayout } from "layouts/app-layout";
|
import { AppLayout } from "layouts/app-layout";
|
||||||
import { ProfileAuthWrapper } from "layouts/profile-layout";
|
import { ProfileAuthWrapper } from "layouts/profile-layout";
|
||||||
// components
|
// components
|
||||||
import { UserProfileHeader } from "components/headers";
|
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
|
// types
|
||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
|
|
||||||
const ProfileCreatedIssues: NextPage = () => (
|
const ProfileCreatedIssues: NextPage = () => {
|
||||||
|
const {
|
||||||
|
workspace: workspaceStore,
|
||||||
|
project: projectStore,
|
||||||
|
profileIssueFilters: profileIssueFiltersStore,
|
||||||
|
profileIssues: profileIssuesStore,
|
||||||
|
} = useMobxStore();
|
||||||
|
|
||||||
|
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 (
|
||||||
<AppLayout header={<UserProfileHeader />}>
|
<AppLayout header={<UserProfileHeader />}>
|
||||||
<ProfileAuthWrapper>
|
<ProfileAuthWrapper showProfileIssuesFilter>
|
||||||
<ProfileIssuesView />
|
{isLoading ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-full relative overflow-auto -z-1">
|
||||||
|
{activeLayout === "list" ? (
|
||||||
|
<ProfileIssuesListLayout />
|
||||||
|
) : activeLayout === "kanban" ? (
|
||||||
|
<ProfileIssuesKanBanLayout />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</ProfileAuthWrapper>
|
</ProfileAuthWrapper>
|
||||||
</AppLayout>
|
</AppLayout>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default ProfileCreatedIssues;
|
export default observer(ProfileCreatedIssues);
|
||||||
|
@ -1,20 +1,61 @@
|
|||||||
import React from "react";
|
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
|
// layouts
|
||||||
import { AppLayout } from "layouts/app-layout";
|
import { AppLayout } from "layouts/app-layout";
|
||||||
import { ProfileAuthWrapper } from "layouts/profile-layout";
|
import { ProfileAuthWrapper } from "layouts/profile-layout";
|
||||||
// components
|
// components
|
||||||
import { UserProfileHeader } from "components/headers";
|
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
|
// types
|
||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
|
|
||||||
const ProfileSubscribedIssues: NextPage = () => (
|
const ProfileSubscribedIssues: NextPage = () => {
|
||||||
|
const {
|
||||||
|
workspace: workspaceStore,
|
||||||
|
project: projectStore,
|
||||||
|
profileIssueFilters: profileIssueFiltersStore,
|
||||||
|
profileIssues: profileIssuesStore,
|
||||||
|
} = useMobxStore();
|
||||||
|
|
||||||
|
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 (
|
||||||
<AppLayout header={<UserProfileHeader />}>
|
<AppLayout header={<UserProfileHeader />}>
|
||||||
<ProfileAuthWrapper>
|
<ProfileAuthWrapper showProfileIssuesFilter>
|
||||||
<ProfileIssuesView />
|
{isLoading ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-full relative overflow-auto -z-1">
|
||||||
|
{activeLayout === "list" ? (
|
||||||
|
<ProfileIssuesListLayout />
|
||||||
|
) : activeLayout === "kanban" ? (
|
||||||
|
<ProfileIssuesKanBanLayout />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</ProfileAuthWrapper>
|
</ProfileAuthWrapper>
|
||||||
</AppLayout>
|
</AppLayout>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default ProfileSubscribedIssues;
|
export default observer(ProfileSubscribedIssues);
|
||||||
|
@ -67,7 +67,7 @@ export class ProfileIssueFilterStore implements IProfileIssueFilterStore {
|
|||||||
if (this.userFilters || this.userDisplayFilters || this.userDisplayProperties) {
|
if (this.userFilters || this.userDisplayFilters || this.userDisplayProperties) {
|
||||||
const workspaceSlug = this.rootStore.workspace.workspaceSlug;
|
const workspaceSlug = this.rootStore.workspace.workspaceSlug;
|
||||||
const userId = this.rootStore.profileIssues?.userId;
|
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");
|
console.log("autorun triggered");
|
||||||
this.rootStore.profileIssues.fetchIssues(
|
this.rootStore.profileIssues.fetchIssues(
|
||||||
workspaceSlug,
|
workspaceSlug,
|
||||||
|
Loading…
Reference in New Issue
Block a user