diff --git a/cypress/e2e/column-usergroup.cy.js b/cypress/e2e/column-usergroup.cy.js index 18282aa3c2..475ba719ed 100644 --- a/cypress/e2e/column-usergroup.cy.js +++ b/cypress/e2e/column-usergroup.cy.js @@ -59,6 +59,7 @@ describe('Test column ' + columnTitle, () => { cy.get('[data-cy="ncTable"] table tr td .user-bubble__name').contains(localUser.userId).should('be.visible') cy.get('[data-cy="ncTable"] [data-cy="editRowBtn"]').click() + cy.get('[data-cy="usergroupRowSelect"] .vs__deselect').click({ multiple: true }) cy.get('[data-cy="usergroupRowSelect"] input').clear().type(nonLocalUser.userId) cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click() cy.get('[data-cy="editRowSaveButton"]').click() diff --git a/src/shared/components/ncTable/partials/rowTypePartials/UsergroupForm.vue b/src/shared/components/ncTable/partials/rowTypePartials/UsergroupForm.vue index ac303469e4..2f6dfd3edb 100644 --- a/src/shared/components/ncTable/partials/rowTypePartials/UsergroupForm.vue +++ b/src/shared/components/ncTable/partials/rowTypePartials/UsergroupForm.vue @@ -44,12 +44,13 @@ export default { return { selectUsers: this.column.usergroupSelectUsers, selectGroups: this.column.usergroupSelectGroups, + internalLocalValue: [], } }, computed: { localValue: { get() { - return this.value + return this.internalLocalValue }, set(v) { let formattedValue = null @@ -58,6 +59,7 @@ export default { } else { formattedValue = [v] } + this.internalLocalValue = formattedValue this.$emit('update:value', formattedValue) }, }, @@ -67,6 +69,22 @@ export default { // Doing this in data() doesn't work due to timing issues, // since the data() function runs before the capabilities are fully initialized this.selectCircles = this.isCirclesEnabled ? this.column.usergroupSelectTeams : false + + let initialValue = this.value + if (!initialValue || (Array.isArray(initialValue) && initialValue.length === 0)) { + initialValue = this.column.usergroupDefault || [] + } + + const formatted = (Array.isArray(initialValue) ? initialValue : []).map(item => ({ + ...(item ?? {}), + // Adding a unique key such that removing items works correctly + key: this.getKeyPrefix(item?.type) + (item?.id ?? ''), + })) + this.internalLocalValue = formatted + + if (formatted.length > 0) { + this.$emit('update:value', formatted) + } }, methods: { addItem(selectedItem) { @@ -77,6 +95,15 @@ export default { } }, + getKeyPrefix(type) { + switch (type) { + case 0: return 'users-' + case 1: return 'groups-' + case 2: return 'circles-' + default: return 'unknown-' + } + }, + filterOutUnwantedItems(list) { return list },