2024-05-08 08:08:58 +00:00
|
|
|
import { MutableRefObject } from "react";
|
2024-02-23 13:40:45 +00:00
|
|
|
// ui
|
|
|
|
import { Loader } from "@plane/ui";
|
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IBlockUpdateData, IGanttBlock } from "@/components/gantt-chart";
|
2024-05-08 08:08:58 +00:00
|
|
|
import { GanttDnDHOC } from "../gantt-dnd-HOC";
|
|
|
|
import { handleOrderChange } from "../utils";
|
2024-02-23 13:40:45 +00:00
|
|
|
import { ModulesSidebarBlock } from "./block";
|
|
|
|
// types
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
title: string;
|
|
|
|
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
|
|
|
|
blocks: IGanttBlock[] | null;
|
|
|
|
enableReorder: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ModuleGanttSidebar: React.FC<Props> = (props) => {
|
|
|
|
const { blockUpdateHandler, blocks, enableReorder } = props;
|
|
|
|
|
2024-05-08 08:08:58 +00:00
|
|
|
const handleOnDrop = (
|
|
|
|
draggingBlockId: string | undefined,
|
|
|
|
droppedBlockId: string | undefined,
|
|
|
|
dropAtEndOfList: boolean
|
|
|
|
) => {
|
|
|
|
handleOrderChange(draggingBlockId, droppedBlockId, dropAtEndOfList, blocks, blockUpdateHandler);
|
2024-02-23 13:40:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-05-08 08:08:58 +00:00
|
|
|
<div className="h-full">
|
|
|
|
{blocks ? (
|
|
|
|
blocks.map((block, index) => (
|
|
|
|
<GanttDnDHOC
|
|
|
|
key={block.id}
|
|
|
|
id={block.id}
|
|
|
|
isLastChild={index === blocks.length - 1}
|
|
|
|
isDragEnabled={enableReorder}
|
|
|
|
onDrop={handleOnDrop}
|
|
|
|
>
|
|
|
|
{(isDragging: boolean, dragHandleRef: MutableRefObject<HTMLButtonElement | null>) => (
|
|
|
|
<ModulesSidebarBlock
|
|
|
|
block={block}
|
|
|
|
enableReorder={enableReorder}
|
|
|
|
isDragging={isDragging}
|
|
|
|
dragHandleRef={dragHandleRef}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</GanttDnDHOC>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<Loader className="space-y-3 pr-2">
|
|
|
|
<Loader.Item height="34px" />
|
|
|
|
<Loader.Item height="34px" />
|
|
|
|
<Loader.Item height="34px" />
|
|
|
|
<Loader.Item height="34px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-02-23 13:40:45 +00:00
|
|
|
);
|
|
|
|
};
|