Skip to content

Commit b0c446e

Browse files
Merge pull request #5126 from OneCommunityGlobal/veda-lbdashboard-fix
Veda - LBDashboard fix
2 parents cd25657 + 0a61472 commit b0c446e

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/components/LBDashboard/LBDashboard.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,17 @@ export function LBDashboard() {
305305
};
306306
}, []);
307307

308-
const dateRange = [
309-
moment()
310-
.subtract(1, 'year')
311-
.startOf('month'),
312-
moment().endOf('month'),
313-
];
308+
// Stable reference so opening metric dropdowns does not retrigger DemandOverTime's effect
309+
// (which would regenerate random series and make the line charts appear to "jump").
310+
const dateRange = useMemo(
311+
() => [
312+
moment()
313+
.subtract(1, 'year')
314+
.startOf('month'),
315+
moment().endOf('month'),
316+
],
317+
[],
318+
);
314319

315320
const getMetricLabel = () => {
316321
const all = Object.values(METRIC_OPTIONS).flat();

src/components/LBDashboard/LbAnalytics/DemandOverTime/DemandOverTime.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useMemo, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import moment from 'moment';
44
import styles from './DemandOverTime.module.css';
@@ -41,6 +41,11 @@ const DemandOverTime = ({
4141
}) => {
4242
const [data, setData] = useState([]);
4343

44+
const dateRangeBoundsKey = useMemo(() => {
45+
if (!dateRange?.length || dateRange.length < 2) return '';
46+
return `${moment(dateRange[0]).valueOf()}-${moment(dateRange[1]).valueOf()}`;
47+
}, [dateRange]);
48+
4449
useEffect(() => {
4550
const getItems = () => {
4651
return compareType === 'villages'
@@ -75,7 +80,8 @@ const DemandOverTime = ({
7580
};
7681

7782
setTimeout(() => setData(generateDummyData()), 300);
78-
}, [compareType, metric, dateRange]);
83+
// eslint-disable-next-line react-hooks/exhaustive-deps -- dateRange bounds are in dateRangeBoundsKey
84+
}, [compareType, metric, dateRangeBoundsKey]);
7985

8086
return (
8187
<div className={`${styles.container} ${darkMode ? styles.darkContainer : ''}`}>

src/utils/lbDashboard/chartsUtils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createChartOptions(metric, darkMode) {
3838
},
3939
},
4040
layout: {
41-
padding: 20,
41+
padding: { top: 36, right: 20, bottom: 20, left: 20 },
4242
},
4343
scales: {
4444
x: {
@@ -59,6 +59,8 @@ export function createChartOptions(metric, darkMode) {
5959
color: darkMode ? '#fff' : '#222',
6060
},
6161
beginAtZero: true,
62+
// Room above the max point so datalabels (align: top) are not clipped at the chart edge
63+
grace: '12%',
6264
ticks: { font: { size: 12 }, color: darkMode ? '#fff' : '#222' },
6365
},
6466
},

0 commit comments

Comments
 (0)