fix(unified-search): Prevent multiple file picker triggers in in-folder search

Signed-off-by: nfebe <fenn25.fn@gmail.com>
This commit is contained in:
nfebe 2025-01-27 20:06:09 +01:00 committed by Andy Scherzinger
parent 6bb24885d6
commit 6e2e35f641
2 changed files with 30 additions and 21 deletions

View file

@ -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')
}
},
})
}

View file

@ -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