2024-05-08 08:08:58 +00:00
|
|
|
import React, { MutableRefObject } from "react";
|
2024-02-23 13:40:45 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import { MoreVertical } from "lucide-react";
|
|
|
|
// components
|
2024-06-04 05:42:24 +00:00
|
|
|
import { MultipleSelectEntityAction } from "@/components/core";
|
|
|
|
import { useGanttChart } from "@/components/gantt-chart/hooks";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IssueGanttSidebarBlock } from "@/components/issues";
|
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-06-04 05:42:24 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useIssueDetail } from "@/hooks/store";
|
2024-06-04 05:42:24 +00:00
|
|
|
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
2024-02-23 13:40:45 +00:00
|
|
|
// constants
|
2024-06-04 05:42:24 +00:00
|
|
|
import { BLOCK_HEIGHT, GANTT_SELECT_GROUP } from "../../constants";
|
|
|
|
// types
|
2024-03-06 13:09:14 +00:00
|
|
|
import { IGanttBlock } from "../../types";
|
2024-02-23 13:40:45 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
block: IGanttBlock;
|
|
|
|
enableReorder: boolean;
|
2024-06-04 05:42:24 +00:00
|
|
|
enableSelection: boolean;
|
2024-05-08 08:08:58 +00:00
|
|
|
isDragging: boolean;
|
|
|
|
dragHandleRef: MutableRefObject<HTMLButtonElement | null>;
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers?: TSelectionHelper;
|
2024-02-23 13:40:45 +00:00
|
|
|
};
|
|
|
|
|
2024-05-08 08:08:58 +00:00
|
|
|
export const IssuesSidebarBlock = observer((props: Props) => {
|
2024-06-04 05:42:24 +00:00
|
|
|
const { block, enableReorder, enableSelection, isDragging, dragHandleRef, selectionHelpers } = props;
|
2024-02-23 13:40:45 +00:00
|
|
|
// store hooks
|
|
|
|
const { updateActiveBlockId, isBlockActive } = useGanttChart();
|
2024-04-30 11:50:02 +00:00
|
|
|
const { getIsIssuePeeked } = useIssueDetail();
|
2024-02-23 13:40:45 +00:00
|
|
|
|
|
|
|
const duration = findTotalDaysInRange(block.start_date, block.target_date);
|
|
|
|
|
2024-06-04 05:42:24 +00:00
|
|
|
const isIssueSelected = selectionHelpers?.getIsEntitySelected(block.id);
|
|
|
|
const isIssueFocused = selectionHelpers?.getIsEntityActive(block.id);
|
|
|
|
const isBlockHoveredOn = isBlockActive(block.id);
|
|
|
|
|
2024-02-23 13:40:45 +00:00
|
|
|
return (
|
|
|
|
<div
|
2024-06-04 05:42:24 +00:00
|
|
|
className={cn("group/list-block", {
|
2024-05-08 08:08:58 +00:00
|
|
|
"rounded bg-custom-background-80": isDragging,
|
2024-06-04 05:42:24 +00:00
|
|
|
"rounded-l border border-r-0 border-custom-primary-70": getIsIssuePeeked(block.data.id),
|
|
|
|
"border border-r-0 border-custom-border-400": isIssueFocused,
|
2024-02-23 13:40:45 +00:00
|
|
|
})}
|
|
|
|
onMouseEnter={() => updateActiveBlockId(block.id)}
|
|
|
|
onMouseLeave={() => updateActiveBlockId(null)}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={cn("group w-full flex items-center gap-2 pl-2 pr-4", {
|
2024-06-04 05:42:24 +00:00
|
|
|
"bg-custom-background-90": isBlockHoveredOn,
|
|
|
|
"bg-custom-primary-100/5 hover:bg-custom-primary-100/10": isIssueSelected,
|
|
|
|
"bg-custom-primary-100/10": isIssueSelected && isBlockHoveredOn,
|
2024-02-23 13:40:45 +00:00
|
|
|
})}
|
|
|
|
style={{
|
|
|
|
height: `${BLOCK_HEIGHT}px`,
|
|
|
|
}}
|
|
|
|
>
|
2024-06-04 05:42:24 +00:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
{enableReorder && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex flex-shrink-0 rounded p-0.5 text-custom-sidebar-text-200 opacity-0 group-hover:opacity-100"
|
|
|
|
ref={dragHandleRef}
|
|
|
|
>
|
|
|
|
<MoreVertical className="h-3.5 w-3.5" />
|
|
|
|
<MoreVertical className="-ml-5 h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{enableSelection && selectionHelpers && (
|
|
|
|
<MultipleSelectEntityAction
|
|
|
|
className={cn(
|
|
|
|
"opacity-0 pointer-events-none group-hover/list-block:opacity-100 group-hover/list-block:pointer-events-auto transition-opacity",
|
|
|
|
{
|
|
|
|
"opacity-100 pointer-events-auto": isIssueSelected,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
groupId={GANTT_SELECT_GROUP}
|
|
|
|
id={block.id}
|
|
|
|
selectionHelpers={selectionHelpers}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-02-23 13:40:45 +00:00
|
|
|
<div className="flex h-full flex-grow items-center justify-between gap-2 truncate">
|
|
|
|
<div className="flex-grow truncate">
|
|
|
|
<IssueGanttSidebarBlock issueId={block.data.id} />
|
|
|
|
</div>
|
|
|
|
{duration && (
|
|
|
|
<div className="flex-shrink-0 text-sm text-custom-text-200">
|
|
|
|
<span>
|
|
|
|
{duration} day{duration > 1 ? "s" : ""}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|