Skip to content

Commit

Permalink
fix(unified-search): Prevent multiple file picker triggers in in-fold…
Browse files Browse the repository at this point in the history
…er search

Signed-off-by: nfebe <[email protected]>
  • Loading branch information
nfebe committed Jan 29, 2025
1 parent 9d0238b commit 1cde688
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
44 changes: 24 additions & 20 deletions apps/files/src/plugins/search/folderSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,30 @@ function init() {
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: 'in-folder',
appId: '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
7 changes: 6 additions & 1 deletion core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,12 @@ export default defineComponent({
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 Down

0 comments on commit 1cde688

Please sign in to comment.