Skip to content

Commit c880248

Browse files
committed
feat: Adapt provider disabled status to applied filters
Some filters are only available for certain providers, the UI should give the user a hint to what providers such filters are available in. Currently, if a filter (date or person) is not support by an a provider, the provider is blurred out in the places dropdown. Signed-off-by: nfebe <[email protected]>
1 parent 184e715 commit c880248

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

core/src/components/UnifiedSearch/UnifiedSearchModal.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
provider.id concatenated to provider.name is used to create the item id, if same then, there should be an issue. -->
3535
<NcActionButton v-for="provider in providers"
3636
:key="`${provider.id}-${provider.name.replace(/\s/g, '')}`"
37+
:disabled="provider.disabled"
3738
@click="addProviderFilter(provider)">
3839
<template #icon>
3940
<img :src="provider.icon" class="filter-button__icon" alt="">
@@ -378,22 +379,18 @@ export default defineComponent({
378379
extraQueries: provider.extraParams,
379380
}
380381
382+
// This block of filter checks should be dynamic somehow and should be handled in
383+
// nextcloud/search lib
381384
if (filters.dateFilterIsApplied) {
382385
if (provider.filters?.since && provider.filters?.until) {
383386
params.since = this.dateFilter.startFrom
384387
params.until = this.dateFilter.endAt
385-
} else {
386-
// Date filter is applied but provider does not support it, no need to search provider
387-
return
388388
}
389389
}
390390
391391
if (filters.personFilterIsApplied) {
392392
if (provider.filters?.person) {
393393
params.person = this.personFilter.user
394-
} else {
395-
// Person filter is applied but provider does not support it, no need to search provider
396-
return
397394
}
398395
}
399396
@@ -493,6 +490,10 @@ export default defineComponent({
493490
this.filters[existingPersonFilter].name = person.displayName
494491
}
495492
493+
this.providers.forEach(async (provider, index) => {
494+
this.providers[index].disabled = !(await this.providerIsCompatibleWithFilters(provider, ['person']))
495+
})
496+
496497
this.debouncedFind(this.searchQuery)
497498
unifiedSearchLogger.debug('Person filter applied', { person })
498499
},
@@ -587,6 +588,9 @@ export default defineComponent({
587588
this.filters.push(this.dateFilter)
588589
}
589590
this.dateFilterIsApplied = true
591+
this.providers.forEach(async (provider, index) => {
592+
this.providers[index].disabled = !(await this.providerIsCompatibleWithFilters(provider, ['since', 'until']))
593+
})
590594
this.debouncedFind(this.searchQuery)
591595
},
592596
applyQuickDateRange(range) {
@@ -677,6 +681,9 @@ export default defineComponent({
677681
678682
return flattenedArray
679683
},
684+
async providerIsCompatibleWithFilters(provider, filterIds) {
685+
return filterIds.every(filterId => Object.prototype.hasOwnProperty.call(provider.filters, filterId))
686+
},
680687
},
681688
})
682689
</script>

0 commit comments

Comments
 (0)