Skip to content

Commit

Permalink
Fix preloading some role pickers values correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Oct 7, 2024
1 parent 550db9f commit 36a787f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
14 changes: 11 additions & 3 deletions client/web/admin/src/components/CRolePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ export default {
},
preloadSelected () {
if (!this.value.length) {
return
}
this.preloading = true
return this.$SystemAPI.roleList({ memberID: this.$auth.user.userID })
.then(({ set }) => { this.selectedRoles = set || [] })
.finally(() => { this.preloading = false })
return this.$SystemAPI.roleList({ roleID: this.value })
.then(({ set }) => {
this.selectedRoles = set || []
})
.finally(() => {
this.preloading = false
})
.catch(this.toastErrorHandler(this.$t('notification:role.fetch.error')))
},
Expand Down
11 changes: 7 additions & 4 deletions client/web/admin/src/views/System/User/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/>

<c-user-editor-roles
v-if="user && userID"
v-if="user && userID && membership.active"
v-model="membership.active"
class="mt-3"
:processing="roles.processing"
Expand Down Expand Up @@ -147,8 +147,8 @@ export default {
initialUserState: undefined,
membership: {
active: [],
initial: [],
active: undefined,
initial: undefined,
},
externalAuthProviders: [],
Expand Down Expand Up @@ -238,7 +238,10 @@ export default {
this.incLoader()
return this.$SystemAPI.userMembershipList({ userID: this.userID })
.then((set = []) => {
this.membership = { active: [...set], initial: [...set] }
this.membership = {
active: [...set],
initial: [...set],
}
})
.catch(this.toastErrorHandler(this.$t('notification:user.roles.error')))
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,25 +952,23 @@ export default {
methods: {
fetchRoles () {
if (this.options.filterPresets.length) {
this.fetchingRoles = true
if (!this.options.filterPresets.length) {
return
}
const rolesToResolve = this.options.filterPresets.reduce((acc, { roles }) => {
return acc.concat(roles)
}, [])
this.fetchingRoles = true
Promise.all(rolesToResolve.map(roleID => {
if (this.resolvedRoles[roleID]) {
return Promise.resolve()
}
const rolesToResolve = this.options.filterPresets.reduce((acc, { roles }) => {
return acc.concat(roles)
}, [])
return this.$SystemAPI.roleRead({ roleID }).then(role => {
this.resolvedRoles[roleID] = role
})
})).finally(() => {
this.fetchingRoles = false
this.$SystemAPI.roleList({ roleID: rolesToResolve }).then(({ set }) => {
set.forEach(role => {
this.resolvedRoles[role.roleID] = role
})
}
}).finally(() => {
this.fetchingRoles = false
})
},
onFilterRoleChange (filter, roles) {
Expand Down

0 comments on commit 36a787f

Please sign in to comment.