Skip to content

Commit

Permalink
Add app-based filtering to global search
Browse files Browse the repository at this point in the history
Emit search queries from the global search modal that would trigger
list filtering in various apps that support it.

Signed-off-by: fenn-cs <[email protected]>
Signed-off-by: nextcloud-command <[email protected]>
  • Loading branch information
nfebe authored and AndyScherzinger committed Nov 23, 2023
1 parent c5caae1 commit b0e28a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
26 changes: 24 additions & 2 deletions core/src/views/GlobalSearchModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<NcModal v-if="isVisible"
id="global-search"
<NcModal id="global-search"
ref="globalSearchModal"
:name="t('core', 'Global search')"
:show.sync="isVisible"
:clear-view-delay="0"
Expand Down Expand Up @@ -115,6 +115,14 @@
</div>
</div>
</div>
<div v-if="supportFiltering()" class="global-search-modal__results">
<NcButton @click="closeModal">
{{ t('core', 'Filter in current view') }}
<template #icon>
<FilterIcon :size="20" />
</template>
</NcButton>
</div>
</div>
</NcModal>
</template>
Expand All @@ -125,6 +133,7 @@ import AccountGroup from 'vue-material-design-icons/AccountGroup.vue'
import CalendarRangeIcon from 'vue-material-design-icons/CalendarRange.vue'
import CustomDateRangeModal from '../components/GlobalSearch/CustomDateRangeModal.vue'
import DotsHorizontalIcon from 'vue-material-design-icons/DotsHorizontal.vue'
import FilterIcon from 'vue-material-design-icons/Filter.vue'
import FilterChip from '../components/GlobalSearch/SearchFilterChip.vue'
import FlaskEmpty from 'vue-material-design-icons/FlaskEmpty.vue'
import ListBox from 'vue-material-design-icons/ListBox.vue'
Expand All @@ -140,6 +149,7 @@ import SearchableList from '../components/GlobalSearch/SearchableList.vue'
import SearchResult from '../components/GlobalSearch/SearchResult.vue'
import debounce from 'debounce'
import { emit } from '@nextcloud/event-bus'
import { getProviders, search as globalSearch, getContacts } from '../services/GlobalSearchService.js'
export default {
Expand All @@ -150,6 +160,7 @@ export default {
CalendarRangeIcon,
CustomDateRangeModal,
DotsHorizontalIcon,
FilterIcon,
FilterChip,
FlaskEmpty,
ListBox,
Expand Down Expand Up @@ -227,6 +238,9 @@ export default {
this.results = []
return
}
if (this.supportFiltering()) {
emit('nextcloud:unified-search.search', { query })
}
const newResults = []
const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers
const searchProvider = (provider, filters) => {
Expand Down Expand Up @@ -490,8 +504,16 @@ export default {
this.updateDateFilter()
},
closeModal() {
this.$refs.globalSearchModal.close()
this.searchQuery = ''
},
supportFiltering() {
/* Hard coded apps for the moment this would be improved in coming updates. */
const providerPaths = ['/settings/users', '/apps/files', '/apps/deck']
const currentPath = window.location.pathname.replace('/index.php', '')
const containsProvider = providerPaths.some(path => currentPath.includes(path))
return containsProvider
},
},
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions dist/core-global-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-global-search.js.map

Large diffs are not rendered by default.

0 comments on commit b0e28a8

Please sign in to comment.