2023-08-11 10:29:13 +00:00
|
|
|
import { FC } from "react";
|
2024-02-23 13:40:45 +00:00
|
|
|
// components
|
2024-03-06 13:09:14 +00:00
|
|
|
import { HEADER_HEIGHT } from "../constants";
|
|
|
|
import { IBlockUpdateData, IGanttBlock } from "../types";
|
2024-02-23 13:40:45 +00:00
|
|
|
import { GanttChartBlock } from "./block";
|
2023-08-11 10:29:13 +00:00
|
|
|
// types
|
2024-02-12 09:38:17 +00:00
|
|
|
// constants
|
2023-08-11 10:29:13 +00:00
|
|
|
|
2023-12-10 10:18:10 +00:00
|
|
|
export type GanttChartBlocksProps = {
|
2023-08-11 10:29:13 +00:00
|
|
|
itemsContainerWidth: number;
|
|
|
|
blocks: IGanttBlock[] | null;
|
2023-11-02 10:32:34 +00:00
|
|
|
blockToRender: (data: any) => React.ReactNode;
|
2023-08-11 10:29:13 +00:00
|
|
|
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
|
2023-08-28 07:55:47 +00:00
|
|
|
enableBlockLeftResize: boolean;
|
|
|
|
enableBlockRightResize: boolean;
|
|
|
|
enableBlockMove: boolean;
|
2024-02-12 13:40:07 +00:00
|
|
|
enableAddBlock: boolean;
|
2024-02-23 13:40:45 +00:00
|
|
|
ganttContainerRef: React.RefObject<HTMLDivElement>;
|
2024-01-30 08:55:15 +00:00
|
|
|
showAllBlocks: boolean;
|
2023-12-10 10:18:10 +00:00
|
|
|
};
|
|
|
|
|
2024-02-23 13:40:45 +00:00
|
|
|
export const GanttChartBlocksList: FC<GanttChartBlocksProps> = (props) => {
|
2023-12-10 10:18:10 +00:00
|
|
|
const {
|
|
|
|
itemsContainerWidth,
|
|
|
|
blocks,
|
|
|
|
blockToRender,
|
|
|
|
blockUpdateHandler,
|
|
|
|
enableBlockLeftResize,
|
|
|
|
enableBlockRightResize,
|
|
|
|
enableBlockMove,
|
2024-02-12 13:40:07 +00:00
|
|
|
enableAddBlock,
|
2024-02-23 13:40:45 +00:00
|
|
|
ganttContainerRef,
|
2024-01-30 08:55:15 +00:00
|
|
|
showAllBlocks,
|
2023-12-10 10:18:10 +00:00
|
|
|
} = props;
|
2023-08-11 10:29:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2024-02-12 09:38:17 +00:00
|
|
|
className="h-full"
|
|
|
|
style={{
|
|
|
|
width: `${itemsContainerWidth}px`,
|
2024-02-13 09:03:24 +00:00
|
|
|
transform: `translateY(${HEADER_HEIGHT}px)`,
|
2024-02-12 09:38:17 +00:00
|
|
|
}}
|
2023-08-11 10:29:13 +00:00
|
|
|
>
|
2024-02-12 09:38:17 +00:00
|
|
|
{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;
|
2024-01-30 08:55:15 +00:00
|
|
|
|
2024-02-12 09:38:17 +00:00
|
|
|
return (
|
2024-02-23 13:40:45 +00:00
|
|
|
<GanttChartBlock
|
2024-03-06 13:09:14 +00:00
|
|
|
key={block.id}
|
2024-02-23 13:40:45 +00:00
|
|
|
block={block}
|
|
|
|
blockToRender={blockToRender}
|
|
|
|
blockUpdateHandler={blockUpdateHandler}
|
|
|
|
enableBlockLeftResize={enableBlockLeftResize}
|
|
|
|
enableBlockRightResize={enableBlockRightResize}
|
|
|
|
enableBlockMove={enableBlockMove}
|
|
|
|
enableAddBlock={enableAddBlock}
|
|
|
|
ganttContainerRef={ganttContainerRef}
|
|
|
|
/>
|
2024-02-12 09:38:17 +00:00
|
|
|
);
|
|
|
|
})}
|
2023-08-11 10:29:13 +00:00
|
|
|
</div>
|
|
|
|
);
|
2024-02-23 13:40:45 +00:00
|
|
|
};
|