2023-02-08 13:20:08 +00:00
|
|
|
import React from "react";
|
2023-02-08 18:28:53 +00:00
|
|
|
|
|
|
|
import Image from "next/image";
|
2023-02-08 13:20:08 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-02-08 18:28:53 +00:00
|
|
|
|
2023-02-08 13:20:08 +00:00
|
|
|
import useSWR from "swr";
|
2023-02-08 18:28:53 +00:00
|
|
|
|
|
|
|
// headless ui
|
|
|
|
import { Tab } from "@headlessui/react";
|
|
|
|
// services
|
|
|
|
import issuesServices from "services/issues.service";
|
|
|
|
import projectService from "services/project.service";
|
2023-02-14 14:35:32 +00:00
|
|
|
// hooks
|
|
|
|
import useLocalStorage from "hooks/use-local-storage";
|
2023-03-29 20:01:43 +00:00
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-02-08 18:28:53 +00:00
|
|
|
// components
|
2023-03-29 06:22:39 +00:00
|
|
|
import { SingleProgressStats } from "components/core";
|
2023-02-08 13:20:08 +00:00
|
|
|
// ui
|
|
|
|
import { Avatar } from "components/ui";
|
|
|
|
// icons
|
|
|
|
import User from "public/user.png";
|
|
|
|
// types
|
2023-03-07 09:34:02 +00:00
|
|
|
import { IIssue, IIssueLabels, IModule, UserAuth } from "types";
|
2023-02-08 18:28:53 +00:00
|
|
|
// fetch-keys
|
2023-02-08 13:20:08 +00:00
|
|
|
import { PROJECT_ISSUE_LABELS, PROJECT_MEMBERS } from "constants/fetch-keys";
|
2023-02-08 18:28:53 +00:00
|
|
|
// types
|
2023-02-08 13:20:08 +00:00
|
|
|
type Props = {
|
|
|
|
groupedIssues: any;
|
|
|
|
issues: IIssue[];
|
2023-03-07 09:34:02 +00:00
|
|
|
module?: IModule;
|
|
|
|
userAuth?: UserAuth;
|
2023-02-08 13:20:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const stateGroupColours: {
|
|
|
|
[key: string]: string;
|
|
|
|
} = {
|
|
|
|
backlog: "#3f76ff",
|
|
|
|
unstarted: "#ff9e9e",
|
|
|
|
started: "#d687ff",
|
|
|
|
cancelled: "#ff5353",
|
|
|
|
completed: "#096e8d",
|
|
|
|
};
|
|
|
|
|
2023-03-07 09:34:02 +00:00
|
|
|
export const SidebarProgressStats: React.FC<Props> = ({
|
|
|
|
groupedIssues,
|
|
|
|
issues,
|
|
|
|
module,
|
|
|
|
userAuth,
|
|
|
|
}) => {
|
2023-02-08 13:20:08 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2023-02-14 14:35:32 +00:00
|
|
|
|
2023-03-29 20:01:43 +00:00
|
|
|
const { filters, setFilters } = useIssuesView();
|
|
|
|
|
2023-02-17 13:22:16 +00:00
|
|
|
const { storedValue: tab, setValue: setTab } = useLocalStorage("tab", "Assignees");
|
2023-02-14 14:35:32 +00:00
|
|
|
|
2023-02-08 13:20:08 +00:00
|
|
|
const { data: issueLabels } = useSWR<IIssueLabels[]>(
|
|
|
|
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
|
|
|
|
);
|
2023-02-13 07:44:23 +00:00
|
|
|
|
2023-02-17 13:22:16 +00:00
|
|
|
const currentValue = (tab: string | null) => {
|
2023-02-13 07:44:23 +00:00
|
|
|
switch (tab) {
|
2023-03-07 09:34:02 +00:00
|
|
|
case "Assignees":
|
2023-03-29 06:22:39 +00:00
|
|
|
return 0;
|
2023-03-07 09:34:02 +00:00
|
|
|
case "Labels":
|
2023-03-29 06:22:39 +00:00
|
|
|
return 1;
|
2023-03-07 09:34:02 +00:00
|
|
|
case "States":
|
2023-03-29 06:22:39 +00:00
|
|
|
return 2;
|
2023-03-07 09:34:02 +00:00
|
|
|
|
2023-02-17 13:22:16 +00:00
|
|
|
default:
|
2023-03-07 09:34:02 +00:00
|
|
|
return 3;
|
2023-02-13 07:44:23 +00:00
|
|
|
}
|
|
|
|
};
|
2023-02-08 13:20:08 +00:00
|
|
|
return (
|
2023-02-13 07:44:23 +00:00
|
|
|
<Tab.Group
|
|
|
|
defaultIndex={currentValue(tab)}
|
|
|
|
onChange={(i) => {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2023-03-07 09:34:02 +00:00
|
|
|
return setTab("Assignees");
|
2023-03-29 06:22:39 +00:00
|
|
|
case 1:
|
2023-03-07 09:34:02 +00:00
|
|
|
return setTab("Labels");
|
2023-03-29 06:22:39 +00:00
|
|
|
case 2:
|
2023-02-13 07:44:23 +00:00
|
|
|
return setTab("States");
|
|
|
|
|
|
|
|
default:
|
2023-03-07 09:34:02 +00:00
|
|
|
return setTab("States");
|
2023-02-13 07:44:23 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2023-02-10 13:10:02 +00:00
|
|
|
<Tab.List
|
|
|
|
as="div"
|
2023-04-20 08:11:24 +00:00
|
|
|
className={`flex w-full items-center justify-between rounded-md bg-brand-surface-1 px-1 py-1.5
|
2023-03-07 09:34:02 +00:00
|
|
|
${module ? "text-xs" : "text-sm"} `}
|
2023-02-10 13:10:02 +00:00
|
|
|
>
|
|
|
|
<Tab
|
2023-03-07 09:34:02 +00:00
|
|
|
className={({ selected }) =>
|
2023-04-20 08:11:24 +00:00
|
|
|
`w-full rounded px-3 py-1 text-brand-base ${
|
|
|
|
selected ? " bg-brand-accent text-white" : " hover:bg-brand-surface-2"
|
2023-03-07 09:34:02 +00:00
|
|
|
}`
|
|
|
|
}
|
2023-02-08 13:20:08 +00:00
|
|
|
>
|
2023-02-10 13:10:02 +00:00
|
|
|
Assignees
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
2023-03-07 09:34:02 +00:00
|
|
|
className={({ selected }) =>
|
2023-04-20 08:11:24 +00:00
|
|
|
`w-full rounded px-3 py-1 text-brand-base ${
|
|
|
|
selected ? " bg-brand-accent text-white" : " hover:bg-brand-surface-2"
|
2023-03-07 09:34:02 +00:00
|
|
|
}`
|
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
>
|
|
|
|
Labels
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
className={({ selected }) =>
|
2023-04-20 08:11:24 +00:00
|
|
|
`w-full rounded px-3 py-1 text-brand-base ${
|
|
|
|
selected ? " bg-brand-accent text-white" : " hover:bg-brand-surface-2"
|
2023-03-07 09:34:02 +00:00
|
|
|
}`
|
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
>
|
|
|
|
States
|
|
|
|
</Tab>
|
|
|
|
</Tab.List>
|
2023-03-29 20:01:43 +00:00
|
|
|
<Tab.Panels className="flex w-full items-center justify-between pt-1">
|
|
|
|
<Tab.Panel as="div" className="flex w-full flex-col text-xs">
|
2023-02-10 13:10:02 +00:00
|
|
|
{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");
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-02-10 13:10:02 +00:00
|
|
|
if (totalArray.length > 0) {
|
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={index}
|
|
|
|
title={
|
|
|
|
<>
|
|
|
|
<Avatar user={member.member} />
|
|
|
|
<span>{member.member.first_name}</span>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
completed={completeArray.length}
|
|
|
|
total={totalArray.length}
|
2023-03-29 20:01:43 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (filters.assignees?.includes(member.member.id))
|
|
|
|
setFilters({
|
|
|
|
assignees: filters.assignees?.filter((a) => a !== member.member.id),
|
|
|
|
});
|
|
|
|
else
|
|
|
|
setFilters({ assignees: [...(filters?.assignees ?? []), member.member.id] });
|
|
|
|
}}
|
|
|
|
selected={filters.assignees?.includes(member.member.id)}
|
2023-02-10 13:10:02 +00:00
|
|
|
/>
|
|
|
|
);
|
2023-02-08 13:20:08 +00:00
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
})}
|
|
|
|
{issues?.filter((i) => i.assignees?.length === 0).length > 0 ? (
|
|
|
|
<SingleProgressStats
|
|
|
|
title={
|
|
|
|
<>
|
2023-04-20 08:11:24 +00:00
|
|
|
<div className="h-5 w-5 rounded-full border-2 border-white bg-brand-surface-2">
|
2023-02-10 13:10:02 +00:00
|
|
|
<Image
|
|
|
|
src={User}
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
className="rounded-full"
|
|
|
|
alt="User"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<span>No assignee</span>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
completed={
|
|
|
|
issues?.filter(
|
|
|
|
(i) => i.state_detail.group === "completed" && i.assignees?.length === 0
|
|
|
|
).length
|
2023-02-08 13:20:08 +00:00
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
total={issues?.filter((i) => i.assignees?.length === 0).length}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
""
|
|
|
|
)}
|
|
|
|
</Tab.Panel>
|
2023-03-29 20:01:43 +00:00
|
|
|
<Tab.Panel as="div" className="w-full space-y-1">
|
2023-03-15 06:14:44 +00:00
|
|
|
{issueLabels?.map((label, index) => {
|
|
|
|
const totalArray = issues?.filter((i) => i.labels?.includes(label.id));
|
2023-02-10 13:10:02 +00:00
|
|
|
const completeArray = totalArray?.filter((i) => i.state_detail.group === "completed");
|
2023-03-15 06:14:44 +00:00
|
|
|
|
2023-02-10 13:10:02 +00:00
|
|
|
if (totalArray.length > 0) {
|
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={index}
|
|
|
|
title={
|
2023-03-07 08:13:09 +00:00
|
|
|
<div className="flex items-center gap-2">
|
2023-02-10 13:10:02 +00:00
|
|
|
<span
|
2023-03-29 20:01:43 +00:00
|
|
|
className="block h-3 w-3 rounded-full"
|
2023-02-10 13:10:02 +00:00
|
|
|
style={{
|
2023-03-15 06:14:44 +00:00
|
|
|
backgroundColor:
|
|
|
|
label.color && label.color !== "" ? label.color : "#000000",
|
2023-02-10 13:10:02 +00:00
|
|
|
}}
|
2023-02-08 13:20:08 +00:00
|
|
|
/>
|
2023-03-15 06:14:44 +00:00
|
|
|
<span className="text-xs capitalize">{label.name}</span>
|
2023-03-07 08:13:09 +00:00
|
|
|
</div>
|
2023-02-10 13:10:02 +00:00
|
|
|
}
|
|
|
|
completed={completeArray.length}
|
|
|
|
total={totalArray.length}
|
2023-03-29 20:01:43 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (filters.labels?.includes(label.id))
|
|
|
|
setFilters({
|
|
|
|
labels: filters.labels?.filter((l) => l !== label.id),
|
|
|
|
});
|
|
|
|
else setFilters({ labels: [...(filters?.labels ?? []), label.id] });
|
|
|
|
}}
|
|
|
|
selected={filters.labels?.includes(label.id)}
|
2023-02-10 13:10:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</Tab.Panel>
|
2023-03-07 09:34:02 +00:00
|
|
|
<Tab.Panel as="div" className="flex w-full flex-col ">
|
2023-02-10 13:10:02 +00:00
|
|
|
{Object.keys(groupedIssues).map((group, index) => (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={index}
|
|
|
|
title={
|
2023-03-07 08:13:09 +00:00
|
|
|
<div className="flex items-center gap-2">
|
2023-02-10 13:10:02 +00:00
|
|
|
<span
|
2023-03-07 08:13:09 +00:00
|
|
|
className="block h-3 w-3 rounded-full "
|
2023-02-10 13:10:02 +00:00
|
|
|
style={{
|
|
|
|
backgroundColor: stateGroupColours[group],
|
|
|
|
}}
|
2023-02-08 13:20:08 +00:00
|
|
|
/>
|
2023-02-10 13:10:02 +00:00
|
|
|
<span className="text-xs capitalize">{group}</span>
|
2023-03-07 08:13:09 +00:00
|
|
|
</div>
|
2023-02-08 13:20:08 +00:00
|
|
|
}
|
2023-03-30 20:50:44 +00:00
|
|
|
completed={groupedIssues[group]}
|
2023-02-10 13:10:02 +00:00
|
|
|
total={issues.length}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tab.Panel>
|
|
|
|
</Tab.Panels>
|
|
|
|
</Tab.Group>
|
2023-02-08 13:20:08 +00:00
|
|
|
);
|
|
|
|
};
|