2023-02-08 13:20:08 +00:00
|
|
|
import React from "react";
|
2023-02-08 18:28:53 +00:00
|
|
|
|
|
|
|
// headless ui
|
|
|
|
import { Tab } from "@headlessui/react";
|
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";
|
|
|
|
// types
|
2023-06-20 11:02:02 +00:00
|
|
|
import {
|
|
|
|
IModule,
|
|
|
|
TAssigneesDistribution,
|
|
|
|
TCompletionChartDistribution,
|
|
|
|
TLabelsDistribution,
|
|
|
|
} from "types";
|
|
|
|
// constants
|
|
|
|
import { STATE_GROUP_COLORS } from "constants/state";
|
2023-02-08 18:28:53 +00:00
|
|
|
// types
|
2023-02-08 13:20:08 +00:00
|
|
|
type Props = {
|
2023-06-20 11:02:02 +00:00
|
|
|
distribution: {
|
|
|
|
assignees: TAssigneesDistribution[];
|
|
|
|
completion_chart: TCompletionChartDistribution;
|
|
|
|
labels: TLabelsDistribution[];
|
|
|
|
};
|
|
|
|
groupedIssues: {
|
|
|
|
[key: string]: number;
|
|
|
|
};
|
|
|
|
totalIssues: number;
|
2023-03-07 09:34:02 +00:00
|
|
|
module?: IModule;
|
2023-05-17 07:28:01 +00:00
|
|
|
roundedTab?: boolean;
|
|
|
|
noBackground?: boolean;
|
2023-02-08 13:20:08 +00:00
|
|
|
};
|
|
|
|
|
2023-03-07 09:34:02 +00:00
|
|
|
export const SidebarProgressStats: React.FC<Props> = ({
|
2023-06-20 11:02:02 +00:00
|
|
|
distribution,
|
2023-03-07 09:34:02 +00:00
|
|
|
groupedIssues,
|
2023-06-20 11:02:02 +00:00
|
|
|
totalIssues,
|
2023-03-07 09:34:02 +00:00
|
|
|
module,
|
2023-05-17 07:28:01 +00:00
|
|
|
roundedTab,
|
|
|
|
noBackground,
|
2023-03-07 09:34:02 +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-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-04-28 12:18:40 +00:00
|
|
|
return 0;
|
2023-02-13 07:44:23 +00:00
|
|
|
}
|
|
|
|
};
|
2023-06-20 11:02:02 +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-04-28 12:18:40 +00:00
|
|
|
return setTab("Assignees");
|
2023-02-13 07:44:23 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2023-02-10 13:10:02 +00:00
|
|
|
<Tab.List
|
|
|
|
as="div"
|
2023-05-17 07:28:01 +00:00
|
|
|
className={`flex w-full items-center gap-2 justify-between rounded-md ${
|
2023-07-10 07:17:00 +00:00
|
|
|
noBackground ? "" : "bg-custom-background-90"
|
2023-05-17 07:28:01 +00:00
|
|
|
} 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-05-17 07:28:01 +00:00
|
|
|
`w-full ${
|
2023-07-17 10:58:23 +00:00
|
|
|
roundedTab ? "rounded-3xl border border-custom-border-200" : "rounded"
|
2023-07-10 07:17:00 +00:00
|
|
|
} px-3 py-1 text-custom-text-100 ${
|
|
|
|
selected ? " bg-custom-primary text-white" : " hover:bg-custom-background-80"
|
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-05-17 07:28:01 +00:00
|
|
|
`w-full ${
|
2023-07-17 10:58:23 +00:00
|
|
|
roundedTab ? "rounded-3xl border border-custom-border-200" : "rounded"
|
2023-07-10 07:17:00 +00:00
|
|
|
} px-3 py-1 text-custom-text-100 ${
|
|
|
|
selected ? " bg-custom-primary text-white" : " hover:bg-custom-background-80"
|
2023-03-07 09:34:02 +00:00
|
|
|
}`
|
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
>
|
|
|
|
Labels
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
className={({ selected }) =>
|
2023-05-17 07:28:01 +00:00
|
|
|
`w-full ${
|
2023-07-17 10:58:23 +00:00
|
|
|
roundedTab ? "rounded-3xl border border-custom-border-200" : "rounded"
|
2023-07-10 07:17:00 +00:00
|
|
|
} px-3 py-1 text-custom-text-100 ${
|
|
|
|
selected ? " bg-custom-primary text-white" : " hover:bg-custom-background-80"
|
2023-03-07 09:34:02 +00:00
|
|
|
}`
|
|
|
|
}
|
2023-02-10 13:10:02 +00:00
|
|
|
>
|
|
|
|
States
|
|
|
|
</Tab>
|
|
|
|
</Tab.List>
|
2023-07-10 07:17:00 +00:00
|
|
|
<Tab.Panels className="flex w-full items-center justify-between pt-1 text-custom-text-200">
|
2023-06-20 11:02:02 +00:00
|
|
|
<Tab.Panel as="div" className="w-full space-y-1">
|
|
|
|
{distribution.assignees.map((assignee, index) => {
|
|
|
|
if (assignee.assignee_id)
|
2023-02-10 13:10:02 +00:00
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
2023-06-20 11:02:02 +00:00
|
|
|
key={assignee.assignee_id}
|
2023-02-10 13:10:02 +00:00
|
|
|
title={
|
2023-06-20 11:02:02 +00:00
|
|
|
<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-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-02-10 13:10:02 +00:00
|
|
|
}
|
2023-06-20 11:02:02 +00:00
|
|
|
completed={assignee.completed_issues}
|
|
|
|
total={assignee.total_issues}
|
2023-03-29 20:01:43 +00:00
|
|
|
onClick={() => {
|
2023-06-20 11:02:02 +00:00
|
|
|
if (filters?.assignees?.includes(assignee.assignee_id ?? ""))
|
2023-03-29 20:01:43 +00:00
|
|
|
setFilters({
|
2023-06-20 11:02:02 +00:00
|
|
|
assignees: filters?.assignees?.filter((a) => a !== assignee.assignee_id),
|
2023-03-29 20:01:43 +00:00
|
|
|
});
|
|
|
|
else
|
2023-06-20 11:02:02 +00:00
|
|
|
setFilters({
|
|
|
|
assignees: [...(filters?.assignees ?? []), assignee.assignee_id ?? ""],
|
|
|
|
});
|
2023-03-29 20:01:43 +00:00
|
|
|
}}
|
2023-06-20 11:02:02 +00:00
|
|
|
selected={filters?.assignees?.includes(assignee.assignee_id ?? "")}
|
2023-02-10 13:10:02 +00:00
|
|
|
/>
|
|
|
|
);
|
2023-06-20 11:02:02 +00:00
|
|
|
else
|
2023-02-10 13:10:02 +00:00
|
|
|
return (
|
|
|
|
<SingleProgressStats
|
2023-06-20 11:02:02 +00:00
|
|
|
key={`unassigned-${index}`}
|
2023-02-10 13:10:02 +00:00
|
|
|
title={
|
2023-03-07 08:13:09 +00:00
|
|
|
<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-20 11:02:02 +00:00
|
|
|
<img
|
|
|
|
src="/user.png"
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
className="rounded-full"
|
|
|
|
alt="User"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<span>No assignee</span>
|
2023-03-07 08:13:09 +00:00
|
|
|
</div>
|
2023-02-10 13:10:02 +00:00
|
|
|
}
|
2023-06-20 11:02:02 +00:00
|
|
|
completed={assignee.completed_issues}
|
|
|
|
total={assignee.total_issues}
|
2023-02-10 13:10:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Tab.Panel>
|
2023-06-20 11:02:02 +00:00
|
|
|
<Tab.Panel as="div" className="w-full space-y-1">
|
|
|
|
{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}
|
|
|
|
onClick={() => {
|
|
|
|
if (filters.labels?.includes(label.label_id ?? ""))
|
|
|
|
setFilters({
|
|
|
|
labels: filters?.labels?.filter((l) => l !== label.label_id),
|
|
|
|
});
|
|
|
|
else setFilters({ labels: [...(filters?.labels ?? []), label.label_id ?? ""] });
|
|
|
|
}}
|
|
|
|
selected={filters?.labels?.includes(label.label_id ?? "")}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tab.Panel>
|
|
|
|
<Tab.Panel as="div" className="w-full space-y-1">
|
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={{
|
2023-06-20 11:02:02 +00:00
|
|
|
backgroundColor: STATE_GROUP_COLORS[group],
|
2023-02-10 13:10:02 +00:00
|
|
|
}}
|
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-06-20 11:02:02 +00:00
|
|
|
total={totalIssues}
|
2023-02-10 13:10:02 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tab.Panel>
|
|
|
|
</Tab.Panels>
|
|
|
|
</Tab.Group>
|
2023-02-08 13:20:08 +00:00
|
|
|
);
|
|
|
|
};
|