2024-05-08 08:08:58 +00:00
|
|
|
import { MutableRefObject } from "react";
|
2024-02-23 13:40:45 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import { MoreVertical } from "lucide-react";
|
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { BLOCK_HEIGHT } from "@/components/gantt-chart/constants";
|
|
|
|
import { useGanttChart } from "@/components/gantt-chart/hooks";
|
2024-02-23 13:40:45 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IGanttBlock } from "@/components/gantt-chart/types";
|
|
|
|
import { ModuleGanttSidebarBlock } from "@/components/modules";
|
2024-02-23 13:40:45 +00:00
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { cn } from "@/helpers/common.helper";
|
|
|
|
import { findTotalDaysInRange } from "@/helpers/date-time.helper";
|
2024-02-23 13:40:45 +00:00
|
|
|
// types
|
|
|
|
// constants
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
block: IGanttBlock;
|
|
|
|
enableReorder: boolean;
|
2024-05-08 08:08:58 +00:00
|
|
|
isDragging: boolean;
|
|
|
|
dragHandleRef: MutableRefObject<HTMLButtonElement | null>;
|
2024-02-23 13:40:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const ModulesSidebarBlock: React.FC<Props> = observer((props) => {
|
2024-05-08 08:08:58 +00:00
|
|
|
const { block, enableReorder, isDragging, dragHandleRef } = props;
|
2024-02-23 13:40:45 +00:00
|
|
|
// store hooks
|
|
|
|
const { updateActiveBlockId, isBlockActive } = useGanttChart();
|
|
|
|
|
|
|
|
const duration = findTotalDaysInRange(block.start_date, block.target_date);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={cn({
|
2024-05-08 08:08:58 +00:00
|
|
|
"rounded bg-custom-background-80": isDragging,
|
2024-02-23 13:40:45 +00:00
|
|
|
})}
|
|
|
|
onMouseEnter={() => updateActiveBlockId(block.id)}
|
|
|
|
onMouseLeave={() => updateActiveBlockId(null)}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
id={`sidebar-block-${block.id}`}
|
|
|
|
className={cn("group w-full flex items-center gap-2 pl-2 pr-4", {
|
|
|
|
"bg-custom-background-80": isBlockActive(block.id),
|
|
|
|
})}
|
|
|
|
style={{
|
|
|
|
height: `${BLOCK_HEIGHT}px`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{enableReorder && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex flex-shrink-0 rounded p-0.5 text-custom-sidebar-text-200 opacity-0 group-hover:opacity-100"
|
2024-05-08 08:08:58 +00:00
|
|
|
ref={dragHandleRef}
|
2024-02-23 13:40:45 +00:00
|
|
|
>
|
|
|
|
<MoreVertical className="h-3.5 w-3.5" />
|
|
|
|
<MoreVertical className="-ml-5 h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<div className="flex h-full flex-grow items-center justify-between gap-2 truncate">
|
|
|
|
<div className="flex-grow truncate">
|
|
|
|
<ModuleGanttSidebarBlock moduleId={block.data.id} />
|
|
|
|
</div>
|
|
|
|
{duration !== undefined && (
|
|
|
|
<div className="flex-shrink-0 text-sm text-custom-text-200">
|
|
|
|
{duration} day{duration > 1 ? "s" : ""}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|