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

Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You could put following as your config files:
"auth_filter_field": "${AUTH_FILTER_FIELD}",
"aggs_include_missing_data": true, // optional, by default true, this boolean decide whether elasticsearch aggregation should return missing data in result
"missing_data_alias": "no data", // optional, only valid if `aggs_include_missing_data` is true, guppy will alias missing data into this keyword during aggregation. By default it's set to `no data`.
"missing_data_display_in_filters": true, // optional, only valid if `aggs_include_missing_data` is true, if false guppy will not display missing data category in filters.
}
```

Expand Down
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
1 change: 1 addition & 0 deletions src/server/__mocks__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config = {
authFilterField: 'gen3_resource_path',
aggregationIncludeMissingData: true,
missingDataAlias: 'no data',
missingDataInFilters: true,
},

port: 3000,
Expand Down
1 change: 1 addition & 0 deletions src/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const config = {
authFilterField: inputConfig.auth_filter_field || 'auth_resource_path',
aggregationIncludeMissingData: typeof inputConfig.aggs_include_missing_data === 'undefined' ? true : inputConfig.aggs_include_missing_data,
missingDataAlias: inputConfig.missing_data_alias || 'no data',
missingDataInFilters: typeof inputConfig.missing_data_display_in_filters === 'undefined' ? true : inputConfig.missing_data_display_in_filters,
},
port: 80,
path: '/graphql',
Expand Down
7 changes: 5 additions & 2 deletions src/server/es/aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,9 @@ export const textAggregation = async (
let missingAlias = {};
// don't add missing alias to numeric field by default
// since the value of missing alias is a string
if (config.esConfig.aggregationIncludeMissingData && !isNumericField) {
if (config.esConfig.aggregationIncludeMissingData
&& !isNumericField
&& config.esConfig.missingDataInFilters) {
Copy link
Contributor

@mfshao mfshao Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why put this in backend? how is this logic different with just using aggregationIncludeMissingData?

if you put missingDataInFilters as false in here, it is essentially the same as using aggregationIncludeMissingData = false isn't it? and the charts will also has no missing data in the results returned from aggregation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i was so excited to get things working i missed this

I got it working in src/components/ConnectedFilter/utils.js file, how would i read the config flags from this location? or do i need to set a variable in data portal and pass it down? is src/components/ConnectedFilter/utils.js the best location for this functionality?

missingAlias = { missing: config.esConfig.missingDataAlias };
}
const aggsName = `${field}Aggs`;
Expand Down Expand Up @@ -652,7 +654,8 @@ export const textAggregation = async (
finalResults = finalResults.sort((e1, e2) => e2.count - e1.count);

// make the missing data bucket to the bottom of the list
if (config.esConfig.aggregationIncludeMissingData) {
if (config.esConfig.aggregationIncludeMissingData
&& config.esConfig.missingDataInFilters) {
const missingDataIndex = finalResults
.findIndex((b) => b.key === config.esConfig.missingDataAlias);
const missingDataItem = finalResults.find((b) => b.key === config.esConfig.missingDataAlias);
Expand Down