2024-05-08 08:08:58 +00:00
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
|
|
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
2024-02-23 13:40:45 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-02-12 09:38:17 +00:00
|
|
|
// components
|
2024-06-04 05:42:24 +00:00
|
|
|
import { MultipleSelectGroup } from "@/components/core";
|
2024-02-12 09:38:17 +00:00
|
|
|
import {
|
|
|
|
BiWeekChartView,
|
2024-06-10 14:45:03 +00:00
|
|
|
ChartDataType,
|
2024-02-12 09:38:17 +00:00
|
|
|
DayChartView,
|
|
|
|
GanttChartBlocksList,
|
|
|
|
GanttChartSidebar,
|
|
|
|
HourChartView,
|
|
|
|
IBlockUpdateData,
|
|
|
|
IGanttBlock,
|
|
|
|
MonthChartView,
|
|
|
|
QuarterChartView,
|
|
|
|
TGanttViews,
|
|
|
|
WeekChartView,
|
|
|
|
YearChartView,
|
2024-03-19 14:38:35 +00:00
|
|
|
} from "@/components/gantt-chart";
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-06-11 12:23:48 +00:00
|
|
|
// plane web components
|
|
|
|
import { IssueBulkOperationsRoot } from "@/plane-web/components/issues";
|
|
|
|
// plane web constants
|
|
|
|
import { ENABLE_BULK_OPERATIONS } from "@/plane-web/constants/issue";
|
|
|
|
// helpers
|
2024-06-04 05:42:24 +00:00
|
|
|
// constants
|
|
|
|
import { GANTT_SELECT_GROUP } from "../constants";
|
|
|
|
// hooks
|
2024-03-06 13:09:14 +00:00
|
|
|
import { useGanttChart } from "../hooks/use-gantt-chart";
|
2024-02-12 09:38:17 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-06-10 14:45:03 +00:00
|
|
|
blockIds: string[];
|
|
|
|
getBlockById: (id: string, currentViewData?: ChartDataType | undefined) => IGanttBlock;
|
|
|
|
canLoadMoreBlocks?: boolean;
|
|
|
|
loadMoreBlocks?: () => void;
|
2024-02-12 09:38:17 +00:00
|
|
|
blockToRender: (data: any) => React.ReactNode;
|
|
|
|
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
|
|
|
|
bottomSpacing: boolean;
|
|
|
|
enableBlockLeftResize: boolean;
|
|
|
|
enableBlockMove: boolean;
|
|
|
|
enableBlockRightResize: boolean;
|
|
|
|
enableReorder: boolean;
|
2024-06-04 05:42:24 +00:00
|
|
|
enableSelection: boolean;
|
2024-06-10 14:45:03 +00:00
|
|
|
enableAddBlock: boolean;
|
2024-02-12 09:38:17 +00:00
|
|
|
itemsContainerWidth: number;
|
|
|
|
showAllBlocks: boolean;
|
|
|
|
sidebarToRender: (props: any) => React.ReactNode;
|
|
|
|
title: string;
|
|
|
|
updateCurrentViewRenderPayload: (direction: "left" | "right", currentView: TGanttViews) => void;
|
2024-02-14 12:45:13 +00:00
|
|
|
quickAdd?: React.JSX.Element | undefined;
|
2024-02-12 09:38:17 +00:00
|
|
|
};
|
|
|
|
|
2024-02-23 13:40:45 +00:00
|
|
|
export const GanttChartMainContent: React.FC<Props> = observer((props) => {
|
2024-02-12 09:38:17 +00:00
|
|
|
const {
|
2024-06-10 14:45:03 +00:00
|
|
|
blockIds,
|
|
|
|
getBlockById,
|
|
|
|
loadMoreBlocks,
|
2024-02-12 09:38:17 +00:00
|
|
|
blockToRender,
|
|
|
|
blockUpdateHandler,
|
|
|
|
bottomSpacing,
|
|
|
|
enableBlockLeftResize,
|
|
|
|
enableBlockMove,
|
|
|
|
enableBlockRightResize,
|
|
|
|
enableReorder,
|
2024-02-12 13:40:07 +00:00
|
|
|
enableAddBlock,
|
2024-06-04 05:42:24 +00:00
|
|
|
enableSelection,
|
2024-02-12 09:38:17 +00:00
|
|
|
itemsContainerWidth,
|
|
|
|
showAllBlocks,
|
|
|
|
sidebarToRender,
|
|
|
|
title,
|
2024-06-10 14:45:03 +00:00
|
|
|
canLoadMoreBlocks,
|
2024-02-12 09:38:17 +00:00
|
|
|
updateCurrentViewRenderPayload,
|
2024-02-14 12:45:13 +00:00
|
|
|
quickAdd,
|
2024-02-12 09:38:17 +00:00
|
|
|
} = props;
|
2024-02-23 13:40:45 +00:00
|
|
|
// refs
|
|
|
|
const ganttContainerRef = useRef<HTMLDivElement>(null);
|
2024-02-12 09:38:17 +00:00
|
|
|
// chart hook
|
2024-02-23 13:40:45 +00:00
|
|
|
const { currentView, currentViewData } = useGanttChart();
|
2024-05-08 08:08:58 +00:00
|
|
|
|
|
|
|
// Enable Auto Scroll for Ganttlist
|
|
|
|
useEffect(() => {
|
|
|
|
const element = ganttContainerRef.current;
|
|
|
|
|
|
|
|
if (!element) return;
|
|
|
|
|
|
|
|
return combine(
|
|
|
|
autoScrollForElements({
|
|
|
|
element,
|
|
|
|
getAllowedAxis: () => "vertical",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}, [ganttContainerRef?.current]);
|
2024-02-12 09:38:17 +00:00
|
|
|
// handling scroll functionality
|
|
|
|
const onScroll = (e: React.UIEvent<HTMLDivElement, UIEvent>) => {
|
|
|
|
const { clientWidth, scrollLeft, scrollWidth } = e.currentTarget;
|
|
|
|
|
2024-02-23 13:40:45 +00:00
|
|
|
// updateScrollLeft(scrollLeft);
|
2024-02-12 09:38:17 +00:00
|
|
|
|
|
|
|
const approxRangeLeft = scrollLeft >= clientWidth + 1000 ? 1000 : scrollLeft - clientWidth;
|
|
|
|
const approxRangeRight = scrollWidth - (scrollLeft + clientWidth);
|
|
|
|
|
|
|
|
if (approxRangeRight < 1000) updateCurrentViewRenderPayload("right", currentView);
|
|
|
|
if (approxRangeLeft < 1000) updateCurrentViewRenderPayload("left", currentView);
|
|
|
|
};
|
|
|
|
|
|
|
|
const CHART_VIEW_COMPONENTS: {
|
|
|
|
[key in TGanttViews]: React.FC;
|
|
|
|
} = {
|
|
|
|
hours: HourChartView,
|
|
|
|
day: DayChartView,
|
|
|
|
week: WeekChartView,
|
|
|
|
bi_week: BiWeekChartView,
|
|
|
|
month: MonthChartView,
|
|
|
|
quarter: QuarterChartView,
|
|
|
|
year: YearChartView,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!currentView) return null;
|
|
|
|
const ActiveChartView = CHART_VIEW_COMPONENTS[currentView];
|
|
|
|
|
|
|
|
return (
|
2024-06-04 05:42:24 +00:00
|
|
|
<MultipleSelectGroup
|
|
|
|
containerRef={ganttContainerRef}
|
|
|
|
entities={{
|
2024-06-10 14:45:03 +00:00
|
|
|
[GANTT_SELECT_GROUP]: blockIds ?? [],
|
2024-06-04 05:42:24 +00:00
|
|
|
}}
|
2024-06-11 12:23:48 +00:00
|
|
|
disabled={!ENABLE_BULK_OPERATIONS}
|
2024-02-12 09:38:17 +00:00
|
|
|
>
|
2024-06-04 05:42:24 +00:00
|
|
|
{(helpers) => (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
// DO NOT REMOVE THE ID
|
|
|
|
id="gantt-container"
|
|
|
|
className={cn(
|
|
|
|
"h-full w-full overflow-auto vertical-scrollbar horizontal-scrollbar scrollbar-lg flex border-t-[0.5px] border-custom-border-200",
|
|
|
|
{
|
|
|
|
"mb-8": bottomSpacing,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
ref={ganttContainerRef}
|
|
|
|
onScroll={onScroll}
|
|
|
|
>
|
|
|
|
<GanttChartSidebar
|
2024-06-10 14:45:03 +00:00
|
|
|
blockIds={blockIds}
|
|
|
|
getBlockById={getBlockById}
|
|
|
|
loadMoreBlocks={loadMoreBlocks}
|
|
|
|
canLoadMoreBlocks={canLoadMoreBlocks}
|
|
|
|
ganttContainerRef={ganttContainerRef}
|
|
|
|
blockUpdateHandler={blockUpdateHandler}
|
|
|
|
enableReorder={enableReorder}
|
|
|
|
enableSelection={enableSelection}
|
|
|
|
sidebarToRender={sidebarToRender}
|
|
|
|
title={title}
|
|
|
|
quickAdd={quickAdd}
|
|
|
|
selectionHelpers={helpers}
|
|
|
|
/>
|
|
|
|
<div className="relative min-h-full h-max flex-shrink-0 flex-grow">
|
|
|
|
<ActiveChartView />
|
|
|
|
{currentViewData && (
|
|
|
|
<GanttChartBlocksList
|
|
|
|
itemsContainerWidth={itemsContainerWidth}
|
|
|
|
blockIds={blockIds}
|
|
|
|
getBlockById={getBlockById}
|
|
|
|
blockToRender={blockToRender}
|
|
|
|
blockUpdateHandler={blockUpdateHandler}
|
|
|
|
enableBlockLeftResize={enableBlockLeftResize}
|
|
|
|
enableBlockRightResize={enableBlockRightResize}
|
|
|
|
enableBlockMove={enableBlockMove}
|
|
|
|
enableAddBlock={enableAddBlock}
|
|
|
|
ganttContainerRef={ganttContainerRef}
|
|
|
|
showAllBlocks={showAllBlocks}
|
|
|
|
selectionHelpers={helpers}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-06-04 05:42:24 +00:00
|
|
|
</div>
|
2024-06-05 07:18:50 +00:00
|
|
|
<IssueBulkOperationsRoot selectionHelpers={helpers} />
|
2024-06-04 05:42:24 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</MultipleSelectGroup>
|
2024-02-12 09:38:17 +00:00
|
|
|
);
|
2024-02-23 13:40:45 +00:00
|
|
|
});
|