From 39ffb719536d80cbd380b32205b226a1d273d98f Mon Sep 17 00:00:00 2001 From: Galia Ilanov <90548502+galiail@users.noreply.github.com> Date: Mon, 17 Apr 2023 17:34:25 +0300 Subject: [PATCH] adding sorting to the riskiest regions widget (#256) ## Description adding sorting to the riskiest regions widget ## Type of Change [ ] Bug Fix [x] New Feature [ ] Breaking Change [ ] Refactor [ ] Documentation [ ] Other (please describe) --- .../layout/Dashboard/RiskiestRegionsWidget/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/src/layout/Dashboard/RiskiestRegionsWidget/index.js b/ui/src/layout/Dashboard/RiskiestRegionsWidget/index.js index f4392c081..aa9e0dfa8 100644 --- a/ui/src/layout/Dashboard/RiskiestRegionsWidget/index.js +++ b/ui/src/layout/Dashboard/RiskiestRegionsWidget/index.js @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import classnames from 'classnames'; +import { orderBy } from 'lodash'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, ResponsiveContainer, Tooltip } from 'recharts'; import { useFetch } from 'hooks'; import Loader from 'components/Loader'; @@ -32,12 +33,18 @@ const TooltipHeader = ({data}) => { } const WidgetContent = ({data}) => { - const formattedData = data.map(({regionName, findingsCount}) => ({regionName, ...findingsCount})) - const [selectedFilters, setSelectedFilters] = useState([ ...WIDGET_FINDINGS_ITEMS.map(({dataKey}) => dataKey) ]); + const formattedData = orderBy(data || [], ({findingsCount}) => { + return Object.keys(findingsCount || {}).reduce((acc, currFindingKey) => { + const count = findingsCount[currFindingKey] || 0; + + return acc + (selectedFilters.includes(currFindingKey) ? count : 0); + }, 0); + }, ["desc"]).map(({regionName, findingsCount}) => ({regionName, ...findingsCount})); + return (