2024-02-23 13:40:45 +00:00
|
|
|
import { useRef } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
|
|
|
// hooks
|
|
|
|
import { useGanttChart } from "../hooks/use-gantt-chart";
|
2024-02-12 09:38:17 +00:00
|
|
|
// components
|
|
|
|
import {
|
|
|
|
BiWeekChartView,
|
|
|
|
DayChartView,
|
|
|
|
GanttChartBlocksList,
|
|
|
|
GanttChartSidebar,
|
|
|
|
HourChartView,
|
|
|
|
IBlockUpdateData,
|
|
|
|
IGanttBlock,
|
|
|
|
MonthChartView,
|
|
|
|
QuarterChartView,
|
|
|
|
TGanttViews,
|
|
|
|
WeekChartView,
|
|
|
|
YearChartView,
|
|
|
|
} from "components/gantt-chart";
|
|
|
|
// helpers
|
|
|
|
import { cn } from "helpers/common.helper";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
blocks: IGanttBlock[] | null;
|
|
|
|
blockToRender: (data: any) => React.ReactNode;
|
|
|
|
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
|
|
|
|
bottomSpacing: boolean;
|
|
|
|
chartBlocks: IGanttBlock[] | null;
|
|
|
|
enableBlockLeftResize: boolean;
|
|
|
|
enableBlockMove: boolean;
|
|
|
|
enableBlockRightResize: boolean;
|
|
|
|
enableReorder: boolean;
|
2024-02-12 13:40:07 +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 {
|
|
|
|
blocks,
|
|
|
|
blockToRender,
|
|
|
|
blockUpdateHandler,
|
|
|
|
bottomSpacing,
|
|
|
|
chartBlocks,
|
|
|
|
enableBlockLeftResize,
|
|
|
|
enableBlockMove,
|
|
|
|
enableBlockRightResize,
|
|
|
|
enableReorder,
|
2024-02-12 13:40:07 +00:00
|
|
|
enableAddBlock,
|
2024-02-12 09:38:17 +00:00
|
|
|
itemsContainerWidth,
|
|
|
|
showAllBlocks,
|
|
|
|
sidebarToRender,
|
|
|
|
title,
|
|
|
|
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-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 (
|
|
|
|
<div
|
|
|
|
// DO NOT REMOVE THE ID
|
|
|
|
id="gantt-container"
|
|
|
|
className={cn(
|
2024-02-21 12:22:35 +00:00
|
|
|
"h-full w-full overflow-auto vertical-scrollbar horizontal-scrollbar scrollbar-lg flex border-t-[0.5px] border-custom-border-200",
|
2024-02-12 09:38:17 +00:00
|
|
|
{
|
|
|
|
"mb-8": bottomSpacing,
|
|
|
|
}
|
|
|
|
)}
|
2024-02-23 13:40:45 +00:00
|
|
|
ref={ganttContainerRef}
|
2024-02-12 09:38:17 +00:00
|
|
|
onScroll={onScroll}
|
|
|
|
>
|
|
|
|
<GanttChartSidebar
|
|
|
|
blocks={blocks}
|
|
|
|
blockUpdateHandler={blockUpdateHandler}
|
|
|
|
enableReorder={enableReorder}
|
|
|
|
sidebarToRender={sidebarToRender}
|
|
|
|
title={title}
|
2024-02-14 12:45:13 +00:00
|
|
|
quickAdd={quickAdd}
|
2024-02-12 09:38:17 +00:00
|
|
|
/>
|
2024-02-24 10:15:17 +00:00
|
|
|
<div className="relative min-h-full h-max flex-shrink-0 flex-grow">
|
2024-02-12 09:38:17 +00:00
|
|
|
<ActiveChartView />
|
|
|
|
{currentViewData && (
|
|
|
|
<GanttChartBlocksList
|
|
|
|
itemsContainerWidth={itemsContainerWidth}
|
|
|
|
blocks={chartBlocks}
|
|
|
|
blockToRender={blockToRender}
|
|
|
|
blockUpdateHandler={blockUpdateHandler}
|
|
|
|
enableBlockLeftResize={enableBlockLeftResize}
|
|
|
|
enableBlockRightResize={enableBlockRightResize}
|
|
|
|
enableBlockMove={enableBlockMove}
|
2024-02-12 13:40:07 +00:00
|
|
|
enableAddBlock={enableAddBlock}
|
2024-02-23 13:40:45 +00:00
|
|
|
ganttContainerRef={ganttContainerRef}
|
2024-02-12 09:38:17 +00:00
|
|
|
showAllBlocks={showAllBlocks}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2024-02-23 13:40:45 +00:00
|
|
|
});
|