"use client"; import { RefObject, MutableRefObject, useState } from "react"; import { observer } from "mobx-react"; // ui import { Loader } from "@plane/ui"; // components import { IGanttBlock, IBlockUpdateData } from "@/components/gantt-chart/types"; //hooks import { useIntersectionObserver } from "@/hooks/use-intersection-observer"; import { TSelectionHelper } from "@/hooks/use-multiple-select"; import { GanttDnDHOC } from "../gantt-dnd-HOC"; import { handleOrderChange } from "../utils"; // types import { IssuesSidebarBlock } from "./block"; type Props = { blockUpdateHandler: (block: any, payload: IBlockUpdateData) => void; getBlockById: (id: string) => IGanttBlock; canLoadMoreBlocks?: boolean; loadMoreBlocks?: () => void; ganttContainerRef: RefObject; blockIds: string[]; enableReorder: boolean; enableSelection: boolean; showAllBlocks?: boolean; selectionHelpers?: TSelectionHelper; }; export const IssueGanttSidebar: React.FC = observer((props) => { const { blockUpdateHandler, blockIds, getBlockById, enableReorder, enableSelection, loadMoreBlocks, canLoadMoreBlocks, ganttContainerRef, showAllBlocks = false, selectionHelpers } = props; const [intersectionElement, setIntersectionElement] = useState(null); useIntersectionObserver(ganttContainerRef, intersectionElement, loadMoreBlocks, "50% 0% 50% 0%"); const handleOnDrop = ( draggingBlockId: string | undefined, droppedBlockId: string | undefined, dropAtEndOfList: boolean ) => { handleOrderChange(draggingBlockId, droppedBlockId, dropAtEndOfList, blockIds, getBlockById, blockUpdateHandler); }; return (
{blockIds ? ( <> {blockIds.map((blockId, index) => { const block = getBlockById(blockId); const isBlockVisibleOnSidebar = block?.start_date && block?.target_date; // hide the block if it doesn't have start and target dates and showAllBlocks is false if (!block || (!showAllBlocks && !isBlockVisibleOnSidebar)) return; return ( {(isDragging: boolean, dragHandleRef: MutableRefObject) => ( )} ); })} {canLoadMoreBlocks && (
)} ) : ( )}
); });