Skip to content

Commit 1dd47af

Browse files
committed
frontend: fix issue with weekly chart when hourly data is missing
This commit addresses an issue where the weekly chart would crash if hourly data was missing. Previously, all three filters (week/month/year) relied on the existence of daily data to display or not. However, the week filter uses hourly data. So to determine whether to display the weekly chart, a new attribute, disableWeeklyFilters, has been introduced to disable only the weekly chart display if hourly data is unavailable.
1 parent 4acfac9 commit 1dd47af

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

frontends/web/src/routes/account/summary/chart.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class Chart extends Component<Props, State> {
135135
return this.props.data.chartDataDaily && this.props.data.chartDataDaily.length > 0;
136136
};
137137

138+
private hasHourlyData = (): boolean => {
139+
return this.props.data.chartDataHourly && this.props.data.chartDataHourly.length > 0;
140+
};
141+
138142
private setFormattedData(data: ChartData) {
139143
this.formattedData = {} as FormattedData;
140144

@@ -482,11 +486,14 @@ class Chart extends Component<Props, State> {
482486
} = this.state;
483487
const hasDifferenece = difference && Number.isFinite(difference);
484488
const hasData = this.hasData();
489+
const hasHourlyData = this.hasHourlyData();
485490
const disableFilters = !hasData || chartDataMissing;
491+
const disableWeeklyFilters = !hasHourlyData || chartDataMissing;
486492
const showMobileTotalValue = toolTipVisible && !!toolTipValue && isMobile;
487493
const chartFiltersProps = {
488494
display,
489495
disableFilters,
496+
disableWeeklyFilters,
490497
onDisplayWeek: this.displayWeek,
491498
onDisplayMonth: this.displayMonth,
492499
onDisplayYear: this.displayYear,

frontends/web/src/routes/account/summary/filters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import styles from './chart.module.css';
2121
const Filters = ({
2222
display,
2323
disableFilters,
24+
disableWeeklyFilters,
2425
onDisplayWeek,
2526
onDisplayMonth,
2627
onDisplayYear,
@@ -31,7 +32,7 @@ const Filters = ({
3132
<div className={styles.filters}>
3233
<button
3334
className={display === 'week' ? styles.filterActive : undefined}
34-
disabled={disableFilters}
35+
disabled={disableFilters || disableWeeklyFilters}
3536
onClick={onDisplayWeek}>
3637
{t('chart.filter.week')}
3738
</button>

frontends/web/src/routes/account/summary/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type TChartDisplay = 'week' | 'month' | 'year' | 'all';
1919
export type TChartFiltersProps = {
2020
display: TChartDisplay
2121
disableFilters: boolean;
22+
disableWeeklyFilters: boolean;
2223
onDisplayWeek: () => void;
2324
onDisplayMonth: () => void;
2425
onDisplayYear: () => void;

0 commit comments

Comments
 (0)