From fc4ba5a1702571e5b0d36ac4f4088433993726af Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Fri, 31 May 2024 13:57:46 +0530 Subject: [PATCH] [WEB-1235] chore: module and cycle sidebar graph improvement (#4650) * chore: module and cycle sidebar graph improvement * chore: code refactor --- .../core/sidebar/progress-chart.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/web/components/core/sidebar/progress-chart.tsx b/web/components/core/sidebar/progress-chart.tsx index 68b1708fe..5f0e56fb7 100644 --- a/web/components/core/sidebar/progress-chart.tsx +++ b/web/components/core/sidebar/progress-chart.tsx @@ -56,21 +56,18 @@ const ProgressChart: React.FC = ({ distribution, startDate, endDate, tota dates = eachDayOfInterval({ start, end }); } - const maxDates = 4; - const totalDates = dates.length; + if (dates.length === 0) return []; - if (totalDates <= maxDates) return dates.map((d) => renderFormattedDateWithoutYear(d)); - else { - const interval = Math.ceil(totalDates / maxDates); - const limitedDates = []; + const formattedDates = dates.map((d) => renderFormattedDateWithoutYear(d)); + const firstDate = formattedDates[0]; + const lastDate = formattedDates[formattedDates.length - 1]; - for (let i = 0; i < totalDates; i += interval) limitedDates.push(renderFormattedDateWithoutYear(dates[i])); + if (formattedDates.length <= 2) return [firstDate, lastDate]; - if (!limitedDates.includes(renderFormattedDateWithoutYear(dates[totalDates - 1]))) - limitedDates.push(renderFormattedDateWithoutYear(dates[totalDates - 1])); + const middleDateIndex = Math.floor(formattedDates.length / 2); + const middleDate = formattedDates[middleDateIndex]; - return limitedDates; - } + return [firstDate, middleDate, lastDate]; }; return (