Skip to content

Commit

Permalink
Use unique key to prevent email component reuse
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
(cherry picked from commit fc03a93)
  • Loading branch information
Pytal committed Jun 27, 2022
1 parent 3008908 commit e7e837d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<Actions
class="actions-email"
:aria-label="t('settings', 'Email options')"
:disabled="deleteDisabled"
:force-menu="true">
<ActionButton
:aria-label="deleteEmailLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
<span v-else>
{{ primaryEmail.value || t('settings', 'No email address set') }}
</span>
<!-- TODO use unique key for additional email when uniqueness can be guaranteed, see https://github.com/nextcloud/server/issues/26866 -->
<Email v-for="(additionalEmail, index) in additionalEmails"
:key="index"
:key="additionalEmail.key"
:index="index"
:scope.sync="additionalEmail.scope"
:email.sync="additionalEmail.value"
Expand Down Expand Up @@ -77,7 +78,7 @@ export default {

data() {
return {
additionalEmails,
additionalEmails: additionalEmails.map(properties => ({ ...properties, key: this.generateUniqueKey() })),
displayNameChangeSupported,
primaryEmail,
isValidForm: true,
Expand Down Expand Up @@ -110,7 +111,7 @@ export default {
methods: {
onAddAdditionalEmail() {
if (this.$refs.form?.checkValidity()) {
this.additionalEmails.push({ value: '', scope: DEFAULT_ADDITIONAL_EMAIL_SCOPE })
this.additionalEmails.push({ value: '', scope: DEFAULT_ADDITIONAL_EMAIL_SCOPE, key: this.generateUniqueKey() })
this.$nextTick(() => this.updateFormValidity())
}
},
Expand Down Expand Up @@ -172,6 +173,10 @@ export default {
updateFormValidity() {
this.isValidForm = this.$refs.form?.checkValidity()
},

generateUniqueKey() {
return Math.random().toString(36).substring(2)
},
},
}
</script>
Expand Down

0 comments on commit e7e837d

Please sign in to comment.