2024-06-10 09:43:10 +00:00
|
|
|
"use client";
|
|
|
|
|
2024-05-21 10:55:57 +00:00
|
|
|
import React, { FC, MutableRefObject, useEffect, useRef, useState } from "react";
|
|
|
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
|
|
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
|
|
import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
|
2024-05-08 09:09:27 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import { IIssueDisplayProperties, TIssue, TIssueMap } from "@plane/types";
|
|
|
|
// components
|
2024-05-21 10:55:57 +00:00
|
|
|
import { DropIndicator } from "@plane/ui";
|
2024-05-08 09:09:27 +00:00
|
|
|
import RenderIfVisible from "@/components/core/render-if-visible-HOC";
|
|
|
|
import { IssueBlock } from "@/components/issues/issue-layouts/list";
|
|
|
|
// hooks
|
|
|
|
import { useIssueDetail } from "@/hooks/store";
|
2024-06-04 05:42:24 +00:00
|
|
|
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
2024-05-21 10:55:57 +00:00
|
|
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
2024-05-08 09:09:27 +00:00
|
|
|
// types
|
2024-05-21 10:55:57 +00:00
|
|
|
import { HIGHLIGHT_CLASS, getIssueBlockId } from "../utils";
|
2024-05-08 09:09:27 +00:00
|
|
|
import { TRenderQuickActions } from "./list-view-types";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issueIds: string[];
|
|
|
|
issueId: string;
|
|
|
|
issuesMap: TIssueMap;
|
|
|
|
updateIssue: ((projectId: string, issueId: string, data: Partial<TIssue>) => Promise<void>) | undefined;
|
|
|
|
quickActions: TRenderQuickActions;
|
|
|
|
canEditProperties: (projectId: string | undefined) => boolean;
|
|
|
|
displayProperties: IIssueDisplayProperties | undefined;
|
|
|
|
nestingLevel: number;
|
|
|
|
spacingLeft?: number;
|
|
|
|
containerRef: MutableRefObject<HTMLDivElement | null>;
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers: TSelectionHelper;
|
2024-05-21 10:55:57 +00:00
|
|
|
groupId: string;
|
|
|
|
isDragAllowed: boolean;
|
|
|
|
canDropOverIssue: boolean;
|
|
|
|
isParentIssueBeingDragged?: boolean;
|
|
|
|
isLastChild?: boolean;
|
2024-05-08 09:09:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const IssueBlockRoot: FC<Props> = observer((props) => {
|
|
|
|
const {
|
|
|
|
issueIds,
|
|
|
|
issueId,
|
|
|
|
issuesMap,
|
2024-05-21 10:55:57 +00:00
|
|
|
groupId,
|
2024-05-08 09:09:27 +00:00
|
|
|
updateIssue,
|
|
|
|
quickActions,
|
|
|
|
canEditProperties,
|
|
|
|
displayProperties,
|
|
|
|
nestingLevel,
|
|
|
|
spacingLeft = 14,
|
|
|
|
containerRef,
|
2024-05-21 10:55:57 +00:00
|
|
|
isDragAllowed,
|
|
|
|
canDropOverIssue,
|
|
|
|
isParentIssueBeingDragged = false,
|
|
|
|
isLastChild = false,
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers,
|
2024-05-08 09:09:27 +00:00
|
|
|
} = props;
|
|
|
|
// states
|
|
|
|
const [isExpanded, setExpanded] = useState<boolean>(false);
|
2024-05-21 10:55:57 +00:00
|
|
|
const [instruction, setInstruction] = useState<"DRAG_OVER" | "DRAG_BELOW" | undefined>(undefined);
|
|
|
|
const [isCurrentBlockDragging, setIsCurrentBlockDragging] = useState(false);
|
|
|
|
// ref
|
|
|
|
const issueBlockRef = useRef<HTMLDivElement | null>(null);
|
2024-05-08 09:09:27 +00:00
|
|
|
// store hooks
|
|
|
|
const { subIssues: subIssuesStore } = useIssueDetail();
|
|
|
|
|
2024-05-21 10:55:57 +00:00
|
|
|
const isSubIssue = nestingLevel !== 0;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const blockElement = issueBlockRef.current;
|
|
|
|
|
|
|
|
if (!blockElement) return;
|
|
|
|
|
|
|
|
return combine(
|
|
|
|
dropTargetForElements({
|
|
|
|
element: blockElement,
|
|
|
|
canDrop: ({ source }) => source?.data?.id !== issueId && !isSubIssue && canDropOverIssue,
|
|
|
|
getData: ({ input, element }) => {
|
|
|
|
const data = { id: issueId, type: "ISSUE" };
|
|
|
|
|
|
|
|
// attach instruction for last in list
|
|
|
|
return attachInstruction(data, {
|
|
|
|
input,
|
|
|
|
element,
|
|
|
|
currentLevel: 0,
|
|
|
|
indentPerLevel: 0,
|
|
|
|
mode: isLastChild ? "last-in-group" : "standard",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onDrag: ({ self }) => {
|
|
|
|
const extractedInstruction = extractInstruction(self?.data)?.type;
|
|
|
|
// check if the highlight is to be shown above or below
|
|
|
|
setInstruction(
|
|
|
|
extractedInstruction
|
|
|
|
? extractedInstruction === "reorder-below" && isLastChild
|
|
|
|
? "DRAG_BELOW"
|
|
|
|
: "DRAG_OVER"
|
|
|
|
: undefined
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onDragLeave: () => {
|
|
|
|
setInstruction(undefined);
|
|
|
|
},
|
|
|
|
onDrop: () => {
|
|
|
|
setInstruction(undefined);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}, [issueId, isLastChild, issueBlockRef, isSubIssue, canDropOverIssue, setInstruction]);
|
|
|
|
|
|
|
|
useOutsideClickDetector(issueBlockRef, () => {
|
|
|
|
issueBlockRef?.current?.classList?.remove(HIGHLIGHT_CLASS);
|
|
|
|
});
|
|
|
|
|
2024-05-08 09:09:27 +00:00
|
|
|
if (!issueId) return null;
|
|
|
|
|
|
|
|
const subIssues = subIssuesStore.subIssuesByIssueId(issueId);
|
|
|
|
return (
|
2024-05-21 10:55:57 +00:00
|
|
|
<div className="relative" ref={issueBlockRef} id={getIssueBlockId(issueId, groupId)}>
|
|
|
|
<DropIndicator classNames={"absolute top-0 z-[2]"} isVisible={instruction === "DRAG_OVER"} />
|
2024-05-08 09:09:27 +00:00
|
|
|
<RenderIfVisible
|
|
|
|
key={`${issueId}`}
|
|
|
|
defaultHeight="3rem"
|
|
|
|
root={containerRef}
|
2024-05-22 06:04:15 +00:00
|
|
|
classNames={`relative ${isLastChild && !isExpanded ? "" : "border-b border-b-custom-border-200"}`}
|
2024-05-08 09:09:27 +00:00
|
|
|
>
|
|
|
|
<IssueBlock
|
|
|
|
issueId={issueId}
|
|
|
|
issuesMap={issuesMap}
|
2024-05-21 10:55:57 +00:00
|
|
|
groupId={groupId}
|
2024-05-08 09:09:27 +00:00
|
|
|
updateIssue={updateIssue}
|
|
|
|
quickActions={quickActions}
|
|
|
|
canEditProperties={canEditProperties}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
isExpanded={isExpanded}
|
|
|
|
setExpanded={setExpanded}
|
|
|
|
nestingLevel={nestingLevel}
|
|
|
|
spacingLeft={spacingLeft}
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers={selectionHelpers}
|
2024-05-21 10:55:57 +00:00
|
|
|
canDrag={!isSubIssue && isDragAllowed}
|
|
|
|
isCurrentBlockDragging={isParentIssueBeingDragged || isCurrentBlockDragging}
|
|
|
|
setIsCurrentBlockDragging={setIsCurrentBlockDragging}
|
2024-05-08 09:09:27 +00:00
|
|
|
/>
|
|
|
|
</RenderIfVisible>
|
|
|
|
|
|
|
|
{isExpanded &&
|
2024-06-04 05:42:24 +00:00
|
|
|
subIssues?.map((subIssueId: string) => (
|
2024-05-08 09:09:27 +00:00
|
|
|
<IssueBlockRoot
|
|
|
|
key={`${subIssueId}`}
|
|
|
|
issueIds={issueIds}
|
|
|
|
issueId={subIssueId}
|
|
|
|
issuesMap={issuesMap}
|
|
|
|
updateIssue={updateIssue}
|
|
|
|
quickActions={quickActions}
|
|
|
|
canEditProperties={canEditProperties}
|
|
|
|
displayProperties={displayProperties}
|
|
|
|
nestingLevel={nestingLevel + 1}
|
2024-06-06 05:33:56 +00:00
|
|
|
spacingLeft={spacingLeft + 12}
|
2024-05-08 09:09:27 +00:00
|
|
|
containerRef={containerRef}
|
2024-06-04 05:42:24 +00:00
|
|
|
selectionHelpers={selectionHelpers}
|
2024-05-21 10:55:57 +00:00
|
|
|
groupId={groupId}
|
|
|
|
isDragAllowed={isDragAllowed}
|
|
|
|
canDropOverIssue={canDropOverIssue}
|
|
|
|
isParentIssueBeingDragged={isParentIssueBeingDragged || isCurrentBlockDragging}
|
2024-05-08 09:09:27 +00:00
|
|
|
/>
|
|
|
|
))}
|
2024-05-21 10:55:57 +00:00
|
|
|
{isLastChild && <DropIndicator classNames={"absolute z-[2]"} isVisible={instruction === "DRAG_BELOW"} />}
|
|
|
|
</div>
|
2024-05-08 09:09:27 +00:00
|
|
|
);
|
|
|
|
});
|