Skip to content

Commit 2c8fa3e

Browse files
authored
Merge pull request #42432 from nextcloud/42167-manual-backport
[stable28] Backport unified search improvments
2 parents db3d81a + 67a874a commit 2c8fa3e

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

core/src/components/UnifiedSearch/SearchableList.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
:label="labelText"
3333
trailing-button-icon="close"
3434
:show-trailing-button="searchTerm !== ''"
35+
@update:value="searchTermChanged"
3536
@trailing-button-click="clearSearch">
3637
<Magnify :size="20" />
3738
</NcTextField>
@@ -126,6 +127,9 @@ export default {
126127
this.clearSearch()
127128
this.opened = false
128129
},
130+
searchTermChanged(term) {
131+
this.$emit('search-term-change', term)
132+
},
129133
},
130134
}
131135
</script>

core/src/services/UnifiedSearchService.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
2424
import axios from '@nextcloud/axios'
25+
import { getCurrentUser } from '@nextcloud/auth'
2526

2627
/**
2728
* Create a cancel token
@@ -103,5 +104,20 @@ export async function getContacts({ searchTerm }) {
103104
const { data: { contacts } } = await axios.post(generateUrl('/contactsmenu/contacts'), {
104105
filter: searchTerm,
105106
})
107+
/*
108+
* Add authenticated user to list of contacts for search filter
109+
* If authtenicated user is searching/filtering, do not add them to the list
110+
*/
111+
if (!searchTerm) {
112+
let authenticatedUser = getCurrentUser()
113+
authenticatedUser = {
114+
id: authenticatedUser.uid,
115+
fullName: authenticatedUser.displayName,
116+
emailAddresses: [],
117+
}
118+
contacts.unshift(authenticatedUser)
119+
return contacts
120+
}
121+
106122
return contacts
107123
}

core/src/views/UnifiedSearchModal.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<SearchableList :label-text="t('core', 'Search people')"
5656
:search-list="userContacts"
5757
:empty-content-text="t('core', 'Not found')"
58+
@search-term-change="debouncedFilterContacts"
5859
@item-selected="applyPersonFilter">
5960
<template #trigger>
6061
<NcButton>
@@ -192,12 +193,13 @@ export default {
192193
filteredProviders: [],
193194
searching: false,
194195
searchQuery: '',
195-
placesFilter: '',
196+
placessearchTerm: '',
196197
dateTimeFilter: null,
197198
filters: [],
198199
results: [],
199200
contacts: [],
200201
debouncedFind: debounce(this.find, 300),
202+
debouncedFilterContacts: debounce(this.filterContacts, 300),
201203
showDateRangeModal: false,
202204
internalIsVisible: false,
203205
}
@@ -216,7 +218,7 @@ export default {
216218
217219
return {
218220
show: isEmptySearch || hasNoResults,
219-
text: this.searching && hasNoResults ? t('core', 'Searching …') : (isEmptySearch ? t('core', 'Start typing in search') : t('core', 'No matching results')),
221+
text: this.searching && hasNoResults ? t('core', 'Searching …') : (isEmptySearch ? t('core', 'Start typing to search') : t('core', 'No matching results')),
220222
icon: MagnifyIcon,
221223
}
222224
},
@@ -241,7 +243,7 @@ export default {
241243
this.providers = providers
242244
console.debug('Search providers', this.providers)
243245
})
244-
getContacts({ filter: '' }).then((contacts) => {
246+
getContacts({ searchTerm: '' }).then((contacts) => {
245247
this.contacts = this.mapContacts(contacts)
246248
console.debug('Contacts', this.contacts)
247249
})
@@ -361,7 +363,7 @@ export default {
361363
})
362364
},
363365
filterContacts(query) {
364-
getContacts({ filter: query }).then((contacts) => {
366+
getContacts({ searchTerm: query }).then((contacts) => {
365367
this.contacts = this.mapContacts(contacts)
366368
console.debug(`Contacts filtered by ${query}`, this.contacts)
367369
})

dist/core-unified-search.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-unified-search.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)