From 392a0e2ad7382791e43994ea327ee76cd7c97828 Mon Sep 17 00:00:00 2001 From: Nicolas Haase Date: Wed, 16 Feb 2022 18:47:51 +1000 Subject: [PATCH] [HEALTHTRAN-442] Added check for schema property to show/hide count in exposed filters select lists. --- .../landing-page/lib/content-collection.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/ripple-nuxt-tide/modules/landing-page/lib/content-collection.js b/packages/ripple-nuxt-tide/modules/landing-page/lib/content-collection.js index 80b936974..f9664db11 100644 --- a/packages/ripple-nuxt-tide/modules/landing-page/lib/content-collection.js +++ b/packages/ripple-nuxt-tide/modules/landing-page/lib/content-collection.js @@ -711,6 +711,20 @@ module.exports = class ContentCollection { return returnFilterField } + getExposedFilterFromModelName (model) { + let returnFilter = null + const filters = this.config?.interface?.filters?.fields + if (filters) { + for (let i = 0; i < filters.length; i++) { + if (filters[i].options.model === model) { + returnFilter = filters[i] + break + } + } + } + return returnFilter + } + getExposedFilterSubmissionGroup () { let returnSubmissionGroup = null const fields = [] @@ -963,7 +977,8 @@ module.exports = class ContentCollection { formData.schema.groups.forEach(group => { group.fields.forEach(field => { if (field.model === model) { - let values = this.getAggregatedFilterValues(aggregations[model].buckets, state[model]) + let dataField = this.getExposedFilterFromModelName(model) + let values = this.getAggregatedFilterValues(aggregations[model].buckets, state[model], dataField) field.values = values const disableField = (values.length === 0) disableFieldCallback(field, disableField) @@ -973,18 +988,19 @@ module.exports = class ContentCollection { }) } - getAggregatedFilterValues (buckets, stateValue) { + getAggregatedFilterValues (buckets, stateValue, dataField) { let returnValues = [] + let hideCount = (dataField['elasticsearch-aggregation-show-count'] === false) if (buckets.length > 0) { // Has Aggregations returnValues = buckets.map(({ key, doc_count: count }) => { - return { id: key, name: `${key} (${count})` } + return hideCount ? { id: key, name: key } : { id: key, name: `${key} (${count})` } }) } else { // No result aggregations - return state value if (stateValue && Array.isArray(stateValue)) { returnValues = stateValue.map(item => { - return { id: item, name: `${item} (0)` } + return hideCount ? { id: item, name: item } : { id: item, name: `${item} (0)` } }) } }