import { FC, Fragment } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import useSWR from "swr"; import { CalendarCheck } from "lucide-react"; // headless ui import { Tab } from "@headlessui/react"; // types import { ICycle, TIssue } from "@plane/types"; // ui import { Tooltip, Loader, PriorityIcon, Avatar } from "@plane/ui"; // components import { SingleProgressStats } from "@/components/core"; import { StateDropdown } from "@/components/dropdowns"; import { EmptyState } from "@/components/empty-state"; // constants import { EmptyStateType } from "@/constants/empty-state"; import { CYCLE_ISSUES_WITH_PARAMS } from "@/constants/fetch-keys"; import { EIssuesStoreType } from "@/constants/issue"; // helper import { cn } from "@/helpers/common.helper"; import { renderFormattedDate, renderFormattedDateWithoutYear } from "@/helpers/date-time.helper"; // hooks import { useIssues, useProject } from "@/hooks/store"; import useLocalStorage from "@/hooks/use-local-storage"; export type ActiveCycleStatsProps = { workspaceSlug: string; projectId: string; cycle: ICycle; }; export const ActiveCycleStats: FC = observer((props) => { const { workspaceSlug, projectId, cycle } = props; const { storedValue: tab, setValue: setTab } = useLocalStorage("activeCycleTab", "Assignees"); const currentValue = (tab: string | null) => { switch (tab) { case "Priority-Issues": return 0; case "Assignees": return 1; case "Labels": return 2; default: return 0; } }; const { issues: { fetchActiveCycleIssues }, } = useIssues(EIssuesStoreType.CYCLE); const { currentProjectDetails } = useProject(); const { data: activeCycleIssues } = useSWR( workspaceSlug && projectId && cycle.id ? CYCLE_ISSUES_WITH_PARAMS(cycle.id, { priority: "urgent,high" }) : null, workspaceSlug && projectId && cycle.id ? () => fetchActiveCycleIssues(workspaceSlug, projectId, cycle.id) : null ); const cycleIssues = activeCycleIssues ?? []; return (
{ switch (i) { case 0: return setTab("Priority-Issues"); case 1: return setTab("Assignees"); case 2: return setTab("Labels"); default: return setTab("Priority-Issues"); } }} > cn( "relative z-[1] font-semibold text-xs rounded-[3px] py-1.5 text-custom-text-400 focus:outline-none transition duration-500", { "text-custom-text-300 bg-custom-background-100": selected, "hover:text-custom-text-300": !selected, } ) } > Priority Issues cn( "relative z-[1] font-semibold text-xs rounded-[3px] py-1.5 text-custom-text-400 focus:outline-none transition duration-500", { "text-custom-text-300 bg-custom-background-100": selected, "hover:text-custom-text-300": !selected, } ) } > Assignees cn( "relative z-[1] font-semibold text-xs rounded-[3px] py-1.5 text-custom-text-400 focus:outline-none transition duration-500", { "text-custom-text-300 bg-custom-background-100": selected, "hover:text-custom-text-300": !selected, } ) } > Labels
{cycleIssues ? ( cycleIssues.length > 0 ? ( cycleIssues.map((issue: TIssue) => (
{currentProjectDetails?.identifier}-{issue.sequence_id} {issue.name}
{}} projectId={projectId?.toString() ?? ""} disabled buttonVariant="background-with-text" buttonContainerClassName="cursor-pointer max-w-24" showTooltip /> {issue.target_date && (
{renderFormattedDateWithoutYear(issue.target_date)}
)}
)) ) : (
) ) : ( )}
{cycle?.distribution?.assignees && cycle.distribution.assignees.length > 0 ? ( cycle.distribution?.assignees?.map((assignee, index) => { if (assignee.assignee_id) return ( {assignee.display_name}
} completed={assignee.completed_issues} total={assignee.total_issues} /> ); else return (
User
No assignee } completed={assignee.completed_issues} total={assignee.total_issues} /> ); }) ) : (
)} {cycle?.distribution?.labels && cycle.distribution.labels.length > 0 ? ( cycle.distribution.labels?.map((label, index) => ( {label.label_name ?? "No labels"} } completed={label.completed_issues} total={label.total_issues} /> )) ) : (
)}
); });