Skip to content

Commit

Permalink
Merge pull request #50128 from nextcloud/fix/49728/adapt-search-filte…
Browse files Browse the repository at this point in the history
…rs-correctly

feat: Adapt providers `disabled` property to match user applied filters
  • Loading branch information
nfebe authored Jan 13, 2025
2 parents 42c021f + 98a2d60 commit 9c717aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
25 changes: 19 additions & 6 deletions core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
provider.id concatenated to provider.name is used to create the item id, if same then, there should be an issue. -->
<NcActionButton v-for="provider in providers"
:key="`${provider.id}-${provider.name.replace(/\s/g, '')}`"
:disabled="provider.disabled"
@click="addProviderFilter(provider)">
<template #icon>
<img :src="provider.icon" class="filter-button__icon" alt="">
Expand Down Expand Up @@ -378,22 +379,18 @@ export default defineComponent({
extraQueries: provider.extraParams,
}

// This block of filter checks should be dynamic somehow and should be handled in
// nextcloud/search lib
if (filters.dateFilterIsApplied) {
if (provider.filters?.since && provider.filters?.until) {
params.since = this.dateFilter.startFrom
params.until = this.dateFilter.endAt
} else {
// Date filter is applied but provider does not support it, no need to search provider
return
}
}

if (filters.personFilterIsApplied) {
if (provider.filters?.person) {
params.person = this.personFilter.user
} else {
// Person filter is applied but provider does not support it, no need to search provider
return
}
}

Expand Down Expand Up @@ -493,6 +490,10 @@ export default defineComponent({
this.filters[existingPersonFilter].name = person.displayName
}

this.providers.forEach(async (provider, index) => {
this.providers[index].disabled = !(await this.providerIsCompatibleWithFilters(provider, ['person']))
})

this.debouncedFind(this.searchQuery)
unifiedSearchLogger.debug('Person filter applied', { person })
},
Expand Down Expand Up @@ -549,6 +550,7 @@ export default defineComponent({
if (filter.type === 'person') {
this.personFilterIsApplied = false
}
this.enableAllProviders()
break
}
}
Expand Down Expand Up @@ -587,6 +589,9 @@ export default defineComponent({
this.filters.push(this.dateFilter)
}
this.dateFilterIsApplied = true
this.providers.forEach(async (provider, index) => {
this.providers[index].disabled = !(await this.providerIsCompatibleWithFilters(provider, ['since', 'until']))
})
this.debouncedFind(this.searchQuery)
},
applyQuickDateRange(range) {
Expand Down Expand Up @@ -677,6 +682,14 @@ export default defineComponent({

return flattenedArray
},
async providerIsCompatibleWithFilters(provider, filterIds) {
return filterIds.every(filterId => provider.filters?.[filterId] !== undefined)
},
async enableAllProviders() {
this.providers.forEach(async (_, index) => {
this.providers[index].disabled = false
})
},
},
})
</script>
Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-unified-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unified-search.js.map

Large diffs are not rendered by default.

0 comments on commit 9c717aa

Please sign in to comment.