import { IIssueDisplayProperties, TIssue, TIssueMap } from "@plane/types"; import { SPREADSHEET_PROPERTY_DETAILS, SPREADSHEET_PROPERTY_LIST } from "constants/spreadsheet"; import { WithDisplayPropertiesHOC } from "../properties/with-display-properties-HOC"; import { Tooltip } from "@plane/ui"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; import { useIssueDetail, useProject } from "hooks/store"; import { useRef, useState } from "react"; import { useRouter } from "next/router"; import { ChevronRight, MoreHorizontal } from "lucide-react"; import { EIssueActions } from "../types"; import { observer } from "mobx-react-lite"; interface Props { displayProperties: IIssueDisplayProperties; isEstimateEnabled: boolean; quickActions: ( issue: TIssue, customActionButton?: React.ReactElement, portalElement?: HTMLDivElement | null ) => React.ReactNode; canEditProperties: (projectId: string | undefined) => boolean; handleIssues: (issue: TIssue, action: EIssueActions) => Promise; portalElement: React.MutableRefObject; nestingLevel: number; issueId: string; } export const SpreadsheetIssueRow = observer((props: Props) => { const { displayProperties, issueId, isEstimateEnabled, nestingLevel, portalElement, handleIssues, quickActions, canEditProperties, } = props; // router const router = useRouter(); const { workspaceSlug } = router.query; const { getProjectById } = useProject(); // states const [isMenuActive, setIsMenuActive] = useState(false); const [isExpanded, setExpanded] = useState(false); const menuActionRef = useRef(null); const handleIssuePeekOverview = (issue: TIssue) => { const { query } = router; router.push({ pathname: router.pathname, query: { ...query, peekIssueId: issue?.id, peekProjectId: issue?.project_id }, }); }; const { subIssues: subIssuesStore, issue } = useIssueDetail(); const issueDetail = issue.getIssueById(issueId); const subIssues = subIssuesStore.subIssuesByIssueId(issueId); const paddingLeft = `${nestingLevel * 54}px`; useOutsideClickDetector(menuActionRef, () => setIsMenuActive(false)); const handleToggleExpand = () => { setExpanded((prevState) => { if (!prevState && workspaceSlug && issueDetail) subIssuesStore.fetchSubIssues(workspaceSlug.toString(), issueDetail.project_id, issueDetail.id); return !prevState; }); }; const customActionButton = (
setIsMenuActive(!isMenuActive)} >
); if (!issueDetail) return null; const disableUserActions = !canEditProperties(issueDetail.project_id); return ( <> {/* first column/ issue name and key column */}
{getProjectById(issueDetail.project_id)?.identifier}-{issueDetail.sequence_id} {canEditProperties(issueDetail.project_id) && ( )}
{issueDetail.sub_issues_count > 0 && (
)}
handleIssuePeekOverview(issueDetail)} > {issueDetail.name}
{/* Rest of the columns */} {SPREADSHEET_PROPERTY_LIST.map((property) => { const { Column } = SPREADSHEET_PROPERTY_DETAILS[property]; const shouldRenderProperty = property === "estimate" ? isEstimateEnabled : true; return ( ) => handleIssues({ ...issue, ...data }, EIssueActions.UPDATE) } disabled={disableUserActions} /> ); })} {isExpanded && subIssues && subIssues.length > 0 && subIssues.map((subIssueId: string) => ( ))} ); });