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

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
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
45 changes: 25 additions & 20 deletions apps/files/src/plugins/search/folderSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@ function init() {

logger.info('Initializing unified search plugin: folder search from files app')
OCA.UnifiedSearch.registerFilterAction({
id: 'files',
id: 'in-folder',
appId: 'files',
label: t('files', 'In folder'),
icon: imagePath('files', 'app.svg'),
callback: () => {
const filepicker = getFilePickerBuilder('Pick plain text files')
.addMimeTypeFilter('httpd/unix-directory')
.allowDirectories(true)
.addButton({
label: 'Pick',
callback: (nodes: Node[]) => {
logger.info('Folder picked', { folder: nodes[0] })
const folder = nodes[0]
emit('nextcloud:unified-search:add-filter', {
id: 'files',
payload: folder,
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
filterParams: { path: folder.path },
})
},
})
.build()
filepicker.pick()
callback: (showFilePicker: boolean = true) => {
if (showFilePicker) {
const filepicker = getFilePickerBuilder('Pick plain text files')
.addMimeTypeFilter('httpd/unix-directory')
.allowDirectories(true)
.addButton({
label: 'Pick',
callback: (nodes: Node[]) => {
logger.info('Folder picked', { folder: nodes[0] })
const folder = nodes[0]
emit('nextcloud:unified-search:add-filter', {
id: 'in-folder',
appId: 'files',
payload: folder,
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
filterParams: { path: folder.path },
})
},
})
.build()
filepicker.pick()
} else {
logger.debug('Folder search callback was handled without showing the file picker, it might already be open')
}
},
})
}
Expand Down
17 changes: 14 additions & 3 deletions core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export default defineComponent({
const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers
const searchProvider = (provider, filters) => {
const params = {
type: provider.id,
type: provider.appId,
query,
cursor: null,
extraQueries: provider.extraParams,
Expand All @@ -397,13 +397,15 @@ export default defineComponent({

if (this.providerResultLimit > 5) {
params.limit = this.providerResultLimit
unifiedSearchLogger.debug('Limiting search to', params.limit)
}

const request = unifiedSearch(params).request

request().then((response) => {
newResults.push({
id: provider.id,
appId: provider.appId,
provider: provider.name,
inAppSearch: provider.inAppSearch,
results: response.data.ocs.data.entries,
Expand Down Expand Up @@ -500,14 +502,21 @@ export default defineComponent({
},
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.debug('Applying provider filter', { providerFilter, loadMoreResultsForProvider })
if (!providerFilter.id) return
if (providerFilter.isPluginFilter) {
providerFilter.callback()
// There is no way to know what should go into the callback currently
// Here we are passing isProviderFilterApplied (boolean) which is a flag sent to the plugin
// This is sent to the plugin so that depending on whether the filter is applied or not, the plugin can decide what to do
// TODO : In nextcloud/search, this should be a proper interface that the plugin can implement
const isProviderFilterApplied = this.filteredProviders.some(provider => provider.id === providerFilter.id)
providerFilter.callback(!isProviderFilterApplied)
}
this.providerResultLimit = loadMoreResultsForProvider ? this.providerResultLimit : 5
this.providerActionMenuIsOpen = false
Expand All @@ -521,6 +530,7 @@ export default defineComponent({
}
this.filteredProviders.push({
id: providerFilter.id,
appId: providerFilter.appId,
name: providerFilter.name,
icon: providerFilter.icon,
type: providerFilter.type || 'provider',
Expand Down Expand Up @@ -649,6 +659,7 @@ export default defineComponent({
this.updateDateFilter()
},
handlePluginFilter(addFilterEvent) {
unifiedSearchLogger.debug('Handling plugin filter', { addFilterEvent })
for (let i = 0; i < this.filteredProviders.length; i++) {
const provider = this.filteredProviders[i]
if (provider.id === addFilterEvent.id) {
Expand Down
4 changes: 1 addition & 3 deletions core/src/store/unified-search-external-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
*/
import { defineStore } from 'pinia'

export const useSearchStore = defineStore({
id: 'search',

export const useSearchStore = defineStore('search', {
state: () => ({
externalFilters: [],
}),
Expand Down
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.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

Loading