diff --git a/web/components/gantt-chart/blocks/blocks-list.tsx b/web/components/gantt-chart/blocks/blocks-list.tsx index 8372d4ecc..8dc344cd0 100644 --- a/web/components/gantt-chart/blocks/blocks-list.tsx +++ b/web/components/gantt-chart/blocks/blocks-list.tsx @@ -1,4 +1,5 @@ -import { FC, useEffect, useRef } from "react"; +import { observer } from "mobx-react"; +import { FC } from "react"; // hooks import { useIssueDetail } from "hooks/store"; import { useChart } from "../hooks"; @@ -20,7 +21,7 @@ export type GanttChartBlocksProps = { showAllBlocks: boolean; }; -export const GanttChartBlocksList: FC = (props) => { +export const GanttChartBlocksList: FC = observer((props) => { const { itemsContainerWidth, blocks, @@ -31,12 +32,10 @@ export const GanttChartBlocksList: FC = (props) => { enableBlockMove, showAllBlocks, } = props; - // refs - const blocksContainerRef = useRef(null); // store hooks const { peekIssue } = useIssueDetail(); // chart hook - const { activeBlock, dispatch, scrollTop, updateScrollTop } = useChart(); + const { activeBlock, dispatch, updateScrollTop } = useChart(); // update the active block on hover const updateActiveBlock = (block: IGanttBlock | null) => { @@ -87,54 +86,44 @@ export const GanttChartBlocksList: FC = (props) => { sidebarScrollContainer.scrollTop = e.currentTarget.scrollTop; }; - useEffect(() => { - const blocksContainer = blocksContainerRef.current; - if (!blocksContainer) return; - - blocksContainer.scrollTop = scrollTop; - }, [scrollTop]); - return (
- {blocks && - blocks.length > 0 && - blocks.map((block) => { - // hide the block if it doesn't have start and target dates and showAllBlocks is false - if (!showAllBlocks && !(block.start_date && block.target_date)) return; + {blocks?.map((block) => { + // hide the block if it doesn't have start and target dates and showAllBlocks is false + if (!showAllBlocks && !(block.start_date && block.target_date)) return; - const isBlockVisibleOnChart = block.start_date && block.target_date; + const isBlockVisibleOnChart = block.start_date && block.target_date; - return ( -
updateActiveBlock(block)} - onMouseLeave={() => updateActiveBlock(null)} - > - {isBlockVisibleOnChart ? ( - handleChartBlockPosition(block, ...args)} - enableBlockLeftResize={enableBlockLeftResize} - enableBlockRightResize={enableBlockRightResize} - enableBlockMove={enableBlockMove} - /> - ) : ( - - )} -
- ); - })} + return ( +
updateActiveBlock(block)} + onMouseLeave={() => updateActiveBlock(null)} + > + {isBlockVisibleOnChart ? ( + handleChartBlockPosition(block, ...args)} + enableBlockLeftResize={enableBlockLeftResize} + enableBlockRightResize={enableBlockRightResize} + enableBlockMove={enableBlockMove} + /> + ) : ( + + )} +
+ ); + })}
); -}; +}); diff --git a/web/components/gantt-chart/chart/main-content.tsx b/web/components/gantt-chart/chart/main-content.tsx index 8d5f9d5fe..084e13da6 100644 --- a/web/components/gantt-chart/chart/main-content.tsx +++ b/web/components/gantt-chart/chart/main-content.tsx @@ -1,9 +1,9 @@ -import { useRef } from "react"; // components import { BiWeekChartView, DayChartView, GanttChartBlocksList, + GanttChartSidebar, HourChartView, IBlockUpdateData, IGanttBlock, @@ -51,16 +51,14 @@ export const GanttChartMainContent: React.FC = (props) => { title, updateCurrentViewRenderPayload, } = props; - // refs - const sidebarRef = useRef(null); // chart hook const { currentView, currentViewData, updateScrollLeft, updateScrollTop } = useChart(); - // handling scroll functionality const onScroll = (e: React.UIEvent) => { const { clientWidth: clientVisibleWidth, scrollLeft: currentLeftScrollPosition, scrollWidth } = e.currentTarget; updateScrollLeft(currentLeftScrollPosition); + updateScrollTop(e.currentTarget.scrollTop); const approxRangeLeft = scrollWidth >= clientVisibleWidth + 1000 ? 1000 : scrollWidth - clientVisibleWidth; const approxRangeRight = scrollWidth - (approxRangeLeft + clientVisibleWidth); @@ -69,8 +67,6 @@ export const GanttChartMainContent: React.FC = (props) => { if (currentLeftScrollPosition <= approxRangeLeft) updateCurrentViewRenderPayload("left", currentView); }; - const onSidebarScroll = (e: React.UIEvent) => updateScrollTop(e.currentTarget.scrollTop); - const CHART_VIEW_COMPONENTS: { [key in TGanttViews]: React.FC; } = { @@ -82,58 +78,45 @@ export const GanttChartMainContent: React.FC = (props) => { quarter: QuarterChartView, year: YearChartView, }; + + if (!currentView) return null; const ActiveChartView = CHART_VIEW_COMPONENTS[currentView]; return (
+
-
-
{title}
-
Duration
-
- -
- {sidebarToRender && sidebarToRender({ title, blockUpdateHandler, blocks, enableReorder })} -
+ + {currentViewData && ( + + )}
- {currentView && ( -
- - {/* blocks */} - {currentViewData && ( - - )} -
- )}
); }; diff --git a/web/components/gantt-chart/chart/views/month.tsx b/web/components/gantt-chart/chart/views/month.tsx index 0b605bfe2..afdb8b326 100644 --- a/web/components/gantt-chart/chart/views/month.tsx +++ b/web/components/gantt-chart/chart/views/month.tsx @@ -14,7 +14,7 @@ export const MonthChartView: FC = () => { return ( <> -
+
{monthBlocks?.map((block, rootIndex) => (
diff --git a/web/components/gantt-chart/sidebar/cycle-sidebar.tsx b/web/components/gantt-chart/sidebar/cycles.tsx similarity index 95% rename from web/components/gantt-chart/sidebar/cycle-sidebar.tsx rename to web/components/gantt-chart/sidebar/cycles.tsx index 1af1529c2..b0254e4f1 100644 --- a/web/components/gantt-chart/sidebar/cycle-sidebar.tsx +++ b/web/components/gantt-chart/sidebar/cycles.tsx @@ -1,4 +1,3 @@ -import { useRouter } from "next/router"; import { DragDropContext, Draggable, DropResult, Droppable } from "@hello-pangea/dnd"; import { MoreVertical } from "lucide-react"; // hooks @@ -20,12 +19,8 @@ type Props = { }; export const CycleGanttSidebar: React.FC = (props) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { title, blockUpdateHandler, blocks, enableReorder } = props; - - const router = useRouter(); - const { cycleId } = router.query; - + const { blockUpdateHandler, blocks, enableReorder } = props; + // chart hook const { activeBlock, dispatch } = useChart(); // update the active block on hover @@ -85,7 +80,6 @@ export const CycleGanttSidebar: React.FC = (props) => { {(droppableProvided) => (
= (props) => { +export const IssueGanttSidebar: React.FC = observer((props) => { const { blockUpdateHandler, blocks, @@ -101,7 +102,7 @@ export const IssueGanttSidebar: React.FC = (props) => { {(droppableProvided) => ( -
+
<> {blocks ? ( blocks.map((block, index) => { @@ -189,4 +190,4 @@ export const IssueGanttSidebar: React.FC = (props) => { ); -}; +}); diff --git a/web/components/gantt-chart/sidebar/module-sidebar.tsx b/web/components/gantt-chart/sidebar/modules.tsx similarity index 95% rename from web/components/gantt-chart/sidebar/module-sidebar.tsx rename to web/components/gantt-chart/sidebar/modules.tsx index 30f146dc5..58ca1ff6f 100644 --- a/web/components/gantt-chart/sidebar/module-sidebar.tsx +++ b/web/components/gantt-chart/sidebar/modules.tsx @@ -1,4 +1,3 @@ -import { useRouter } from "next/router"; import { DragDropContext, Draggable, Droppable, DropResult } from "@hello-pangea/dnd"; import { MoreVertical } from "lucide-react"; // hooks @@ -20,12 +19,8 @@ type Props = { }; export const ModuleGanttSidebar: React.FC = (props) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { title, blockUpdateHandler, blocks, enableReorder } = props; - - const router = useRouter(); - const { cycleId } = router.query; - + const { blockUpdateHandler, blocks, enableReorder } = props; + // chart hook const { activeBlock, dispatch } = useChart(); // update the active block on hover @@ -85,7 +80,6 @@ export const ModuleGanttSidebar: React.FC = (props) => { {(droppableProvided) => (
= (props) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { title, blockUpdateHandler, blocks, enableReorder } = props; - - const router = useRouter(); - const { cycleId } = router.query; - + const { blockUpdateHandler, blocks, enableReorder } = props; + // chart hook const { activeBlock, dispatch } = useChart(); // update the active block on hover @@ -86,7 +81,6 @@ export const ProjectViewGanttSidebar: React.FC = (props) => { {(droppableProvided) => (
void; + enableReorder: boolean; + sidebarToRender: (props: any) => React.ReactNode; + title: string; +}; + +export const GanttChartSidebar: React.FC = (props) => { + const { blocks, blockUpdateHandler, enableReorder, sidebarToRender, title } = props; + // refs + const sidebarRef = useRef(null); + // chart hook + const { updateScrollTop } = useChart(); + + const onSidebarScroll = (e: React.UIEvent) => updateScrollTop(e.currentTarget.scrollTop); + + return ( +
+
+
{title}
+
Duration
+
+ +
+ {sidebarToRender && sidebarToRender({ title, blockUpdateHandler, blocks, enableReorder })} +
+
+ ); +};