Make share results distinguishable if there are more than one with the exact same display name

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-09-23 12:39:53 +02:00
parent 48865b30f5
commit defdaf1e18
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
1 changed files with 21 additions and 1 deletions

View File

@ -240,7 +240,27 @@ export default {
// if there is a condition specified, filter it // if there is a condition specified, filter it
const externalResults = this.externalResults.filter(result => !result.condition || result.condition(this)) const externalResults = this.externalResults.filter(result => !result.condition || result.condition(this))
this.suggestions = exactSuggestions.concat(suggestions).concat(externalResults).concat(lookupEntry) const allSuggestions = exactSuggestions.concat(suggestions).concat(externalResults).concat(lookupEntry)
// Count occurances of display names in order to provide a distinguishable description if needed
const nameCounts = allSuggestions.reduce((nameCounts, result) => {
if (!result.displayName) {
return nameCounts
}
if (!nameCounts[result.displayName]) {
nameCounts[result.displayName] = 0
}
nameCounts[result.displayName]++
return nameCounts
}, {})
this.suggestions = allSuggestions.map(item => {
// Make sure that items with duplicate displayName get the shareWith applied as a description
if (nameCounts[item.displayName] > 1 && !item.desc) {
return { ...item, desc: item.shareWith }
}
return item
})
this.loading = false this.loading = false
console.info('suggestions', this.suggestions) console.info('suggestions', this.suggestions)