import React from "react"; import { Tab } from "@headlessui/react"; import { useRouter } from "next/router"; import useSWR from "swr"; import Image from "next/image"; // ui import SingleProgressStats from "./single-progress-stats"; import { Avatar } from "components/ui"; // icons import User from "public/user.png"; // types import { IIssue, IIssueLabels } from "types"; // constants import { PROJECT_ISSUE_LABELS, PROJECT_MEMBERS } from "constants/fetch-keys"; // services import issuesServices from "services/issues.service"; import projectService from "services/project.service"; type Props = { groupedIssues: any; issues: IIssue[]; }; const stateGroupColours: { [key: string]: string; } = { backlog: "#3f76ff", unstarted: "#ff9e9e", started: "#d687ff", cancelled: "#ff5353", completed: "#096e8d", }; const SidebarProgressStats: React.FC = ({ groupedIssues, issues }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: issueLabels } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null, workspaceSlug && projectId ? () => issuesServices.getIssueLabels(workspaceSlug as string, projectId as string) : null ); const { data: members } = useSWR( workspaceSlug && projectId ? PROJECT_MEMBERS(workspaceSlug as string) : null, workspaceSlug && projectId ? () => projectService.projectMembers(workspaceSlug as string, projectId as string) : null ); return (
`w-1/2 rounded py-1 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` } > Assignees `w-1/2 rounded py-1 ${selected ? "bg-gray-300 font-semibold" : "hover:bg-gray-200 "}` } > Labels `w-1/2 rounded py-1 ${selected ? "bg-gray-300 font-semibold" : "hover:bg-gray-200 "}` } > States {members?.map((member, index) => { const totalArray = issues?.filter((i) => i.assignees?.includes(member.member.id)); const completeArray = totalArray?.filter((i) => i.state_detail.group === "completed"); if (totalArray.length > 0) { return ( {member.member.first_name} } completed={completeArray.length} total={totalArray.length} /> ); } })} {issues?.filter((i) => i.assignees?.length === 0).length > 0 ? (
User
No assignee } completed={ issues?.filter( (i) => i.state_detail.group === "completed" && i.assignees?.length === 0 ).length } total={issues?.filter((i) => i.assignees?.length === 0).length} /> ) : ( "" )}
{issueLabels?.map((issue, index) => { const totalArray = issues?.filter((i) => i.labels?.includes(issue.id)); const completeArray = totalArray?.filter((i) => i.state_detail.group === "completed"); if (totalArray.length > 0) { return ( {issue.name} } completed={completeArray.length} total={totalArray.length} /> ); } })} {Object.keys(groupedIssues).map((group, index) => ( {group} } completed={groupedIssues[group].length} total={issues.length} /> ))}
); }; export default SidebarProgressStats;