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";
|
2024-06-04 05:42:24 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IGanttBlock, IBlockUpdateData } from "@/components/gantt-chart/types";
|
2024-06-04 05:42:24 +00:00
|
|
|
// hooks
|
|
|
|
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
2024-05-08 08:08:58 +00:00
|
|
|
import { GanttDnDHOC } from "../gantt-dnd-HOC";
|
|
|
|
import { handleOrderChange } from "../utils";
|
2024-06-04 05:42:24 +00:00
|
|
|
// types
|
2024-03-06 13:09:14 +00:00
|
|
|
import { IssuesSidebarBlock } from "./block";
|
2024-02-23 13:40:45 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void;
|
|
|
|
blocks: IGanttBlock[] | null;
|
|
|
|
enableReorder: boolean;
|
2024-06-04 05:42:24 +00:00
|
|
|
enableSelection: boolean;
|
2024-02-23 13:40:45 +00:00
|
|
|
showAllBlocks?: boolean;
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers?: TSelectionHelper;
|
2024-02-23 13:40:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const IssueGanttSidebar: React.FC<Props> = (props) => {
|
2024-06-04 05:42:24 +00:00
|
|
|
const { blockUpdateHandler, blocks, enableReorder, enableSelection, showAllBlocks = false, selectionHelpers } = props;
|
2024-02-23 13:40:45 +00:00
|
|
|
|
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>
|
|
|
|
{blocks ? (
|
|
|
|
blocks.map((block, index) => {
|
|
|
|
const isBlockVisibleOnSidebar = block.start_date && block.target_date;
|
2024-02-23 13:40:45 +00:00
|
|
|
|
2024-05-08 08:08:58 +00:00
|
|
|
// hide the block if it doesn't have start and target dates and showAllBlocks is false
|
|
|
|
if (!showAllBlocks && !isBlockVisibleOnSidebar) return;
|
2024-02-23 13:40:45 +00:00
|
|
|
|
2024-05-08 08:08:58 +00:00
|
|
|
return (
|
|
|
|
<GanttDnDHOC
|
|
|
|
key={block.id}
|
|
|
|
id={block.id}
|
|
|
|
isLastChild={index === blocks.length - 1}
|
|
|
|
isDragEnabled={enableReorder}
|
|
|
|
onDrop={handleOnDrop}
|
|
|
|
>
|
|
|
|
{(isDragging: boolean, dragHandleRef: MutableRefObject<HTMLButtonElement | null>) => (
|
|
|
|
<IssuesSidebarBlock
|
|
|
|
block={block}
|
|
|
|
enableReorder={enableReorder}
|
2024-06-04 05:42:24 +00:00
|
|
|
enableSelection={enableSelection}
|
2024-05-08 08:08:58 +00:00
|
|
|
isDragging={isDragging}
|
|
|
|
dragHandleRef={dragHandleRef}
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers={selectionHelpers}
|
2024-05-08 08:08:58 +00:00
|
|
|
/>
|
2024-02-23 13:40:45 +00:00
|
|
|
)}
|
2024-05-08 08:08:58 +00:00
|
|
|
</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
|
|
|
);
|
|
|
|
};
|