From 87e80be1bfb875e7d5081be1fd919d93c0717dbb Mon Sep 17 00:00:00 2001 From: Cleopatra Enjeck M Date: Mon, 13 May 2024 12:45:16 +0100 Subject: [PATCH] enh: refactor items for searching users and groups Signed-off-by: Cleopatra Enjeck M --- cypress/e2e/tables-table.cy.js | 2 +- src/modules/modals/EditContext.vue | 2 +- src/modules/sidebar/partials/ShareForm.vue | 28 ++++++------- .../ncContextResource/ResourceSharees.vue | 16 +++----- .../NcUserAndGroupPicker.vue | 11 ++---- src/shared/constants.js | 12 ++++++ src/shared/mixins/searchUserGroup.js | 9 +++-- src/shared/mixins/shareTypesMixin.js | 39 ------------------- src/store/store.js | 4 +- 9 files changed, 43 insertions(+), 80 deletions(-) delete mode 100644 src/shared/mixins/shareTypesMixin.js diff --git a/cypress/e2e/tables-table.cy.js b/cypress/e2e/tables-table.cy.js index fc4d6e54f..7189afcb4 100644 --- a/cypress/e2e/tables-table.cy.js +++ b/cypress/e2e/tables-table.cy.js @@ -99,7 +99,7 @@ describe('Manage a table', () => { cy.get('[data-cy="editTableModal"]').should('not.exist') cy.get('[data-cy="transferTableModal"]').should('be.visible') cy.get('[data-cy="transferTableModal"] input[type="search"]').clear().type(targetUserTransfer.userId) - cy.get(`.vs__dropdown-menu [user="${targetUserTransfer.userId}"]`).click() + cy.get(`.vs__dropdown-menu [id="${targetUserTransfer.userId}"]`).click() cy.get('[data-cy="transferTableButton"]').should('be.enabled').click() cy.get('.toastify.toast-success').should('be.visible') cy.get('.app-navigation__list').contains('test table').should('not.exist') diff --git a/src/modules/modals/EditContext.vue b/src/modules/modals/EditContext.vue index 766b083a0..d30c9d113 100644 --- a/src/modules/modals/EditContext.vue +++ b/src/modules/modals/EditContext.vue @@ -186,7 +186,7 @@ export default { sharing = sharing.filter((share) => getCurrentUser().uid !== share.receiver) const receivers = sharing.map((share) => { return { - user: share.receiver, + id: share.receiver, displayName: share.receiver_display_name, icon: share.receiver_type === 'user' ? 'icon-user' : 'icon-group', isUser: share.receiver_type === 'user', diff --git a/src/modules/sidebar/partials/ShareForm.vue b/src/modules/sidebar/partials/ShareForm.vue index 5cc6dd392..d12b009ae 100644 --- a/src/modules/sidebar/partials/ShareForm.vue +++ b/src/modules/sidebar/partials/ShareForm.vue @@ -60,7 +60,7 @@ import debounce from 'debounce' import { NcSelect } from '@nextcloud/vue' import { mapState } from 'vuex' import formatting from '../../../shared/mixins/formatting.js' -import ShareTypes from '../../../shared/mixins/shareTypesMixin.js' +import { SHARE_TYPES } from '../../../shared/constants.js' export default { name: 'ShareForm', @@ -68,7 +68,7 @@ export default { NcSelect, }, - mixins: [ShareTypes, formatting], + mixins: [formatting], props: { shares: { @@ -160,8 +160,8 @@ export default { this.loading = true const shareType = [ - this.SHARE_TYPES.SHARE_TYPE_USER, - this.SHARE_TYPES.SHARE_TYPE_GROUP, + SHARE_TYPES.SHARE_TYPE_USER, + SHARE_TYPES.SHARE_TYPE_GROUP, ] const request = await axios.get(generateOcsUrl('apps/files_sharing/api/v1/sharees'), { @@ -248,7 +248,7 @@ export default { try { // filter out current user - if (share.value.shareType === this.SHARE_TYPES.SHARE_TYPE_USER + if (share.value.shareType === SHARE_TYPES.SHARE_TYPE_USER && share.value.shareWith === getCurrentUser().uid) { return arr } @@ -274,7 +274,7 @@ export default { shareWith: result.value.shareWith, shareType: result.value.shareType, user: result.uuid || result.value.shareWith, - isNoUser: result.value.shareType !== this.SHARE_TYPES.SHARE_TYPE_USER, + isNoUser: result.value.shareType !== SHARE_TYPES.SHARE_TYPE_USER, displayName: result.name || result.label, icon: this.shareTypeToIcon(result.value.shareType), // Vue unique binding to render within Multiselect's AvatarSelectOption @@ -290,20 +290,20 @@ export default { */ shareTypeToIcon(type) { switch (type) { - case this.SHARE_TYPES.SHARE_TYPE_GUEST: + case SHARE_TYPES.SHARE_TYPE_GUEST: // default is a user, other icons are here to differenciate // themselves from it, so let's not display the user icon - // case this.SHARE_TYPES.SHARE_TYPE_REMOTE: - // case this.SHARE_TYPES.SHARE_TYPE_USER: + // case SHARE_TYPES.SHARE_TYPE_REMOTE: + // case SHARE_TYPES.SHARE_TYPE_USER: return 'icon-user' - case this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP: - case this.SHARE_TYPES.SHARE_TYPE_GROUP: + case SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP: + case SHARE_TYPES.SHARE_TYPE_GROUP: return 'icon-group' - case this.SHARE_TYPES.SHARE_TYPE_EMAIL: + case SHARE_TYPES.SHARE_TYPE_EMAIL: return 'icon-mail' - case this.SHARE_TYPES.SHARE_TYPE_CIRCLE: + case SHARE_TYPES.SHARE_TYPE_CIRCLE: return 'icon-circle' - case this.SHARE_TYPES.SHARE_TYPE_ROOM: + case SHARE_TYPES.SHARE_TYPE_ROOM: return 'icon-room' default: diff --git a/src/shared/components/ncContextResource/ResourceSharees.vue b/src/shared/components/ncContextResource/ResourceSharees.vue index d3d36b98d..06461d748 100644 --- a/src/shared/components/ncContextResource/ResourceSharees.vue +++ b/src/shared/components/ncContextResource/ResourceSharees.vue @@ -22,7 +22,6 @@ import { NcSelect } from '@nextcloud/vue' import formatting from '../../../shared/mixins/formatting.js' import searchUserGroup from '../../../shared/mixins/searchUserGroup.js' -import ShareTypes from '../../mixins/shareTypesMixin.js' import '@nextcloud/dialogs/style.css' export default { @@ -31,7 +30,7 @@ export default { NcSelect, }, - mixins: [ShareTypes, formatting, searchUserGroup], + mixins: [formatting, searchUserGroup], props: { receivers: { @@ -50,9 +49,8 @@ export default { data() { return { - value: '', preExistingSharees: [...this.receivers], - localSharees: this.receivers.map(userObject => userObject.user), + localSharees: this.receivers.map(userObject => userObject.id), } }, @@ -62,7 +60,7 @@ export default { return this.localSharees }, set(v) { - this.localSharees = v.map(userObject => userObject.user) + this.localSharees = v.map(userObject => userObject.id) this.$emit('update', v) }, }, @@ -70,11 +68,7 @@ export default { methods: { addShare(selectedItem) { - if (selectedItem) { - this.localValue = selectedItem - } else { - this.localValue = [] - } + this.localValue = selectedItem }, filterOutUnwantedItems(list) { @@ -83,7 +77,7 @@ export default { }, filterOutSelectedUsers(list) { - return list.filter((item) => !(item.isUser && this.localSharees.includes(item.user))) + return list.filter((item) => !(item.isUser && this.localSharees.includes(item.id))) }, }, diff --git a/src/shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue b/src/shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue index 57af7ba33..e3e36569a 100644 --- a/src/shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue +++ b/src/shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue @@ -14,7 +14,6 @@