Skip to content

Commit 4a4a090

Browse files
authored
Merge pull request #80 from CBIIT/dev-1.0.0
Fix INS-371 issue: update filter info when options are not available …
2 parents 2485e64 + b3c630b commit 4a4a090

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

src/pages/dashboardTab/store/dashboardReducer.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-len */
12
/* eslint-disable arrow-body-style */
23
/* eslint-disable react/destructuring-assignment */
34
import _ from 'lodash';
@@ -218,7 +219,7 @@ const transformDonutData = (data) => {
218219
transformedData.projectCountByFiscalYearSorted = data.projectCountByFiscalYear.sort((a, b) => ((a.subjects < b.subjects) ? 1 : -1));
219220

220221
for (let i = 0; i < transformedData.publicationCountByYearSorted.length; i += 1) {
221-
// eslint-disable-next-line max-len
222+
// eslint-disable-next-line max-len
222223
transformedData.publicationCountByYearSorted[i].group = new Date(parseInt(transformedData.publicationCountByYearSorted[i].group, 10)).getFullYear();
223224
}
224225

@@ -1258,28 +1259,71 @@ const reducers = {
12581259
};
12591260
},
12601261
TOGGLE_CHECKBOX_WITH_API: (state, item) => {
1262+
const newAllFilters = {
1263+
award_amounts: [], docs: [], fiscal_years: [], programs: [],
1264+
};
1265+
1266+
let validCheckBoxOptions = [];
1267+
1268+
if (item.allFilters.award_amounts.length !== 0) {
1269+
validCheckBoxOptions = item.data.searchProjects.filterProjectCountByAwardAmount.map((opt) => opt.group);
1270+
item.allFilters.award_amounts.forEach((amount) => {
1271+
if (validCheckBoxOptions.indexOf(amount) > -1) {
1272+
newAllFilters.award_amounts.push(amount);
1273+
}
1274+
});
1275+
}
1276+
1277+
if (item.allFilters.docs.length !== 0) {
1278+
validCheckBoxOptions = item.data.searchProjects.filterProjectCountByDOC.map((opt) => opt.group);
1279+
item.allFilters.docs.forEach((doc) => {
1280+
if (validCheckBoxOptions.indexOf(doc) > -1) {
1281+
newAllFilters.docs.push(doc);
1282+
}
1283+
});
1284+
}
1285+
1286+
if (item.allFilters.fiscal_years.length !== 0) {
1287+
validCheckBoxOptions = item.data.searchProjects.filterProjectCountByFiscalYear.map((opt) => opt.group);
1288+
item.allFilters.fiscal_years.forEach((fyear) => {
1289+
if (validCheckBoxOptions.indexOf(fyear) > -1) {
1290+
newAllFilters.fiscal_years.push(fyear);
1291+
}
1292+
});
1293+
}
1294+
1295+
if (item.allFilters.programs.length !== 0) {
1296+
validCheckBoxOptions = item.data.searchProjects.filterProjectCountByProgram.map((opt) => opt.group);
1297+
item.allFilters.programs.forEach((program) => {
1298+
if (validCheckBoxOptions.indexOf(program) > -1) {
1299+
newAllFilters.programs.push(program);
1300+
}
1301+
});
1302+
}
1303+
12611304
let updatedCheckboxData1 = updateFilteredAPIDataIntoCheckBoxData(
12621305
item.data.searchProjects, facetSearchData,
12631306
);
12641307
const rangeData = updatedCheckboxData1.filter((sideBar) => sideBar.slider === true);
12651308
updatedCheckboxData1 = updatedCheckboxData1.filter((sideBar) => sideBar.slider !== true);
1266-
let checkboxData1 = setSelectedFilterValues(updatedCheckboxData1, item.allFilters);
1309+
let checkboxData1 = setSelectedFilterValues(updatedCheckboxData1, newAllFilters);
12671310
updatedCheckboxData1 = updatedCheckboxData1.concat(rangeData);
12681311
checkboxData1 = checkboxData1.concat(rangeData);
12691312
checkboxData1.forEach((cbd, idx) => {
12701313
checkboxData1[idx].tooltips = updatedCheckboxData1[idx].tooltips;
12711314
});
12721315
fetchDataForDashboardTab(
12731316
tabIndex[0].title,
1274-
item.allFilters,
1317+
newAllFilters,
12751318
);
1319+
12761320
return {
12771321
...state,
12781322
setSideBarLoading: false,
1279-
allActiveFilters: item.allFilters,
1323+
allActiveFilters: newAllFilters,
12801324
checkbox: {
12811325
data: checkboxData1,
1282-
variables: item.allFilters,
1326+
variables: newAllFilters,
12831327
},
12841328
stats: getFilteredStat(item.data.searchProjects, statsCount),
12851329
widgets: getWidgetsInitData(item.data.searchProjects, widgetsData),

0 commit comments

Comments
 (0)