From 97aa3a284c6b764d20c60e3c14effa8b78e916d6 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Sat, 17 Feb 2024 23:27:12 +0100 Subject: [PATCH] feat(files): restore unified search filtering in files view The unified search emits, search events that other apps can subscribe to and react however they want to search queries, following 4b55594f55ce4146ed93c50f71e6204a57d29612 and prior updates to migrate the Files app ui to vue.js that feature was broken. This commit reintroduces the feature using the current `FileList` implementation. This commit also adds some logging to an empty exception handler. Resolve : https://github.com/nextcloud/server/issues/43365 Signed-off-by: fenn-cs (cherry picked from commit 29c37af40c7c28ef17da4b9565e8c30fab27fec4) Signed-off-by: Christopher Ng --- apps/files/src/legacy/filelistSearch.js | 42 ----------------------- apps/files/src/views/FilesList.vue | 44 ++++++++++++++++++------- core/src/views/UnifiedSearchModal.vue | 10 +++++- 3 files changed, 42 insertions(+), 54 deletions(-) delete mode 100644 apps/files/src/legacy/filelistSearch.js diff --git a/apps/files/src/legacy/filelistSearch.js b/apps/files/src/legacy/filelistSearch.js deleted file mode 100644 index 9512f47eccc35..0000000000000 --- a/apps/files/src/legacy/filelistSearch.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * @copyright Copyright (c) 2021 Julius Härtl - * - * @author Julius Härtl - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -import { subscribe } from '@nextcloud/event-bus' - -(function() { - - const FilesPlugin = { - attach(fileList) { - subscribe('nextcloud:unified-search.search', ({ query }) => { - fileList.setFilter(query) - }) - subscribe('nextcloud:unified-search.reset', () => { - this.query = null - fileList.setFilter('') - }) - - }, - } - - window.OC.Plugins.register('OCA.Files.FileList', FilesPlugin) - -})() diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index 641dcf78c541b..d6e1e26a4e88b 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -80,8 +80,7 @@ - + { + return node.attributes.basename.toLowerCase().includes(this.filterText.toLowerCase()) + }) + console.debug('Files view filtered', filteredDirContent) + } + const customColumn = (this.currentView?.columns || []) .find(column => column.id === this.sortingMode) @@ -304,7 +314,7 @@ export default defineComponent({ } return orderBy( - [...this.dirContents], + filteredDirContent, ...this.sortingParameters, ) }, @@ -348,7 +358,7 @@ export default defineComponent({ return { ...this.$route, query: { dir } } }, - shareAttributes(): number[]|undefined { + shareAttributes(): number[] | undefined { if (!this.currentFolder?.attributes?.['share-types']) { return undefined } @@ -364,7 +374,7 @@ export default defineComponent({ } return this.t('files', 'Shared') }, - shareButtonType(): Type|null { + shareButtonType(): Type | null { if (!this.shareAttributes) { return null } @@ -440,6 +450,8 @@ export default defineComponent({ mounted() { this.fetchContent() subscribe('files:node:updated', this.onUpdatedNode) + subscribe('nextcloud:unified-search.search', this.onSearch) + subscribe('nextcloud:unified-search.reset', this.onSearch) }, unmounted() { @@ -556,7 +568,9 @@ export default defineComponent({ showError(this.t('files', 'Error during upload: {message}', { message })) return } - } catch (error) {} + } catch (error) { + logger.error('Error while parsing', { error }) + } // Finally, check the status code if we have one if (status !== 0) { @@ -577,7 +591,15 @@ export default defineComponent({ this.fetchContent() } }, - + /** + * Handle search event from unified search. + * + * @param searchEvent is event object. + */ + onSearch: debounce(function(searchEvent) { + console.debug('Files app handling search event from unified search...', searchEvent) + this.filterText = searchEvent.query + }, 500), openSharingSidebar() { if (!this.currentFolder) { logger.debug('No current folder found for opening sharing sidebar') @@ -589,7 +611,6 @@ export default defineComponent({ } sidebarAction.exec(this.currentFolder, this.currentView, this.currentFolder.path) }, - toggleGridView() { this.userConfigStore.update('grid_view', !this.userConfig.grid_view) }, @@ -622,7 +643,8 @@ $navigationToggleSize: 50px; // Align with the navigation toggle icon margin: $margin $margin $margin $navigationToggleSize; max-width: 100%; - > * { + + >* { // Do not grow or shrink (horizontally) // Only the breadcrumbs shrinks flex: 0 0; @@ -630,6 +652,7 @@ $navigationToggleSize: 50px; &-share-button { color: var(--color-text-maxcontrast) !important; + &--shared { color: var(--color-main-text) !important; } @@ -646,5 +669,4 @@ $navigationToggleSize: 50px; margin: auto; } } - diff --git a/core/src/views/UnifiedSearchModal.vue b/core/src/views/UnifiedSearchModal.vue index 004005b57d900..f09d2325537a8 100644 --- a/core/src/views/UnifiedSearchModal.vue +++ b/core/src/views/UnifiedSearchModal.vue @@ -237,6 +237,14 @@ export default { }, watch: { isVisible(value) { + if (value) { + /* + * Before setting the search UI to visible, reset previous search event emissions. + * This allows apps to restore defaults after "Filter in current view" if the user opens the search interface once more. + * Additionally, it's a new search, so it's better to reset all previous events emitted. + */ + emit('nextcloud:unified-search.reset', { query: '' }) + } this.internalIsVisible = value }, internalIsVisible(value) { @@ -265,9 +273,9 @@ export default { if (query.length === 0) { this.results = [] this.searching = false + emit('nextcloud:unified-search.reset', { query }) return } - // Event should probably be refactored at some point to used nextcloud:unified-search.search emit('nextcloud:unified-search.search', { query }) const newResults = [] const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers