Skip to content

Commit fc45650

Browse files
committed
fix(unified-search): Prevent multiple file picker triggers in in-folder search
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent d36fc17 commit fc45650

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

apps/files/src/plugins/search/folderSearch.ts

+24-20
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,30 @@ function init() {
2525
appId: 'files',
2626
label: t('files', 'In folder'),
2727
icon: imagePath('files', 'app.svg'),
28-
callback: () => {
29-
const filepicker = getFilePickerBuilder('Pick plain text files')
30-
.addMimeTypeFilter('httpd/unix-directory')
31-
.allowDirectories(true)
32-
.addButton({
33-
label: 'Pick',
34-
callback: (nodes: Node[]) => {
35-
logger.info('Folder picked', { folder: nodes[0] })
36-
const folder = nodes[0]
37-
emit('nextcloud:unified-search:add-filter', {
38-
id: 'in-folder',
39-
appId: 'files',
40-
payload: folder,
41-
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
42-
filterParams: { path: folder.path },
43-
})
44-
},
45-
})
46-
.build()
47-
filepicker.pick()
28+
callback: (showFilePicker: boolean = true) => {
29+
if (showFilePicker) {
30+
const filepicker = getFilePickerBuilder('Pick plain text files')
31+
.addMimeTypeFilter('httpd/unix-directory')
32+
.allowDirectories(true)
33+
.addButton({
34+
label: 'Pick',
35+
callback: (nodes: Node[]) => {
36+
logger.info('Folder picked', { folder: nodes[0] })
37+
const folder = nodes[0]
38+
emit('nextcloud:unified-search:add-filter', {
39+
id: 'in-folder',
40+
appId: 'files',
41+
payload: folder,
42+
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
43+
filterParams: { path: folder.path },
44+
})
45+
},
46+
})
47+
.build()
48+
filepicker.pick()
49+
} else {
50+
logger.debug('Folder search callback was handled without showing the file picker, it might already be open')
51+
}
4852
},
4953
})
5054
}

core/src/components/UnifiedSearch/UnifiedSearchModal.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,12 @@ export default defineComponent({
512512
unifiedSearchLogger.info('Applying provider filter', { providerFilter, loadMoreResultsForProvider })
513513
if (!providerFilter.id) return
514514
if (providerFilter.isPluginFilter) {
515-
providerFilter.callback()
515+
// There is no way to know what should go into the callback currently
516+
// Here we are passing isProviderFilterApplied (boolean) which is a flag sent to the plugin
517+
// This is sent to the plugin so that depending on whether the filter is applied or not, the plugin can decide what to do
518+
// TODO : In nextcloud/search, this should be a proper interface that the plugin can implement
519+
const isProviderFilterApplied = this.filteredProviders.some(provider => provider.id === providerFilter.id)
520+
providerFilter.callback(!isProviderFilterApplied)
516521
}
517522
this.providerResultLimit = loadMoreResultsForProvider ? this.providerResultLimit : 5
518523
this.providerActionMenuIsOpen = false

0 commit comments

Comments
 (0)