From 0b8b621fa09b238272a0f93159a43b52cd3f9047 Mon Sep 17 00:00:00 2001 From: nfebe Date: Mon, 27 Jan 2025 20:06:09 +0100 Subject: [PATCH] fix(unified-search): Prevent multiple file picker triggers in in-folder search Signed-off-by: nfebe --- apps/files/src/plugins/search/folderSearch.ts | 44 ++++++++++--------- .../UnifiedSearch/UnifiedSearchModal.vue | 7 ++- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/apps/files/src/plugins/search/folderSearch.ts b/apps/files/src/plugins/search/folderSearch.ts index 4ba7e34a40ef2..33dae31995cdb 100644 --- a/apps/files/src/plugins/search/folderSearch.ts +++ b/apps/files/src/plugins/search/folderSearch.ts @@ -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') + } }, }) } diff --git a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue index d75d54756acc5..a2646780a137b 100644 --- a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue +++ b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue @@ -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