2023-06-23 05:39:34 +00:00
|
|
|
import React, { Fragment } from "react";
|
2023-05-17 07:28:01 +00:00
|
|
|
|
|
|
|
// headless ui
|
|
|
|
import { Tab } from "@headlessui/react";
|
|
|
|
// hooks
|
|
|
|
import useLocalStorage from "hooks/use-local-storage";
|
|
|
|
// components
|
|
|
|
import { SingleProgressStats } from "components/core";
|
|
|
|
// ui
|
|
|
|
import { Avatar } from "components/ui";
|
|
|
|
// types
|
2023-06-20 11:02:02 +00:00
|
|
|
import { ICycle } from "types";
|
2023-05-17 07:28:01 +00:00
|
|
|
// types
|
|
|
|
type Props = {
|
2023-06-20 11:02:02 +00:00
|
|
|
cycle: ICycle;
|
2023-05-17 07:28:01 +00:00
|
|
|
};
|
|
|
|
|
2023-06-20 11:02:02 +00:00
|
|
|
export const ActiveCycleProgressStats: React.FC<Props> = ({ cycle }) => {
|
2023-05-17 07:28:01 +00:00
|
|
|
const { storedValue: tab, setValue: setTab } = useLocalStorage("activeCycleTab", "Assignees");
|
|
|
|
|
|
|
|
const currentValue = (tab: string | null) => {
|
|
|
|
switch (tab) {
|
|
|
|
case "Assignees":
|
|
|
|
return 0;
|
|
|
|
case "Labels":
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2023-06-20 11:02:02 +00:00
|
|
|
|
2023-05-17 07:28:01 +00:00
|
|
|
return (
|
|
|
|
<Tab.Group
|
2023-06-23 05:39:34 +00:00
|
|
|
as={Fragment}
|
2023-05-17 07:28:01 +00:00
|
|
|
defaultIndex={currentValue(tab)}
|
|
|
|
onChange={(i) => {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return setTab("Assignees");
|
|
|
|
case 1:
|
|
|
|
return setTab("Labels");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return setTab("Assignees");
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2023-05-19 21:38:23 +00:00
|
|
|
<Tab.List
|
|
|
|
as="div"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="flex sticky top-0 z-10 bg-custom-background-100 w-full px-4 pt-4 pb-1 flex-wrap items-center justify-start gap-4 text-sm"
|
2023-05-19 21:38:23 +00:00
|
|
|
>
|
2023-05-17 07:28:01 +00:00
|
|
|
<Tab
|
|
|
|
className={({ selected }) =>
|
2023-07-17 10:58:23 +00:00
|
|
|
`px-3 py-1 text-custom-text-100 rounded-3xl border border-custom-border-200 ${
|
2023-07-10 07:17:00 +00:00
|
|
|
selected ? " bg-custom-primary text-white" : " hover:bg-custom-background-80"
|
2023-05-17 07:28:01 +00:00
|
|
|
}`
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Assignees
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
className={({ selected }) =>
|
2023-07-17 10:58:23 +00:00
|
|
|
`px-3 py-1 text-custom-text-100 rounded-3xl border border-custom-border-200 ${
|
2023-07-10 07:17:00 +00:00
|
|
|
selected ? " bg-custom-primary text-white" : " hover:bg-custom-background-80"
|
2023-05-17 07:28:01 +00:00
|
|
|
}`
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Labels
|
|
|
|
</Tab>
|
|
|
|
</Tab.List>
|
2023-06-23 05:39:34 +00:00
|
|
|
{cycle.total_issues > 0 ? (
|
|
|
|
<Tab.Panels as={Fragment}>
|
|
|
|
<Tab.Panel
|
|
|
|
as="div"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="w-full gap-1 overflow-y-scroll items-center text-custom-text-200 p-4"
|
2023-06-23 05:39:34 +00:00
|
|
|
>
|
|
|
|
{cycle.distribution.assignees.map((assignee, index) => {
|
|
|
|
if (assignee.assignee_id)
|
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={assignee.assignee_id}
|
|
|
|
title={
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Avatar
|
|
|
|
user={{
|
|
|
|
id: assignee.assignee_id,
|
|
|
|
avatar: assignee.avatar ?? "",
|
|
|
|
first_name: assignee.first_name ?? "",
|
|
|
|
last_name: assignee.last_name ?? "",
|
2023-08-08 07:31:43 +00:00
|
|
|
display_name: assignee.display_name ?? "",
|
2023-06-23 05:39:34 +00:00
|
|
|
}}
|
2023-06-20 11:02:02 +00:00
|
|
|
/>
|
2023-08-08 07:31:43 +00:00
|
|
|
<span>{assignee.display_name}</span>
|
2023-06-20 11:02:02 +00:00
|
|
|
</div>
|
2023-06-23 05:39:34 +00:00
|
|
|
}
|
|
|
|
completed={assignee.completed_issues}
|
|
|
|
total={assignee.total_issues}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
else
|
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={`unassigned-${index}`}
|
|
|
|
title={
|
|
|
|
<div className="flex items-center gap-2">
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="h-5 w-5 rounded-full border-2 border-custom-border-200 bg-custom-background-80">
|
2023-06-23 05:39:34 +00:00
|
|
|
<img
|
|
|
|
src="/user.png"
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
className="rounded-full"
|
|
|
|
alt="User"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<span>No assignee</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
completed={assignee.completed_issues}
|
|
|
|
total={assignee.total_issues}
|
2023-06-20 11:02:02 +00:00
|
|
|
/>
|
2023-06-23 05:39:34 +00:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Tab.Panel>
|
|
|
|
<Tab.Panel
|
|
|
|
as="div"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="w-full gap-1 overflow-y-scroll items-center text-custom-text-200 p-4"
|
2023-06-23 05:39:34 +00:00
|
|
|
>
|
|
|
|
{cycle.distribution.labels.map((label, index) => (
|
|
|
|
<SingleProgressStats
|
|
|
|
key={label.label_id ?? `no-label-${index}`}
|
|
|
|
title={
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<span
|
|
|
|
className="block h-3 w-3 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: label.color ?? "transparent",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<span className="text-xs">{label.label_name ?? "No labels"}</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
completed={label.completed_issues}
|
|
|
|
total={label.total_issues}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tab.Panel>
|
|
|
|
</Tab.Panels>
|
|
|
|
) : (
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="grid place-items-center text-custom-text-200 text-sm text-center mt-4">
|
2023-06-23 05:39:34 +00:00
|
|
|
No issues present in the cycle.
|
|
|
|
</div>
|
|
|
|
)}
|
2023-05-17 07:28:01 +00:00
|
|
|
</Tab.Group>
|
|
|
|
);
|
|
|
|
};
|