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

[stable29] feat: Adapt providers disabled property to match user applied filters #50153

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from 1 commit
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
25 changes: 19 additions & 6 deletions core/src/views/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -299,22 +300,18 @@ export default {
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 @@ -415,6 +412,10 @@ export default {
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)
console.debug('Person filter applied', person)
},
Expand Down Expand Up @@ -471,6 +472,7 @@ export default {
if (filter.type === 'person') {
this.personFilterIsApplied = false
}
this.enableAllProviders()
break
}
}
Expand Down Expand Up @@ -509,6 +511,9 @@ export default {
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 @@ -599,6 +604,14 @@ export default {

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
})
},
focusInput() {
this.$refs.searchInput.$el.children[0].children[0].focus()
},
Expand Down
Loading