import { FC, useCallback } from "react"; import Link from "next/link"; // hooks import useLocalStorage from "hooks/use-local-storage"; // ui import { Tooltip, LinearProgressIndicator, Loader, PriorityIcon, Button, CycleGroupIcon } from "@plane/ui"; import { CalendarCheck } from "lucide-react"; // components import ProgressChart from "components/core/sidebar/progress-chart"; import { StateDropdown } from "components/dropdowns"; // types import { ICycle, TCycleGroups, TCycleLayout, TCycleView } from "@plane/types"; // helpers import { renderFormattedDate, findHowManyDaysLeft, renderFormattedDateWithoutYear } from "helpers/date-time.helper"; import { truncateText } from "helpers/string.helper"; import { renderEmoji } from "helpers/emoji.helper"; // constants import { STATE_GROUPS_DETAILS } from "constants/cycle"; export type ActiveCycleInfoProps = { cycle: ICycle; workspaceSlug: string; projectId: string; }; export const ActiveCycleInfo: FC = (props) => { const { cycle, workspaceSlug, projectId } = props; // local storage const { setValue: setCycleTab } = useLocalStorage("cycle_tab", "active"); const { setValue: setCycleLayout } = useLocalStorage("cycle_layout", "list"); const cycleIssues = cycle.issues ?? []; const handleCurrentLayout = useCallback( (_layout: TCycleLayout) => { setCycleLayout(_layout); }, [setCycleLayout] ); const handleCurrentView = useCallback( (_view: TCycleView) => { setCycleTab(_view); if (_view === "draft") handleCurrentLayout("list"); }, [handleCurrentLayout, setCycleTab] ); const groupedIssues: any = { completed: cycle.completed_issues, started: cycle.started_issues, unstarted: cycle.unstarted_issues, backlog: cycle.backlog_issues, }; const progressIndicatorData = STATE_GROUPS_DETAILS.map((group, index) => ({ id: index, name: group.title, value: cycle.total_issues > 0 ? (cycle[group.key as keyof ICycle] as number) : 0, color: group.color, })); const cuurentCycle = cycle.status.toLowerCase() as TCycleGroups; const daysLeft = findHowManyDaysLeft(cycle.end_date ?? new Date()); return ( <>
{cycle.project_detail.emoji ? ( {renderEmoji(cycle.project_detail.emoji)} ) : cycle.project_detail.icon_prop ? (
{renderEmoji(cycle.project_detail.icon_prop)}
) : ( {cycle.project_detail?.name.charAt(0)} )}

{cycle.project_detail.name}

{truncateText(cycle.name, 70)}

{`${daysLeft} ${daysLeft > 1 ? "Days" : "Day"} Left`}
Lead:
{cycle.owned_by.avatar && cycle.owned_by.avatar !== "" ? ( {cycle.owned_by.display_name} ) : ( {cycle.owned_by.display_name.charAt(0)} )} {cycle.owned_by.display_name}

Progress

{`${cycle.completed_issues + cycle.cancelled_issues}/${cycle.total_issues - cycle.cancelled_issues} ${ cycle.completed_issues + cycle.cancelled_issues > 1 ? "Issues" : "Issue" } closed`}
{Object.keys(groupedIssues).map((group, index) => ( <> {groupedIssues[group] > 0 && (
{group}
{`: ${groupedIssues[group]} ${groupedIssues[group] > 1 ? "Issues" : "Issue"}`}
)} ))} {cycle.cancelled_issues > 0 && ( {`${cycle.cancelled_issues} cancelled ${ cycle.cancelled_issues > 1 ? "issues are" : "issue is" } excluded from this report.`}{" "} )}

Issue Burndown

Priority

{cycleIssues ? ( cycleIssues.length > 0 ? ( cycleIssues.map((issue: any) => (
{cycle.project_detail?.identifier}-{issue.sequence_id} {issue.name}
{}} projectId={projectId?.toString() ?? ""} disabled={true} buttonVariant="background-with-text" /> {issue.target_date && (
{renderFormattedDateWithoutYear(issue.target_date)}
)}
)) ) : (
There are no high priority issues present in this cycle.
) ) : ( )}
); };