import React, { useCallback, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // components import { ViewAssigneeSelect, ViewDueDateSelect, ViewEstimateSelect, ViewLabelSelect, ViewPrioritySelect, ViewStateSelect, } from "components/issues"; import { Popover2 } from "@blueprintjs/popover2"; // icons import { Icon } from "components/ui"; import { EllipsisHorizontalIcon, LinkIcon, PencilIcon, TrashIcon, } from "@heroicons/react/24/outline"; // hooks import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view"; import useToast from "hooks/use-toast"; // services import issuesService from "services/issues.service"; // constant import { CYCLE_DETAILS, CYCLE_ISSUES_WITH_PARAMS, MODULE_DETAILS, MODULE_ISSUES_WITH_PARAMS, PROJECT_ISSUES_LIST_WITH_PARAMS, SUB_ISSUES, VIEW_ISSUES, } from "constants/fetch-keys"; // types import { ICurrentUserResponse, IIssue, ISubIssueResponse, Properties, UserAuth } from "types"; // helper import { copyTextToClipboard } from "helpers/string.helper"; import { renderLongDetailDateFormat } from "helpers/date-time.helper"; type Props = { issue: IIssue; index: number; expanded: boolean; handleToggleExpand: (issueId: string) => void; properties: Properties; handleEditIssue: (issue: IIssue) => void; handleDeleteIssue: (issue: IIssue) => void; gridTemplateColumns: string; isCompleted?: boolean; user: ICurrentUserResponse | undefined; userAuth: UserAuth; nestingLevel: number; }; export const SingleSpreadsheetIssue: React.FC = ({ issue, index, expanded, handleToggleExpand, properties, handleEditIssue, handleDeleteIssue, gridTemplateColumns, isCompleted = false, user, userAuth, nestingLevel, }) => { const [isOpen, setIsOpen] = useState(false); const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query; const { params } = useSpreadsheetIssuesView(); const { setToastAlert } = useToast(); const partialUpdateIssue = useCallback( (formData: Partial, issue: IIssue) => { if (!workspaceSlug || !projectId) return; const fetchKey = cycleId ? CYCLE_ISSUES_WITH_PARAMS(cycleId.toString(), params) : moduleId ? MODULE_ISSUES_WITH_PARAMS(moduleId.toString(), params) : viewId ? VIEW_ISSUES(viewId.toString(), params) : PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params); if (issue.parent) { mutate( SUB_ISSUES(issue.parent.toString()), (prevData) => { if (!prevData) return prevData; return { ...prevData, sub_issues: (prevData.sub_issues ?? []).map((i) => { if (i.id === issue.id) { return { ...i, ...formData, }; } return i; }), }; }, false ); } else { mutate( fetchKey, (prevData) => (prevData ?? []).map((p) => { if (p.id === issue.id) { return { ...p, ...formData, }; } return p; }), false ); } issuesService .patchIssue( workspaceSlug as string, projectId as string, issue.id as string, formData, user ) .then(() => { if (issue.parent) { mutate(SUB_ISSUES(issue.parent as string)); } else { mutate(fetchKey); if (cycleId) mutate(CYCLE_DETAILS(cycleId as string)); if (moduleId) mutate(MODULE_DETAILS(moduleId as string)); } }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, cycleId, moduleId, viewId, params, user] ); const handleCopyText = () => { const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; copyTextToClipboard( `${originURL}/${workspaceSlug}/projects/${projectId}/issues/${issue.id}` ).then(() => { setToastAlert({ type: "success", title: "Link Copied!", message: "Issue link copied to clipboard.", }); }); }; const paddingLeft = `${nestingLevel * 68}px`; const tooltipPosition = index === 0 ? "bottom" : "top"; const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (
{properties.key && ( {issue.project_detail?.identifier}-{issue.sequence_id} )} {!isNotAllowed && !isCompleted && (
setIsOpen(nextOpenState)} content={
} placement="bottom-start" >
)}
{issue.sub_issues_count > 0 && (
)}
{issue.name}
{properties.state && (
)} {properties.priority && (
)} {properties.assignee && (
)} {properties.labels && (
)} {properties.due_date && (
)} {properties.estimate && (
)} {properties.created_on && (
{renderLongDetailDateFormat(issue.created_at)}
)} {properties.updated_on && (
{renderLongDetailDateFormat(issue.updated_at)}
)}
); };