Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Backport unified search improvments #42432

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/components/UnifiedSearch/SearchableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:label="labelText"
trailing-button-icon="close"
:show-trailing-button="searchTerm !== ''"
@update:value="searchTermChanged"
@trailing-button-click="clearSearch">
<Magnify :size="20" />
</NcTextField>
Expand Down Expand Up @@ -126,6 +127,9 @@ export default {
this.clearSearch()
this.opened = false
},
searchTermChanged(term) {
this.$emit('search-term-change', term)
},
},
}
</script>
Expand Down
16 changes: 16 additions & 0 deletions core/src/services/UnifiedSearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import { generateOcsUrl, generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { getCurrentUser } from '@nextcloud/auth'

/**
* Create a cancel token
Expand Down Expand Up @@ -103,5 +104,20 @@ export async function getContacts({ searchTerm }) {
const { data: { contacts } } = await axios.post(generateUrl('/contactsmenu/contacts'), {
filter: searchTerm,
})
/*
* Add authenticated user to list of contacts for search filter
* If authtenicated user is searching/filtering, do not add them to the list
*/
if (!searchTerm) {
let authenticatedUser = getCurrentUser()
authenticatedUser = {
id: authenticatedUser.uid,
fullName: authenticatedUser.displayName,
emailAddresses: [],
}
contacts.unshift(authenticatedUser)
return contacts
}

return contacts
}
10 changes: 6 additions & 4 deletions core/src/views/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<SearchableList :label-text="t('core', 'Search people')"
:search-list="userContacts"
:empty-content-text="t('core', 'Not found')"
@search-term-change="debouncedFilterContacts"
@item-selected="applyPersonFilter">
<template #trigger>
<NcButton>
Expand Down Expand Up @@ -192,12 +193,13 @@ export default {
filteredProviders: [],
searching: false,
searchQuery: '',
placesFilter: '',
placessearchTerm: '',
dateTimeFilter: null,
filters: [],
results: [],
contacts: [],
debouncedFind: debounce(this.find, 300),
debouncedFilterContacts: debounce(this.filterContacts, 300),
showDateRangeModal: false,
internalIsVisible: false,
}
Expand All @@ -216,7 +218,7 @@ export default {

return {
show: isEmptySearch || hasNoResults,
text: this.searching && hasNoResults ? t('core', 'Searching …') : (isEmptySearch ? t('core', 'Start typing in search') : t('core', 'No matching results')),
text: this.searching && hasNoResults ? t('core', 'Searching …') : (isEmptySearch ? t('core', 'Start typing to search') : t('core', 'No matching results')),
icon: MagnifyIcon,
}
},
Expand All @@ -241,7 +243,7 @@ export default {
this.providers = providers
console.debug('Search providers', this.providers)
})
getContacts({ filter: '' }).then((contacts) => {
getContacts({ searchTerm: '' }).then((contacts) => {
this.contacts = this.mapContacts(contacts)
console.debug('Contacts', this.contacts)
})
Expand Down Expand Up @@ -361,7 +363,7 @@ export default {
})
},
filterContacts(query) {
getContacts({ filter: query }).then((contacts) => {
getContacts({ searchTerm: query }).then((contacts) => {
this.contacts = this.mapContacts(contacts)
console.debug(`Contacts filtered by ${query}`, this.contacts)
})
Expand Down
4 changes: 2 additions & 2 deletions dist/core-unified-search.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading