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

fix(unified-search): load more than 5 items in folder filter #50129

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
43 changes: 34 additions & 9 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 @@ -128,7 +129,7 @@
v-bind="result" />
</ul>
<div class="result-footer">
<NcButton type="tertiary-no-background" @click="loadMoreResultsForProvider(providerResult.id)">
<NcButton type="tertiary-no-background" @click="loadMoreResultsForProvider(providerResult.providerId || providerResult.id)">
{{ t('core', 'Load more results') }}
<template #icon>
<IconDotsHorizontal :size="20" />
Expand Down Expand Up @@ -371,41 +372,44 @@
const newResults = []
const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers
const searchProvider = (provider, filters) => {
console.log('HMMMMMMM', provider)

Check failure on line 375 in core/src/components/UnifiedSearch/UnifiedSearchModal.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
const params = {
type: provider.id,
// Some filters such as In folder have identical id's with other providers such as Files
// To differentiate such in the UI we use an id that is different from the providerId.
// So, if providerId is present, use it, otherwise use the id, it indicates a plugin filter which has an id
// that might not match a valid search provider.
type: provider.providerId || provider.id,
query,
cursor: null,
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
}
}

if (this.providerResultLimit > 5) {
params.limit = this.providerResultLimit
console.log('Limiting search to', params.limit)

Check failure on line 404 in core/src/components/UnifiedSearch/UnifiedSearchModal.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
}

const request = unifiedSearch(params).request

request().then((response) => {
newResults.push({
id: provider.id,
providerId: provider.providerId ?? provider.id,
provider: provider.name,
inAppSearch: provider.inAppSearch,
results: response.data.ocs.data.entries,
Expand Down Expand Up @@ -493,16 +497,22 @@
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 })
},
loadMoreResultsForProvider(providerId) {
this.providerResultLimit += 5
this.filters = this.filters.filter(filter => filter.type !== 'provider')
// If user wants more result for a particular filter remove other filters???
this.filters = this.filters.filter(filter => filter.id === providerId)
const provider = this.providers.find(provider => provider.id === providerId)
this.addProviderFilter(provider, true)
},
addProviderFilter(providerFilter, loadMoreResultsForProvider = false) {
unifiedSearchLogger.info('Applying provider filter', { providerFilter, loadMoreResultsForProvider })
if (!providerFilter.id) return
if (providerFilter.isPluginFilter) {
providerFilter.callback()
Expand Down Expand Up @@ -549,6 +559,7 @@
if (filter.type === 'person') {
this.personFilterIsApplied = false
}
this.enableAllProviders()
break
}
}
Expand Down Expand Up @@ -587,6 +598,9 @@
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 @@ -647,6 +661,9 @@
const provider = this.filteredProviders[i]
if (provider.id === addFilterEvent.id) {
provider.name = addFilterEvent.filterUpdateText
if (addFilterEvent.providerId) {
provider.providerId = addFilterEvent.providerId
}
// Filters attached may only make sense with certain providers,
// So, find the provider attached, add apply the extra parameters to those providers only
const compatibleProviderIndex = this.providers.findIndex(provider => provider.id === addFilterEvent.id)
Expand Down Expand Up @@ -677,6 +694,14 @@

return flattenedArray
},
async providerIsCompatibleWithFilters(provider, filterIds) {
return filterIds.every(filterId => Object.prototype.hasOwnProperty.call(provider.filters ? provider.filters : {}, filterId))
},
async enableAllProviders() {
this.providers.forEach(async (_, index) => {
this.providers[index].disabled = false
})
},
},
})
</script>
Expand Down
Loading