Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion genData/genData.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function run() {
const dCopy = { ...d };
Object.keys(dCopy).forEach((key) => {
if (fieldValues[key]) {
const index = getRandomInt(0, fieldValues[key].length - 1);
const index = getRandomInt(0, fieldValues[key].length);
dCopy[key] = fieldValues[key][index];
} else {
switch (schema.items.properties[key].rawType) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gen3/guppy",
"version": "0.12.0",
"version": "0.13.0",
"description": "Server that support GraphQL queries on data from elasticsearch",
"main": "src/server/server.js",
"directories": {
Expand Down
5 changes: 4 additions & 1 deletion src/components/ConnectedFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ class ConnectedFilter extends React.Component {
const tabs = this.props.filterConfig.tabs.map(({ fields, searchFields }, index) => {
const sections = getFilterSections(fields, searchFields, fieldMapping, processedTabsOptions,
this.state.initialAggsData, this.state.adminAppliedPreFilters,
this.props.guppyConfig, this.arrayFields);
this.props.guppyConfig, this.arrayFields,
this.props.filterValuesToHide);
const filterStatus = this.state.filterStatusArray
? this.state.filterStatusArray[index] : null;
return (
Expand Down Expand Up @@ -336,6 +337,7 @@ ConnectedFilter.propTypes = {
hidden: PropTypes.bool,
userFilterFromURL: PropTypes.object,
hideEmptyFilterSection: PropTypes.bool,
filterValuesToHide: PropTypes.arrayOf(PropTypes.string),
};

ConnectedFilter.defaultProps = {
Expand All @@ -354,6 +356,7 @@ ConnectedFilter.defaultProps = {
hidden: false,
userFilterFromURL: {},
hideEmptyFilterSection: false,
filterValuesToHide: [],
};

export default ConnectedFilter;
15 changes: 12 additions & 3 deletions src/components/ConnectedFilter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getFilterGroupConfig = (filterConfig) => ({
})),
});

const getSingleFilterOption = (histogramResult, initHistogramRes) => {
const getSingleFilterOption = (histogramResult, initHistogramRes, filterValuesToHide) => {
if (!histogramResult || !histogramResult.histogram) {
throw new Error(`Error parsing field options ${JSON.stringify(histogramResult)}`);
}
Expand All @@ -28,8 +28,14 @@ const getSingleFilterOption = (histogramResult, initHistogramRes) => {
});
return rangeOptions;
}

const textOptions = histogramResult.histogram.map((item) => ({
let rawtextOptions = histogramResult.histogram;
// hide filterValuesToHide from filters
// filterValuesToHide added to guppyConfig in data-portal
if (filterValuesToHide.length > 0) {
rawtextOptions = histogramResult.histogram
.filter((item) => filterValuesToHide.indexOf(item.key) < 0);
}
const textOptions = rawtextOptions.map((item) => ({
text: item.key,
filterType: 'singleSelect',
count: item.count,
Expand Down Expand Up @@ -104,6 +110,7 @@ export const checkIsArrayField = (field, arrayFields) => {
export const getFilterSections = (
fields, searchFields, fieldMapping, tabsOptions,
initialTabsOptions, adminAppliedPreFilters, guppyConfig, arrayFields,
filterValuesToHide,
) => {
let searchFieldSections = [];

Expand All @@ -129,6 +136,7 @@ export const getFilterSections = (
selectedOptions = getSingleFilterOption(
tabsOptionsFiltered,
initialTabsOptions ? initialTabsOptions[field] : undefined,
filterValuesToHide,
);
}

Expand All @@ -155,6 +163,7 @@ export const getFilterSections = (
const defaultOptions = getSingleFilterOption(
tabsOptionsFiltered,
initialTabsOptions ? initialTabsOptions[field] : undefined,
filterValuesToHide,
);

const fieldIsArrayField = checkIsArrayField(field, arrayFields);
Expand Down
14 changes: 14 additions & 0 deletions stories/connectedFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ storiesOf('ConnectedFilter', module)
/>
);
})
.add('Filter Hidden "no data"', () => {
const processFilterAggsData = (aggsData) => aggsData;
return (
<ConnectedFilter
filterConfig={filterConfig}
guppyConfig={guppyConfig}
onFilterChange={action('filter change')}
fieldMapping={fieldMapping}
onProcessFilterAggsData={processFilterAggsData}
tierAccessLimit={guppyConfig.tierAccessLimit}
filterValuesToHide={["no data"]}
/>
);
})
.add('SwitchableFilterExample', () => (
<SwitchableFilterExample />
));