import { useRouter } from "next/router"; import React from "react"; import { ChevronDown, ChevronRight, X, Pencil, Trash, Link as LinkIcon, Loader } from "lucide-react"; // components import { SubIssuesRootList } from "./issues-list"; import { IssueProperty } from "./properties"; import { IssuePeekOverview } from "components/issues"; // ui import { CustomMenu, Tooltip } from "@plane/ui"; // types import { IUser, TIssue, TIssueSubIssues } from "@plane/types"; import { ISubIssuesRootLoaders, ISubIssuesRootLoadersHandler } from "./root"; import { useIssueDetail, useProject, useProjectState } from "hooks/store"; export interface ISubIssues { workspaceSlug: string; projectId: string; parentIssue: TIssue; issueId: string; handleIssue: { fetchIssues: (issueId: string) => Promise; updateIssue: (issueId: string, data: Partial) => Promise; removeIssue: (issueId: string) => Promise; }; spacingLeft?: number; user: IUser | undefined; editable: boolean; removeIssueFromSubIssues: (parentIssueId: string, issue: TIssue) => void; issuesLoader: ISubIssuesRootLoaders; handleIssuesLoader: ({ key, issueId }: ISubIssuesRootLoadersHandler) => void; copyText: (text: string) => void; handleIssueCrudOperation: ( key: "create" | "existing" | "edit" | "delete", issueId: string, issue?: TIssue | null ) => void; handleUpdateIssue: (issue: TIssue, data: Partial) => void; } export const SubIssues: React.FC = ({ workspaceSlug, projectId, parentIssue, issueId, handleIssue, spacingLeft = 0, user, editable, removeIssueFromSubIssues, issuesLoader, handleIssuesLoader, copyText, handleIssueCrudOperation, handleUpdateIssue, }) => { const router = useRouter(); const { peekProjectId, peekIssueId } = router.query; const { issue: { getIssueById }, } = useIssueDetail(); const project = useProject(); const { getProjectStates } = useProjectState(); const issue = getIssueById(issueId); const projectDetail = project.getProjectById(projectId); const currentIssueStateDetail = (issue?.project_id && getProjectStates(issue?.project_id)?.find((state) => issue?.state_id == state.id)) || undefined; const handleIssuePeekOverview = () => { const { query } = router; router.push({ pathname: router.pathname, query: { ...query, peekIssueId: issue?.id, peekProjectId: issue?.project_id }, }); }; return ( <> {workspaceSlug && peekProjectId && peekIssueId && peekIssueId === issue?.id && ( await handleUpdateIssue(issue, { ...issue, ...issueToUpdate })} /> )}
{issue && (
{issue?.sub_issues_count > 0 && ( <> {issuesLoader.sub_issues.includes(issue?.id) ? (
) : (
handleIssuesLoader({ key: "visibility", issueId: issue?.id })} > {issuesLoader && issuesLoader.visibility.includes(issue?.id) ? ( ) : ( )}
)} )}
{projectDetail?.identifier}-{issue?.sequence_id}
{issue?.name}
{editable && ( handleIssueCrudOperation("edit", parentIssue?.id, issue)}>
Edit issue
)} {editable && ( handleIssueCrudOperation("delete", parentIssue?.id, issue)}>
Delete issue
)} copyText(`${workspaceSlug}/projects/${issue.project_id}/issues/${issue.id}`)} >
Copy issue link
{editable && ( <> {issuesLoader.delete.includes(issue?.id) ? (
) : (
{ handleIssuesLoader({ key: "delete", issueId: issue?.id }); removeIssueFromSubIssues(parentIssue?.id, issue); }} >
)} )}
)} {issuesLoader.visibility.includes(issueId) && issue?.sub_issues_count && issue?.sub_issues_count > 0 && ( )}
); };