2023-11-23 09:17:04 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-29 08:55:57 +00:00
|
|
|
// mobx store
|
2023-11-23 09:17:04 +00:00
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// components
|
2023-11-29 08:55:57 +00:00
|
|
|
import { IssueGanttBlock, IssuePeekOverview } from "components/issues";
|
2023-11-23 09:17:04 +00:00
|
|
|
import {
|
|
|
|
GanttChartRoot,
|
|
|
|
IBlockUpdateData,
|
|
|
|
renderIssueBlocksStructure,
|
|
|
|
IssueGanttSidebar,
|
|
|
|
} from "components/gantt-chart";
|
|
|
|
// types
|
|
|
|
import { IIssueUnGroupedStructure } from "store/issue";
|
|
|
|
import { IIssue } from "types";
|
|
|
|
import {
|
|
|
|
ICycleIssuesFilterStore,
|
|
|
|
ICycleIssuesStore,
|
|
|
|
IModuleIssuesFilterStore,
|
|
|
|
IModuleIssuesStore,
|
|
|
|
IProjectIssuesFilterStore,
|
|
|
|
IProjectIssuesStore,
|
|
|
|
IViewIssuesFilterStore,
|
|
|
|
IViewIssuesStore,
|
|
|
|
} from "store/issues";
|
|
|
|
import { TUnGroupedIssues } from "store/issues/types";
|
2023-12-04 14:33:23 +00:00
|
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
2023-11-23 09:17:04 +00:00
|
|
|
|
|
|
|
interface IBaseGanttRoot {
|
|
|
|
issueFiltersStore:
|
|
|
|
| IProjectIssuesFilterStore
|
|
|
|
| IModuleIssuesFilterStore
|
|
|
|
| ICycleIssuesFilterStore
|
|
|
|
| IViewIssuesFilterStore;
|
|
|
|
issueStore: IProjectIssuesStore | IModuleIssuesStore | ICycleIssuesStore | IViewIssuesStore;
|
|
|
|
viewId?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const BaseGanttRoot: React.FC<IBaseGanttRoot> = observer((props: IBaseGanttRoot) => {
|
|
|
|
const { issueFiltersStore, issueStore, viewId } = props;
|
|
|
|
|
|
|
|
const router = useRouter();
|
2023-11-29 08:55:57 +00:00
|
|
|
const { workspaceSlug, peekIssueId, peekProjectId } = router.query;
|
2023-11-23 09:17:04 +00:00
|
|
|
|
2023-11-28 11:35:42 +00:00
|
|
|
const {
|
|
|
|
user: { currentProjectRole },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
2023-11-23 09:17:04 +00:00
|
|
|
const appliedDisplayFilters = issueFiltersStore.issueFilters?.displayFilters;
|
|
|
|
|
|
|
|
const issuesResponse = issueStore.getIssues;
|
|
|
|
const issueIds = (issueStore.getIssuesIds ?? []) as TUnGroupedIssues;
|
|
|
|
|
|
|
|
const issues = issueIds.map((id) => issuesResponse?.[id]);
|
|
|
|
|
|
|
|
const updateIssue = (issue: IIssue, payload: IBlockUpdateData) => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
|
|
|
//Todo fix sort order in the structure
|
2023-11-27 08:45:33 +00:00
|
|
|
issueStore.updateIssue(
|
2023-11-29 08:55:57 +00:00
|
|
|
workspaceSlug.toString(),
|
2023-11-27 08:45:33 +00:00
|
|
|
issue.project,
|
|
|
|
issue.id,
|
|
|
|
{
|
|
|
|
start_date: payload.start_date,
|
|
|
|
target_date: payload.target_date,
|
|
|
|
},
|
|
|
|
viewId
|
|
|
|
);
|
2023-11-23 09:17:04 +00:00
|
|
|
};
|
|
|
|
|
2023-12-04 14:33:23 +00:00
|
|
|
const isAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER;
|
2023-11-23 09:17:04 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="w-full h-full">
|
|
|
|
<GanttChartRoot
|
|
|
|
border={false}
|
|
|
|
title="Issues"
|
|
|
|
loaderTitle="Issues"
|
|
|
|
blocks={issues ? renderIssueBlocksStructure(issues as IIssueUnGroupedStructure) : null}
|
|
|
|
blockUpdateHandler={updateIssue}
|
2023-11-29 08:55:57 +00:00
|
|
|
blockToRender={(data: IIssue) => <IssueGanttBlock data={data} />}
|
2023-11-23 09:17:04 +00:00
|
|
|
sidebarToRender={(props) => (
|
|
|
|
<IssueGanttSidebar
|
|
|
|
{...props}
|
|
|
|
quickAddCallback={issueStore.quickAddIssue}
|
|
|
|
viewId={viewId}
|
|
|
|
enableQuickIssueCreate
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
enableBlockLeftResize={isAllowed}
|
|
|
|
enableBlockRightResize={isAllowed}
|
|
|
|
enableBlockMove={isAllowed}
|
|
|
|
enableReorder={appliedDisplayFilters?.order_by === "sort_order" && isAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-29 08:55:57 +00:00
|
|
|
{workspaceSlug && peekIssueId && peekProjectId && (
|
|
|
|
<IssuePeekOverview
|
|
|
|
workspaceSlug={workspaceSlug.toString()}
|
|
|
|
projectId={peekProjectId.toString()}
|
|
|
|
issueId={peekIssueId.toString()}
|
|
|
|
handleIssue={(issueToUpdate) => {
|
|
|
|
// TODO: update the logic here
|
|
|
|
updateIssue(issueToUpdate as IIssue, {});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2023-11-23 09:17:04 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|