Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTCONTRIB-187] Added check for schema property to show/hide count in exposed filters select lists. #1150

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand All @@ -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)` }
})
}
}
Expand Down