Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(detail-page): fix total for yearly periods
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorenogogoleva committed Jun 7, 2020
1 parent 64303b6 commit 2b1e827
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/features/statistics/features/details/generic/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ export const Detail = ({ group, detailType, detailTitle, dataPath }: Props) => {
[data, dataPath],
);

const total = useMemo(
() =>
Option.of(
dataByPeriod && head(dataByPeriod) && head(dataByPeriod)[dataPath],
),
[dataByPeriod],
);
const total = useMemo(() => {
if (!dataByPeriod) return null;

const byMonth = dataByPeriod?.length === 1;

const totalValue = byMonth
? head(dataByPeriod)[dataPath]
: dataByPeriod.reduce((sum, it) => it[dataPath] + sum, 0);

return Option.of(totalValue);
}, [dataByPeriod]);

const errorState = error ? Option.of('Error') : Option.of<string>(null);

Expand Down

0 comments on commit 2b1e827

Please sign in to comment.