From defdaf1e183748c5c5ea58e84206e6d55463c890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 23 Sep 2020 12:39:53 +0200 Subject: [PATCH] Make share results distinguishable if there are more than one with the exact same display name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../src/components/SharingInput.vue | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/src/components/SharingInput.vue b/apps/files_sharing/src/components/SharingInput.vue index 06b39db4fc..5a23444b4a 100644 --- a/apps/files_sharing/src/components/SharingInput.vue +++ b/apps/files_sharing/src/components/SharingInput.vue @@ -240,7 +240,27 @@ export default { // if there is a condition specified, filter it 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 console.info('suggestions', this.suggestions)