fix: cycle stats empty state (#1338)

* chore: active cycle percentage fix

* fix: progress chart x-axis values
This commit is contained in:
Aaryan Khandelwal 2023-06-23 11:09:34 +05:30 committed by GitHub
parent 9c85704be3
commit d3c56c1765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 211 additions and 165 deletions

View File

@ -3,7 +3,7 @@ import React from "react";
// ui // ui
import { LineGraph } from "components/ui"; import { LineGraph } from "components/ui";
// helpers // helpers
import { renderShortNumericDateFormat } from "helpers/date-time.helper"; import { getDatesInRange, renderShortNumericDateFormat } from "helpers/date-time.helper";
//types //types
import { TCompletionChartDistribution } from "types"; import { TCompletionChartDistribution } from "types";
@ -46,6 +46,27 @@ const ProgressChart: React.FC<Props> = ({ distribution, startDate, endDate, tota
pending: distribution[key], pending: distribution[key],
})); }));
const generateXAxisTickValues = () => {
const dates = getDatesInRange(startDate, endDate);
const maxDates = 4;
const totalDates = dates.length;
if (totalDates <= maxDates) return dates;
else {
const interval = Math.ceil(totalDates / maxDates);
const limitedDates = [];
for (let i = 0; i < totalDates; i += interval)
limitedDates.push(renderShortNumericDateFormat(dates[i]));
if (!limitedDates.includes(renderShortNumericDateFormat(dates[totalDates - 1])))
limitedDates.push(renderShortNumericDateFormat(dates[totalDates - 1]));
return limitedDates;
}
};
return ( return (
<div className="w-full flex justify-center items-center"> <div className="w-full flex justify-center items-center">
<LineGraph <LineGraph
@ -86,7 +107,7 @@ const ProgressChart: React.FC<Props> = ({ distribution, startDate, endDate, tota
]} ]}
layers={["grid", "markers", "areas", DashedLine, "slices", "points", "axes", "legends"]} layers={["grid", "markers", "areas", DashedLine, "slices", "points", "axes", "legends"]}
axisBottom={{ axisBottom={{
tickValues: chartData.map((item, index) => (index % 2 === 0 ? item.currentDate : "")), tickValues: generateXAxisTickValues(),
}} }}
enablePoints={false} enablePoints={false}
enableArea enableArea

View File

@ -395,6 +395,7 @@ export const ActiveCycleDetails: React.FC = () => {
<div className="text-brand-primary">High Priority Issues</div> <div className="text-brand-primary">High Priority Issues</div>
<div className="my-3 flex max-h-[240px] min-h-[240px] flex-col gap-2.5 overflow-y-scroll rounded-md"> <div className="my-3 flex max-h-[240px] min-h-[240px] flex-col gap-2.5 overflow-y-scroll rounded-md">
{issues ? ( {issues ? (
issues.length > 0 ? (
issues.map((issue) => ( issues.map((issue) => (
<div <div
key={issue.id} key={issue.id}
@ -421,7 +422,6 @@ export const ActiveCycleDetails: React.FC = () => {
</span> </span>
</Tooltip> </Tooltip>
</div> </div>
<div className="flex items-center gap-1.5"> <div className="flex items-center gap-1.5">
<div <div
className={`grid h-6 w-6 place-items-center items-center rounded border shadow-sm flex-shrink-0 ${ className={`grid h-6 w-6 place-items-center items-center rounded border shadow-sm flex-shrink-0 ${
@ -471,6 +471,11 @@ export const ActiveCycleDetails: React.FC = () => {
</div> </div>
</div> </div>
)) ))
) : (
<div className="grid place-items-center text-brand-secondary text-sm text-center">
No issues present in the cycle.
</div>
)
) : ( ) : (
<Loader className="space-y-3"> <Loader className="space-y-3">
<Loader.Item height="50px" /> <Loader.Item height="50px" />
@ -481,6 +486,7 @@ export const ActiveCycleDetails: React.FC = () => {
</div> </div>
</div> </div>
{issues && issues.length > 0 && (
<div className="flex items-center justify-between gap-2"> <div className="flex items-center justify-between gap-2">
<div className="h-1 w-full rounded-full bg-brand-surface-2"> <div className="h-1 w-full rounded-full bg-brand-surface-2">
<div <div
@ -502,6 +508,7 @@ export const ActiveCycleDetails: React.FC = () => {
{issues?.length} {issues?.length}
</div> </div>
</div> </div>
)}
</div> </div>
<div className="flex flex-col justify-between border-brand-base p-4"> <div className="flex flex-col justify-between border-brand-base p-4">
<div className="flex items-start justify-between gap-4 py-1.5 text-xs"> <div className="flex items-start justify-between gap-4 py-1.5 text-xs">

View File

@ -1,4 +1,4 @@
import React from "react"; import React, { Fragment } from "react";
// headless ui // headless ui
import { Tab } from "@headlessui/react"; import { Tab } from "@headlessui/react";
@ -32,6 +32,7 @@ export const ActiveCycleProgressStats: React.FC<Props> = ({ cycle }) => {
return ( return (
<Tab.Group <Tab.Group
as={Fragment}
defaultIndex={currentValue(tab)} defaultIndex={currentValue(tab)}
onChange={(i) => { onChange={(i) => {
switch (i) { switch (i) {
@ -68,10 +69,11 @@ export const ActiveCycleProgressStats: React.FC<Props> = ({ cycle }) => {
Labels Labels
</Tab> </Tab>
</Tab.List> </Tab.List>
<Tab.Panels className="flex w-full px-4 pb-4"> {cycle.total_issues > 0 ? (
<Tab.Panels as={Fragment}>
<Tab.Panel <Tab.Panel
as="div" as="div"
className="flex flex-col w-full mt-2 gap-1 overflow-y-scroll items-center text-brand-secondary" className="w-full gap-1 overflow-y-scroll items-center text-brand-secondary p-4"
> >
{cycle.distribution.assignees.map((assignee, index) => { {cycle.distribution.assignees.map((assignee, index) => {
if (assignee.assignee_id) if (assignee.assignee_id)
@ -121,7 +123,7 @@ export const ActiveCycleProgressStats: React.FC<Props> = ({ cycle }) => {
</Tab.Panel> </Tab.Panel>
<Tab.Panel <Tab.Panel
as="div" as="div"
className="flex flex-col w-full mt-2 gap-1 overflow-y-scroll items-center text-brand-secondary" className="w-full gap-1 overflow-y-scroll items-center text-brand-secondary p-4"
> >
{cycle.distribution.labels.map((label, index) => ( {cycle.distribution.labels.map((label, index) => (
<SingleProgressStats <SingleProgressStats
@ -143,6 +145,11 @@ export const ActiveCycleProgressStats: React.FC<Props> = ({ cycle }) => {
))} ))}
</Tab.Panel> </Tab.Panel>
</Tab.Panels> </Tab.Panels>
) : (
<div className="grid place-items-center text-brand-secondary text-sm text-center mt-4">
No issues present in the cycle.
</div>
)}
</Tab.Group> </Tab.Group>
); );
}; };

View File

@ -282,12 +282,18 @@ export const SingleCycleList: React.FC<TSingleStatProps> = ({
> >
{cycleStatus === "current" ? ( {cycleStatus === "current" ? (
<span className="flex gap-1"> <span className="flex gap-1">
{cycle.total_issues > 0 ? (
<>
<RadialProgressBar <RadialProgressBar
progress={(cycle.completed_issues / cycle.total_issues) * 100} progress={(cycle.completed_issues / cycle.total_issues) * 100}
/> />
<span> <span>
{Math.floor((cycle.completed_issues / cycle.total_issues) * 100)} % {Math.floor((cycle.completed_issues / cycle.total_issues) * 100)} %
</span> </span>
</>
) : (
<span className="normal-case">No issues present</span>
)}
</span> </span>
) : cycleStatus === "upcoming" ? ( ) : cycleStatus === "upcoming" ? (
<span className="flex gap-1"> <span className="flex gap-1">

View File

@ -25,13 +25,18 @@ export const findHowManyDaysLeft = (date: string | Date) => {
return Math.ceil(timeDiff / (1000 * 3600 * 24)); return Math.ceil(timeDiff / (1000 * 3600 * 24));
}; };
export const getDatesInRange = (startDate: Date, endDate: Date) => { export const getDatesInRange = (startDate: string | Date, endDate: string | Date) => {
startDate = new Date(startDate);
endDate = new Date(endDate);
const date = new Date(startDate.getTime()); const date = new Date(startDate.getTime());
const dates = []; const dates = [];
while (date <= endDate) { while (date <= endDate) {
dates.push(new Date(date)); dates.push(new Date(date));
date.setDate(date.getDate() + 1); date.setDate(date.getDate() + 1);
} }
return dates; return dates;
}; };