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

adding sorting to the riskiest regions widget #256

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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