Skip to content

Commit

Permalink
explorer facet filter
Browse files Browse the repository at this point in the history
  • Loading branch information
[Toyo Udosen] committed Mar 28, 2022
1 parent 83cc803 commit 28d471d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 56 deletions.
4 changes: 2 additions & 2 deletions public/injectEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ window.injectedEnv = {
REACT_APP_ABOUT_CONTENT_URL: 'https://raw.githubusercontent.com/CBIIT/bento-icdc-frontend/Develop/src/content/pre-prod/aboutPagesContent.yaml',
REACT_APP_GA_TRACKING_ID: 'UA-154442677-1',
REACT_APP_FILE_SERVICE_API: 'https://caninecommons-dev.cancer.gov/api/files/',
REACT_APP_DATA_MODEL: 'https://raw.githubusercontent.com/CBIIT/icdc-model-tool/March_updates_and_fixes/model-desc/icdc-model.yml',
REACT_APP_DATA_MODEL_PROPS: 'https://raw.githubusercontent.com/CBIIT/icdc-model-tool/March_updates_and_fixes/model-desc/icdc-model-props.yml',
REACT_APP_DATA_MODEL: 'https://raw.githubusercontent.com/CBIIT/icdc-model-tool/master/model-desc/icdc-model.yml',
REACT_APP_DATA_MODEL_PROPS: 'https://raw.githubusercontent.com/CBIIT/icdc-model-tool/master/model-desc/icdc-model-props.yml',
};
72 changes: 18 additions & 54 deletions src/components/DataDictionaryComponent/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,22 @@ const initializeFilterHashMap = (dictionary) => {

const generateCount = (filtered, searchGroup, searchTerm, flag, filterBy, filterTerms) => {
let count = 0;
console.log('filterTerms', filterTerms);
if (flag) {
console.log('In like swimwear');
Object.keys(filtered).forEach((elem) => {
console.log('erro3 elem', elem);
console.log('erro3 filter', filtered[elem]);
console.log('erro3 filter.searchGroup', filtered[elem][searchGroup]);
console.log('erro3 searchTerm', searchTerm);
if (filterBy === 'inclusion') {
const inclusionObj = filtered[elem][filterBy] ? filtered[elem][filterBy] : {};
console.log('error3 here now');

if (
filtered[elem][searchGroup] === searchTerm
&& filterTerms.find((term) => (
Object.prototype.hasOwnProperty.call(inclusionObj, term.toLowerCase())))
) {
count += 1;
}

return;
}

if (
filtered[elem][searchGroup] === searchTerm
&& filterTerms.find((term) => term.toLowerCase()
Expand Down Expand Up @@ -204,8 +200,6 @@ const generateFilterBy = (filterObj) => {
const categoryexemptSubjectCount = (
unfiltered, filtered, groupName, filterObj, oldSubjectCountObject,
) => {
console.log('group there', groupName);
console.log('filterObj', filterObj);
switch (groupName) {
case 'category':
return {
Expand Down Expand Up @@ -280,7 +274,6 @@ const categoryexemptSubjectCount = (
optional: generateCount(unfiltered, 'inclusion', 'optional'),
};
case '$category':
console.log('$category', unfiltered);
return {
core: generateCount(
unfiltered,
Expand Down Expand Up @@ -319,7 +312,6 @@ const categoryexemptSubjectCount = (
optional: generateCount(filtered, 'inclusion', 'optional'),
};
case '$assignment':
console.log('$assignment', unfiltered);
return {
administrative: generateCount(
unfiltered,
Expand Down Expand Up @@ -392,7 +384,6 @@ const categoryexemptSubjectCount = (
optional: generateCount(filtered, 'inclusion', 'optional'),
};
case '$class':
console.log('$class', unfiltered);
return {
administrative: generateCount(
unfiltered,
Expand Down Expand Up @@ -569,67 +560,62 @@ const categoryexemptSubjectCount = (
}
case 'categoryunchecked':
case '$categoryunchecked': {
console.log('erro2 doing this');
const processedGroupName = groupName.slice(0, groupName.indexOf('unchecked'));
console.log('erro2 processGrpNm', processedGroupName);
let filterBy = filterObj[processedGroupName]
? filterObj[processedGroupName] : generateFilterBy(filterObj, processedGroupName);

filterBy = processedGroupName.includes('$') ? `$${filterBy}` : filterBy;
console.log('erro2 filBy', filterBy);
console.log('erro2 filObj', filterObj);

if (Object.prototype.hasOwnProperty.call(filterObj, processedGroupName)) {
console.log('erro2 in here');
return oldSubjectCountObject;
}

return categoryexemptSubjectCount(unfiltered, filtered, filterBy, filterObj);
}
case 'assignmentunchecked':
case '$assignmentunchecked': {
console.log('erro2 doing this');
const processedGroupName = groupName.slice(0, groupName.indexOf('unchecked'));
console.log('erro2 processGrpNm', processedGroupName);

let filterBy = filterObj[processedGroupName]
? filterObj[processedGroupName] : generateFilterBy(filterObj, processedGroupName);

filterBy = processedGroupName.includes('$') ? `$${filterBy}` : filterBy;
console.log('erro2 filBy', filterBy);
console.log('erro2 filObj', filterObj);

if (Object.prototype.hasOwnProperty.call(filterObj, processedGroupName)) {
return oldSubjectCountObject;
}

return categoryexemptSubjectCount(unfiltered, filtered, filterBy, filterObj);
}
case 'classunchecked':
case '$classunchecked': {
console.log('erro2 doing this instead');
const processedGroupName = groupName.slice(0, groupName.indexOf('unchecked'));
console.log('erro2 processGrpNm', processedGroupName);

let filterBy = filterObj[processedGroupName]
? filterObj[processedGroupName] : generateFilterBy(filterObj, processedGroupName);
filterBy = processedGroupName.includes('$') ? `$${filterBy}` : filterBy;
console.log('erro2 filBy', filterBy);
console.log('erro2 filObj', filterObj);

if (Object.prototype.hasOwnProperty.call(filterObj, processedGroupName)) {
return oldSubjectCountObject;
}

return categoryexemptSubjectCount(unfiltered, filtered, filterBy, filterObj);
}
case 'inclusionunchecked':
case '$inclusionunchecked': {
console.log('erro2 doing this instead');
const processedGroupName = groupName.slice(0, groupName.indexOf('unchecked'));
console.log('erro2 processGrpNm', processedGroupName);

let filterBy = filterObj[processedGroupName]
? filterObj[processedGroupName] : generateFilterBy(filterObj, processedGroupName);
filterBy = processedGroupName.includes('$') ? `$${filterBy}` : filterBy;
console.log('erro2 filBy', filterBy);
console.log('erro2 filObj', filterObj);

if (Object.prototype.hasOwnProperty.call(filterObj, processedGroupName)) {
return oldSubjectCountObject;
}

return categoryexemptSubjectCount(unfiltered, filtered, filterBy, filterObj);
}
default:
console.log('default');
return generateSubjectCounts(unfiltered);
}
};
Expand All @@ -640,23 +626,17 @@ const newHandleExplorerFilter = (selectedFilters, filterHashMap) => {
selectedFilters.forEach(([key, value], index) => {
switch (index) {
case 0: {
value.forEach((filterValue, filindex) => {
value.forEach((filterValue) => {
filteredDict = [
...filteredDict,
...filterHashMap.get(filterValue.toLowerCase()),
];
console.log(`error4 dict ${filindex}`, filteredDict);
console.log(`error4 hash ${filindex}`, filterHashMap.get(filterValue.toLowerCase()));
});
break;
}
case 1: {
if (key === 'inclusion') {
console.log('erro2 doing this!!!');
value.forEach((filterValue) => {
console.log('erro2 alternateFilly', alternateFilteredDict);
console.log('erro2 filteredDict', filteredDict);
console.log('erro2 compu', filteredDict.filter(([, thisValue]) => (thisValue[key] && thisValue[key][filterValue.toLowerCase()] ? thisValue[key][filterValue.toLowerCase()].length > 0 : false)));
alternateFilteredDict = [
...filteredDict.filter(([, thisValue]) => (thisValue[key]
&& thisValue[key][filterValue.toLowerCase()]
Expand All @@ -668,9 +648,6 @@ const newHandleExplorerFilter = (selectedFilters, filterHashMap) => {
break;
}
value.forEach((filterValue) => {
console.log('erro? alternateFilly', alternateFilteredDict);
console.log('erro? filteredDict', filteredDict);
console.log('error compu', filteredDict.filter(([, thisValue]) => thisValue[key] === filterValue.toLowerCase()));
alternateFilteredDict = [
...alternateFilteredDict,
...filteredDict.filter(([, thisValue]) => thisValue[key] === filterValue.toLowerCase()),
Expand All @@ -681,13 +658,8 @@ const newHandleExplorerFilter = (selectedFilters, filterHashMap) => {
}

default: {
console.log('erro2 in case 2');
if (key === 'inclusion') {
console.log('erro2 doing this!!!');
value.forEach((filterValue) => {
console.log('erro2 alternateFilly', alternateFilteredDict);
console.log('erro2 filteredDict', filteredDict);
console.log('erro2 compu', filteredDict.filter(([, thisValue]) => (thisValue[key] && thisValue[key][filterValue.toLowerCase()] ? thisValue[key][filterValue.toLowerCase()].length > 0 : false)));
alternateFilteredDict = [
...filteredDict.filter(([, thisValue]) => (thisValue[key]
&& thisValue[key][filterValue.toLowerCase()]
Expand All @@ -698,14 +670,10 @@ const newHandleExplorerFilter = (selectedFilters, filterHashMap) => {
break;
}
value.forEach((filterValue, filterIndex) => {
console.log('erro2 alternateFilly', alternateFilteredDict);
console.log('erro2 filteredDict', filteredDict);
console.log('erro2 compu', filteredDict.filter(([, thisValue]) => thisValue[key] === filterValue.toLowerCase()));
alternateFilteredDict = [
...filteredDict.filter(([, thisValue]) => thisValue[key] === filterValue.toLowerCase()),
];
if (filterIndex > 0) {
console.log('erro2 now!!');
alternateFilteredDict = [
...filteredDict,
];
Expand All @@ -716,7 +684,7 @@ const newHandleExplorerFilter = (selectedFilters, filterHashMap) => {
}
}
});
console.log('error4 final', filteredDict);

return Object.fromEntries(filteredDict);
};

Expand All @@ -741,7 +709,6 @@ const reducers = {

const processedFiltersObj = Object.fromEntries(processedFilters);
const filteredDict = newHandleExplorerFilter(processedFilters, state.filterHashMap);
console.log('error4 output', filteredDict, Object.keys(filteredDict).length);

const subjectCountObj = {
...state.subjectCountObject,
Expand All @@ -753,9 +720,6 @@ const reducers = {
state.oldSubjectCountObject,
),
};
console.log('erro2 sateSub', state.subjectCountObject);
console.log('erro2 subCntObj', subjectCountObj);
console.log('erro2 old.subCntObj', state.oldSubjectCountObject);

const finalCheckboxData = setSubjectCount(updatedCheckboxData, subjectCountObj || {});
return {
Expand Down

0 comments on commit 28d471d

Please sign in to comment.