import { Dispatch, MouseEvent, SetStateAction, useRef } from "react"; import { observer } from "mobx-react-lite"; import { ChevronRight } from "lucide-react"; // types import { TIssue, IIssueDisplayProperties, TIssueMap } from "@plane/types"; // ui import { Spinner, Tooltip, ControlLink } from "@plane/ui"; // components import { IssueProperties } from "@/components/issues/issue-layouts/properties"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { useApplication, useIssueDetail, useProject } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; // types import { TRenderQuickActions } from "./list-view-types"; interface IssueBlockProps { issueId: string; issuesMap: TIssueMap; updateIssue: ((projectId: string, issueId: string, data: Partial) => Promise) | undefined; quickActions: TRenderQuickActions; displayProperties: IIssueDisplayProperties | undefined; canEditProperties: (projectId: string | undefined) => boolean; nestingLevel: number; spacingLeft?: number; isExpanded: boolean; setExpanded: Dispatch>; } export const IssueBlock: React.FC = observer((props: IssueBlockProps) => { const { issuesMap, issueId, updateIssue, quickActions, displayProperties, canEditProperties, nestingLevel, spacingLeft = 14, isExpanded, setExpanded, } = props; // refs const parentRef = useRef(null); // hooks const { router: { workspaceSlug }, } = useApplication(); // store hooks const { getProjectIdentifierById } = useProject(); const { getIsIssuePeeked, setPeekIssue, subIssues: subIssuesStore } = useIssueDetail(); const handleIssuePeekOverview = (issue: TIssue) => workspaceSlug && issue && issue.project_id && issue.id && !getIsIssuePeeked(issue.id) && setPeekIssue({ workspaceSlug, projectId: issue.project_id, issueId: issue.id }); const issue = issuesMap[issueId]; const { isMobile } = usePlatformOS(); if (!issue) return null; const canEditIssueProperties = canEditProperties(issue.project_id); const projectIdentifier = getProjectIdentifierById(issue.project_id); const paddingLeft = `${spacingLeft}px`; const handleToggleExpand = (e: MouseEvent) => { e.stopPropagation(); e.preventDefault(); if (nestingLevel >= 3) { handleIssuePeekOverview(issue); } else { setExpanded((prevState) => { if (!prevState && workspaceSlug && issue) subIssuesStore.fetchSubIssues(workspaceSlug.toString(), issue.project_id, issue.id); return !prevState; }); } }; return (
{issue.sub_issues_count > 0 && ( )}
{displayProperties && displayProperties?.key && (
{projectIdentifier}-{issue.sequence_id}
)} {issue?.tempId !== undefined && (
)}
{issue?.is_draft ? (

{issue.name}

) : ( handleIssuePeekOverview(issue)} className="w-full truncate cursor-pointer text-sm text-custom-text-100" disabled={!!issue?.tempId} >

{issue.name}

)}
{!issue?.tempId && (
{quickActions({ issue, parentRef, })}
)}
{!issue?.tempId ? ( <>
{quickActions({ issue, parentRef, })}
) : (
)}
); });