Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
adding sorting to the riskiest regions widget (#256)
Browse files Browse the repository at this point in the history
## Description

adding sorting to the riskiest regions widget

## Type of Change

[ ] Bug Fix  
[x] New Feature  
[ ] Breaking Change  
[ ] Refactor  
[ ] Documentation  
[ ] Other (please describe)
  • Loading branch information
galiail authored Apr 17, 2023
1 parent b6cb757 commit 39ffb71
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ui/src/layout/Dashboard/RiskiestRegionsWidget/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<div style={{display: "flex", flexDirection: "column", height: "100%"}}>
<FindingsFilters
Expand Down

0 comments on commit 39ffb71

Please sign in to comment.