Skip to content

Commit 3de73c6

Browse files
authored
Fix/guppy crash (#1427)
* debug * fix having undefined fields * update lock * update lock
1 parent 3ae8666 commit 3de73c6

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@fortawesome/free-brands-svg-icons": "^5.14.0",
1414
"@fortawesome/free-solid-svg-icons": "^5.2.0",
1515
"@fortawesome/react-fontawesome": "^0.2.0",
16-
"@gen3/guppy": "^0.17.0",
16+
"@gen3/guppy": "^0.17.1",
1717
"@gen3/ui-component": "^0.11.4",
1818
"@reactour/tour": "^2.12.0",
1919
"@upsetjs/venn.js": "^1.4.2",

src/GuppyDataExplorer/ExplorerFilter/index.jsx

+33-20
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,34 @@ class ExplorerFilter extends React.Component {
6060
return null;
6161
}
6262

63-
componentDidUpdate() {
63+
/**
64+
* Little helper function to apply accessibility filters to aggregation histogram results
65+
* @param {*} accessibleValues list of values that user has access to
66+
* @param {*} histogram raw histogram array
67+
* @returns modified histogram after applying accessibility filters
68+
*/
69+
applyAccessibleFilter = (accessibleValues, histogram) => {
70+
if (!Array.isArray(histogram)) {
71+
throw new Error('Invalid histogram format');
72+
}
73+
return histogram.filter(({ key }) => {
74+
const accessible = accessibleValues.includes(key);
75+
switch (this.state.selectedAccessFilter) {
76+
case 'all-data':
77+
return true; // always show all items if 'all-data'
78+
case 'with-access':
79+
return accessible; // only show accessible items if 'with-access'
80+
case 'without-access':
81+
return !accessible; // only show unaccessible items if 'without-access'
82+
default:
83+
throw new Error('Invalid access filter option');
84+
}
85+
})
86+
.map(({ key, count }) => ({
87+
key,
88+
count,
89+
accessible: accessibleValues.includes(key),
90+
}));
6491
}
6592

6693
/**
@@ -87,26 +114,12 @@ class ExplorerFilter extends React.Component {
87114
// if the field is in accessibleFieldObject, add "accessible=false"
88115
// to those items which are unaccessible
89116
const accessibleValues = this.props.accessibleFieldObject[field];
90-
const newHistogram = aggsData[field].histogram
91-
.filter(({ key }) => {
92-
const accessible = accessibleValues.includes(key);
93-
switch (this.state.selectedAccessFilter) {
94-
case 'all-data':
95-
return true; // always show all items if 'all-data'
96-
case 'with-access':
97-
return accessible; // only show accessible items if 'with-access'
98-
case 'without-access':
99-
return !accessible; // only show unaccessible items if 'without-access'
100-
default:
101-
throw new Error('Invalid access filter option');
102-
}
103-
})
104-
.map(({ key, count }) => ({
105-
key,
106-
count,
107-
accessible: accessibleValues.includes(key),
108-
}));
117+
const newHistogram = this.applyAccessibleFilter(accessibleValues, aggsData[field].histogram);
109118
res[field] = { histogram: newHistogram };
119+
if (Array.isArray(aggsData[field].asTextHistogram)) {
120+
const newAsTextHistogram = this.applyAccessibleFilter(accessibleValues, aggsData[field].asTextHistogram);
121+
res[field] = { ...res[field], asTextHistogram: newAsTextHistogram };
122+
}
110123
return res;
111124
}, {});
112125
return newAggsData;

0 commit comments

Comments
 (0)