Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table modal filtering bugs #221

Merged
merged 2 commits into from
Aug 8, 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
30 changes: 21 additions & 9 deletions frontend/src/Components/Elements/Table/TableModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ function TableModal({ chartState, dataSet, columns, isOpen, closeModal }) {
return () => document.removeEventListener('keyup', _handleKeyUp);
}, [closeModal]);

const cleanMonthlyData = (data) =>
data
.filter((d) => !d.hasOwnProperty('year'))
.map((d) => {
const row = d;
row['year'] = row['date'];
delete row['date'];
return row;
});

useEffect(() => {
let tableDS = mapDataSetToEnum[dataSet];
if (Array.isArray(dataSet)) {
Expand All @@ -133,14 +143,14 @@ function TableModal({ chartState, dataSet, columns, isOpen, closeModal }) {
if (yearRange.length <= 3) {
setDateInterval('month');
// Needs to show the monthly range dates in the 'year' column
tableData = tableData
.filter((d) => !d.hasOwnProperty('year'))
.map((d) => {
const row = d;
row['year'] = row['date'];
delete row['date'];
return row;
});
if (tableDS === STOPS_BY_REASON || tableDS === LIKELIHOOD_OF_SEARCH) {
tableData.stops = cleanMonthlyData(tableData.stops);
tableData.searches = cleanMonthlyData(tableData.searches);
} else if (tableDS === CONTRABAND_HIT_RATE) {
tableData.contraband = cleanMonthlyData(tableData.contraband);
} else {
tableData = cleanMonthlyData(tableData);
}
} else {
setDateInterval('year');
}
Expand Down Expand Up @@ -352,7 +362,9 @@ function TableModal({ chartState, dataSet, columns, isOpen, closeModal }) {
const mapContrbandHitrate = (ds) => {
const data = tableChartState.data[ds];
const { contraband } = data;
const mappedData = tableChartState.yearRange.map((year) => {
const yearRangeMap =
dateInterval === 'month' ? contraband.map((c) => c.year) : tableChartState.yearRange;
const mappedData = yearRangeMap.map((year) => {
const hits = contraband.find((d) => d.year === year) || 0;
const comparedData = { year };
if (!hits) {
Expand Down