fix: project views bugs related to store refactor. (#3391)

* chore: remove debounce logic to fix create/ update view modal bugs.

* fix: bug in delete views not mutating the store.

* chore: replace `Project Empty State` with `Project Views Empty State`.

* chore: add issue peek overview.

* refactor: issue update, delete actions for project views layout.
fix: issue update and delete action throwing error bug.
fix: issue quick add throwing error bug.
This commit is contained in:
Prateek Shourya 2024-01-17 18:37:46 +05:30 committed by GitHub
parent a1d27a1bf0
commit 7833ca7bea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 131 additions and 125 deletions

View File

@ -4,33 +4,28 @@ import { observer } from "mobx-react-lite";
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// components // components
import { ProjectIssueQuickActions } from "components/issues"; import { ProjectIssueQuickActions } from "components/issues";
import { BaseCalendarRoot } from "../base-calendar-root";
// types // types
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
import { EIssueActions } from "../../types"; import { EIssueActions } from "../../types";
import { BaseCalendarRoot } from "../base-calendar-root"; // constants
import { EIssuesStoreType } from "constants/issue"; import { EIssuesStoreType } from "constants/issue";
import { useMemo } from "react";
export const ProjectViewCalendarLayout: React.FC = observer(() => { export interface IViewCalendarLayout {
issueActions: {
[EIssueActions.DELETE]: (issue: TIssue) => Promise<void>;
[EIssueActions.UPDATE]?: (issue: TIssue) => Promise<void>;
[EIssueActions.REMOVE]?: (issue: TIssue) => Promise<void>;
};
}
export const ProjectViewCalendarLayout: React.FC<IViewCalendarLayout> = observer((props) => {
const { issueActions } = props;
// store
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW);
// router
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId, viewId } = router.query; const { viewId } = router.query;
const issueActions = useMemo(
() => ({
[EIssueActions.UPDATE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, issue);
},
[EIssueActions.DELETE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.removeIssue(workspaceSlug.toString(), projectId.toString(), issue.id);
},
}),
[issues, workspaceSlug, projectId]
);
return ( return (
<BaseCalendarRoot <BaseCalendarRoot

View File

@ -4,28 +4,34 @@ import { observer } from "mobx-react-lite";
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// components // components
import { BaseGanttRoot } from "./base-gantt-root"; import { BaseGanttRoot } from "./base-gantt-root";
// constants
import { EIssuesStoreType } from "constants/issue"; import { EIssuesStoreType } from "constants/issue";
// types
import { EIssueActions } from "../types"; import { EIssueActions } from "../types";
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
export const ProjectViewGanttLayout: React.FC = observer(() => { export interface IViewGanttLayout {
issueActions: {
[EIssueActions.DELETE]: (issue: TIssue) => Promise<void>;
[EIssueActions.UPDATE]?: (issue: TIssue) => Promise<void>;
[EIssueActions.REMOVE]?: (issue: TIssue) => Promise<void>;
};
}
export const ProjectViewGanttLayout: React.FC<IViewGanttLayout> = observer((props) => {
const { issueActions } = props;
// store
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW);
// router // router
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query; const { viewId } = router.query;
const issueActions = { return (
[EIssueActions.UPDATE]: async (issue: TIssue) => { <BaseGanttRoot
if (!workspaceSlug) return; issueFiltersStore={issuesFilter}
issueStore={issues}
await issues.updateIssue(workspaceSlug.toString(), issue.project_id, issue.id, issue); issueActions={issueActions}
}, viewId={viewId?.toString()}
[EIssueActions.DELETE]: async (issue: TIssue) => { />
if (!workspaceSlug) return; );
await issues.removeIssue(workspaceSlug.toString(), issue.project_id, issue.id);
},
};
return <BaseGanttRoot issueFiltersStore={issuesFilter} issueStore={issues} issueActions={issueActions} />;
}); });

View File

@ -1,38 +1,32 @@
import React, { useMemo } from "react"; import React from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// hooks // hooks
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// constant // constant
import { EIssuesStoreType } from "constants/issue";
// types
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
import { EIssueActions } from "../../types"; import { EIssueActions } from "../../types";
import { ProjectIssueQuickActions } from "../../quick-action-dropdowns";
// components // components
import { BaseKanBanRoot } from "../base-kanban-root"; import { BaseKanBanRoot } from "../base-kanban-root";
import { EIssuesStoreType } from "constants/issue"; import { ProjectIssueQuickActions } from "../../quick-action-dropdowns";
export interface IViewKanBanLayout {} export interface IViewKanBanLayout {
issueActions: {
[EIssueActions.DELETE]: (issue: TIssue) => Promise<void>;
[EIssueActions.UPDATE]?: (issue: TIssue) => Promise<void>;
[EIssueActions.REMOVE]?: (issue: TIssue) => Promise<void>;
};
}
export const ProjectViewKanBanLayout: React.FC = observer(() => { export const ProjectViewKanBanLayout: React.FC<IViewKanBanLayout> = observer((props) => {
const { issueActions } = props;
// router
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query as { workspaceSlug: string; projectId: string }; const { viewId } = router.query;
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW);
const issueActions = useMemo(
() => ({
[EIssueActions.UPDATE]: async (issue: TIssue) => {
if (!workspaceSlug) return;
await issues.updateIssue(workspaceSlug, issue.project_id, issue.id, issue);
},
[EIssueActions.DELETE]: async (issue: TIssue) => {
if (!workspaceSlug) return;
await issues.removeIssue(workspaceSlug, issue.project_id, issue.id);
},
}),
[issues, workspaceSlug]
);
return ( return (
<BaseKanBanRoot <BaseKanBanRoot
@ -42,6 +36,7 @@ export const ProjectViewKanBanLayout: React.FC = observer(() => {
showLoader={true} showLoader={true}
QuickActions={ProjectIssueQuickActions} QuickActions={ProjectIssueQuickActions}
currentStore={EIssuesStoreType.PROJECT_VIEW} currentStore={EIssuesStoreType.PROJECT_VIEW}
viewId={viewId?.toString()}
/> />
); );
}); });

View File

@ -1,43 +1,35 @@
import React, { useMemo } from "react"; import React from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { useRouter } from "next/router";
// store // store
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// constants // constants
import { useRouter } from "next/router"; import { EIssuesStoreType } from "constants/issue";
// types
import { EIssueActions } from "../../types"; import { EIssueActions } from "../../types";
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
// components // components
import { BaseListRoot } from "../base-list-root"; import { BaseListRoot } from "../base-list-root";
import { ProjectIssueQuickActions } from "../../quick-action-dropdowns"; import { ProjectIssueQuickActions } from "../../quick-action-dropdowns";
import { EIssuesStoreType } from "constants/issue";
export interface IViewListLayout {} export interface IViewListLayout {
issueActions: {
[EIssueActions.DELETE]: (issue: TIssue) => Promise<void>;
[EIssueActions.UPDATE]?: (issue: TIssue) => Promise<void>;
[EIssueActions.REMOVE]?: (issue: TIssue) => Promise<void>;
};
}
export const ProjectViewListLayout: React.FC = observer(() => { export const ProjectViewListLayout: React.FC<IViewListLayout> = observer((props) => {
const { issueActions } = props;
// store // store
const { issuesFilter, issues } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { issuesFilter, issues } = useIssues(EIssuesStoreType.PROJECT_VIEW);
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query as { workspaceSlug: string; projectId: string }; const { workspaceSlug, projectId, viewId } = router.query;
if (!workspaceSlug || !projectId) return null; if (!workspaceSlug || !projectId) return null;
const issueActions = useMemo(
() => ({
[EIssueActions.UPDATE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.updateIssue(workspaceSlug, projectId, issue.id, issue);
},
[EIssueActions.DELETE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.removeIssue(workspaceSlug, projectId, issue.id);
},
}),
[issues, workspaceSlug, projectId]
);
return ( return (
<BaseListRoot <BaseListRoot
issuesFilter={issuesFilter} issuesFilter={issuesFilter}
@ -45,6 +37,7 @@ export const ProjectViewListLayout: React.FC = observer(() => {
QuickActions={ProjectIssueQuickActions} QuickActions={ProjectIssueQuickActions}
issueActions={issueActions} issueActions={issueActions}
currentStore={EIssuesStoreType.PROJECT_VIEW} currentStore={EIssuesStoreType.PROJECT_VIEW}
viewId={viewId?.toString()}
/> />
); );
}); });

View File

@ -1,4 +1,4 @@
import React from "react"; import React, { useMemo } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import useSWR from "swr"; import useSWR from "swr";
@ -6,16 +6,21 @@ import useSWR from "swr";
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// components // components
import { import {
ProjectEmptyState, IssuePeekOverview,
ProjectViewAppliedFiltersRoot, ProjectViewAppliedFiltersRoot,
ProjectViewCalendarLayout, ProjectViewCalendarLayout,
ProjectViewEmptyState,
ProjectViewGanttLayout, ProjectViewGanttLayout,
ProjectViewKanBanLayout, ProjectViewKanBanLayout,
ProjectViewListLayout, ProjectViewListLayout,
ProjectViewSpreadsheetLayout, ProjectViewSpreadsheetLayout,
} from "components/issues"; } from "components/issues";
import { Spinner } from "@plane/ui"; import { Spinner } from "@plane/ui";
// constants
import { EIssuesStoreType } from "constants/issue"; import { EIssuesStoreType } from "constants/issue";
// types
import { TIssue } from "@plane/types";
import { EIssueActions } from "../types";
export const ProjectViewLayoutRoot: React.FC = observer(() => { export const ProjectViewLayoutRoot: React.FC = observer(() => {
// router // router
@ -39,6 +44,22 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => {
} }
); );
const issueActions = useMemo(
() => ({
[EIssueActions.UPDATE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, issue, viewId?.toString());
},
[EIssueActions.DELETE]: async (issue: TIssue) => {
if (!workspaceSlug || !projectId) return;
await issues.removeIssue(workspaceSlug.toString(), projectId.toString(), issue.id, viewId?.toString());
},
}),
[issues, workspaceSlug, projectId, viewId]
);
const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout; const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout;
if (!workspaceSlug || !projectId || !viewId) return <></>; if (!workspaceSlug || !projectId || !viewId) return <></>;
@ -53,22 +74,26 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => {
) : ( ) : (
<> <>
{!issues?.groupedIssueIds ? ( {!issues?.groupedIssueIds ? (
// TODO: Replace this with project view empty state <ProjectViewEmptyState />
<ProjectEmptyState />
) : ( ) : (
<div className="relative h-full w-full overflow-auto"> <>
{activeLayout === "list" ? ( <div className="relative h-full w-full overflow-auto">
<ProjectViewListLayout /> {activeLayout === "list" ? (
) : activeLayout === "kanban" ? ( <ProjectViewListLayout issueActions={issueActions} />
<ProjectViewKanBanLayout /> ) : activeLayout === "kanban" ? (
) : activeLayout === "calendar" ? ( <ProjectViewKanBanLayout issueActions={issueActions} />
<ProjectViewCalendarLayout /> ) : activeLayout === "calendar" ? (
) : activeLayout === "gantt_chart" ? ( <ProjectViewCalendarLayout issueActions={issueActions} />
<ProjectViewGanttLayout /> ) : activeLayout === "gantt_chart" ? (
) : activeLayout === "spreadsheet" ? ( <ProjectViewGanttLayout issueActions={issueActions} />
<ProjectViewSpreadsheetLayout /> ) : activeLayout === "spreadsheet" ? (
) : null} <ProjectViewSpreadsheetLayout issueActions={issueActions} />
</div> ) : null}
</div>
{/* peek overview */}
<IssuePeekOverview />
</>
)} )}
</> </>
)} )}

View File

@ -1,43 +1,40 @@
import React, { useMemo } from "react"; import React from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// mobx store // mobx store
import { useIssues } from "hooks/store"; import { useIssues } from "hooks/store";
// components // components
import { BaseSpreadsheetRoot } from "../base-spreadsheet-root"; import { BaseSpreadsheetRoot } from "../base-spreadsheet-root";
import { ProjectIssueQuickActions } from "../../quick-action-dropdowns";
// types
import { EIssueActions } from "../../types"; import { EIssueActions } from "../../types";
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
import { ProjectIssueQuickActions } from "../../quick-action-dropdowns"; // constants
import { EIssuesStoreType } from "constants/issue"; import { EIssuesStoreType } from "constants/issue";
export const ProjectViewSpreadsheetLayout: React.FC = observer(() => { export interface IViewSpreadsheetLayout {
issueActions: {
[EIssueActions.DELETE]: (issue: TIssue) => Promise<void>;
[EIssueActions.UPDATE]?: (issue: TIssue) => Promise<void>;
[EIssueActions.REMOVE]?: (issue: TIssue) => Promise<void>;
};
}
export const ProjectViewSpreadsheetLayout: React.FC<IViewSpreadsheetLayout> = observer((props) => {
const { issueActions } = props;
// router
const router = useRouter(); const router = useRouter();
const { workspaceSlug } = router.query as { workspaceSlug: string }; const { viewId } = router.query;
const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW); const { issues, issuesFilter } = useIssues(EIssuesStoreType.PROJECT_VIEW);
const issueActions = useMemo(
() => ({
[EIssueActions.UPDATE]: async (issue: TIssue) => {
if (!workspaceSlug) return;
await issues.updateIssue(workspaceSlug, issue.project_id, issue.id, issue);
},
[EIssueActions.DELETE]: async (issue: TIssue) => {
if (!workspaceSlug) return;
await issues.removeIssue(workspaceSlug, issue.project_id, issue.id);
},
}),
[issues, workspaceSlug]
);
return ( return (
<BaseSpreadsheetRoot <BaseSpreadsheetRoot
issueStore={issues} issueStore={issues}
issueFiltersStore={issuesFilter} issueFiltersStore={issuesFilter}
issueActions={issueActions} issueActions={issueActions}
QuickActions={ProjectIssueQuickActions} QuickActions={ProjectIssueQuickActions}
viewId={viewId?.toString()}
/> />
); );
}); });

View File

@ -208,7 +208,7 @@ export const ProjectViewForm: React.FC<Props> = observer((props) => {
<Button variant="neutral-primary" size="sm" onClick={handleClose} tabIndex={4}> <Button variant="neutral-primary" size="sm" onClick={handleClose} tabIndex={4}>
Cancel Cancel
</Button> </Button>
<Button variant="primary" size="sm" type="submit" tabIndex={5}> <Button variant="primary" size="sm" type="submit" tabIndex={5} disabled={isSubmitting}>
{data {data
? isSubmitting ? isSubmitting
? "Updating View..." ? "Updating View..."

View File

@ -1,7 +1,6 @@
import { FC, Fragment } from "react"; import { FC, Fragment } from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
import { debounce } from "lodash";
// hooks // hooks
import { useProjectView } from "hooks/store"; import { useProjectView } from "hooks/store";
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
@ -33,9 +32,7 @@ export const CreateUpdateProjectViewModal: FC<Props> = observer((props) => {
const handleCreateView = async (payload: IProjectView) => { const handleCreateView = async (payload: IProjectView) => {
await createView(workspaceSlug, projectId, payload) await createView(workspaceSlug, projectId, payload)
.then(() => { .then(() => {
// console.log("after calling store");
handleClose(); handleClose();
// console.log("after closing");
setToastAlert({ setToastAlert({
type: "success", type: "success",
title: "Success!", title: "Success!",
@ -68,8 +65,6 @@ export const CreateUpdateProjectViewModal: FC<Props> = observer((props) => {
else await handleUpdateView(formData); else await handleUpdateView(formData);
}; };
const debouncedFormSubmit = debounce(handleFormSubmit, 10, { leading: false, trailing: true });
return ( return (
<Transition.Root show={isOpen} as={Fragment}> <Transition.Root show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-20" onClose={handleClose}> <Dialog as="div" className="relative z-20" onClose={handleClose}>
@ -100,7 +95,7 @@ export const CreateUpdateProjectViewModal: FC<Props> = observer((props) => {
<ProjectViewForm <ProjectViewForm
data={data} data={data}
handleClose={handleClose} handleClose={handleClose}
handleFormSubmit={debouncedFormSubmit as (formData: IProjectView) => Promise<void>} handleFormSubmit={handleFormSubmit}
preLoadedData={preLoadedData} preLoadedData={preLoadedData}
/> />
</Dialog.Panel> </Dialog.Panel>

View File

@ -1,4 +1,4 @@
import { omit, set } from "lodash"; import { set } from "lodash";
import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { observable, action, makeObservable, runInAction, computed } from "mobx";
// services // services
import { ViewService } from "services/view.service"; import { ViewService } from "services/view.service";
@ -163,7 +163,7 @@ export class ProjectViewStore implements IProjectViewStore {
deleteView = async (workspaceSlug: string, projectId: string, viewId: string): Promise<any> => { deleteView = async (workspaceSlug: string, projectId: string, viewId: string): Promise<any> => {
await this.viewService.deleteView(workspaceSlug, projectId, viewId).then(() => { await this.viewService.deleteView(workspaceSlug, projectId, viewId).then(() => {
runInAction(() => { runInAction(() => {
omit(this.viewMap, [viewId]); delete this.viewMap[viewId];
}); });
}); });
}; };