import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { X, CopyPlus } from "lucide-react"; // hooks import { useIssueDetail, useIssues, useProject, useUser } from "hooks/store"; import useToast from "hooks/use-toast"; // components import { ExistingIssuesListModal } from "components/core"; // icons import { BlockerIcon, BlockedIcon, RelatedIcon } from "@plane/ui"; // types import { TIssueRelationTypes, ISearchIssueResponse } from "@plane/types"; export type TRelationObject = { name: string; icon: (size: number) => any; className: string }; export const issueRelationObject: Record = { blocking: { name: "Blocking", icon: (size: number = 16) => , className: "text-yellow-500 duration-300 hover:border-yellow-500/20 hover:bg-yellow-500/20", }, blocked_by: { name: "Blocked by", icon: (size: number = 16) => , className: "border-custom-border-200 text-red-500 hover:border-red-500/20 hover:bg-red-500/20", }, duplicate: { name: "Duplicate", icon: (size: number = 16) => , className: "border-custom-border-200", }, relates_to: { name: "Relates to", icon: (size: number = 16) => , className: "border-custom-border-200", }, }; type TIssueRelationSelect = { workspaceSlug: string; projectId: string; issueId: string; relationKey: TIssueRelationTypes; disabled?: boolean; }; export const IssueRelationSelect: React.FC = observer((props) => { const { workspaceSlug, projectId, issueId, relationKey, disabled = false } = props; // hooks const { currentUser } = useUser(); const { getProjectById } = useProject(); const { createRelation, removeRelation, relation: { getRelationByIssueIdRelationType }, } = useIssueDetail(); const { issueMap } = useIssues(); // states const [isRelationModalOpen, setIsRelationModalOpen] = useState(false); // toast alert const { setToastAlert } = useToast(); const relationIssueIds = getRelationByIssueIdRelationType(issueId as string, relationKey); const onSubmit = async (data: ISearchIssueResponse[]) => { if (data.length === 0) { setToastAlert({ type: "error", title: "Error!", message: "Please select at least one issue.", }); return; } await createRelation( workspaceSlug as string, projectId as string, issueId as string, relationKey, data.map((i) => i.id) ); setIsRelationModalOpen(false); }; return ( <> setIsRelationModalOpen(false)} searchParams={{ issue_relation: true, issue_id: issueId }} handleOnSubmit={onSubmit} workspaceLevelToggle />
{relationKey && issueRelationObject[relationKey] && ( <> {issueRelationObject[relationKey].icon(16)}

{issueRelationObject[relationKey].name}

)}
{relationIssueIds && relationIssueIds.length > 0 ? relationIssueIds.map((relationIssueId: any) => { const currentIssue = issueMap[relationIssueId]; if (!currentIssue) return; const projectDetails = getProjectById(currentIssue.project_id); return (
{issueRelationObject[relationKey].icon(10)} {`${projectDetails?.identifier}-${currentIssue?.sequence_id}`} {!disabled && ( )}
); }) : null}
); });