From 36a787f70508c962e0490d49d6f12e0f8365e14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Mon, 7 Oct 2024 15:25:29 +0200 Subject: [PATCH] Fix preloading some role pickers values correctly --- .../web/admin/src/components/CRolePicker.vue | 14 ++++++-- .../admin/src/views/System/User/Editor.vue | 11 +++--- .../PageBlocks/RecordListConfigurator.vue | 34 +++++++++---------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/client/web/admin/src/components/CRolePicker.vue b/client/web/admin/src/components/CRolePicker.vue index f92b09eb8..aa0d1bd29 100644 --- a/client/web/admin/src/components/CRolePicker.vue +++ b/client/web/admin/src/components/CRolePicker.vue @@ -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'))) }, diff --git a/client/web/admin/src/views/System/User/Editor.vue b/client/web/admin/src/views/System/User/Editor.vue index 57f6ef151..ce78845ca 100644 --- a/client/web/admin/src/views/System/User/Editor.vue +++ b/client/web/admin/src/views/System/User/Editor.vue @@ -59,7 +59,7 @@ /> { - this.membership = { active: [...set], initial: [...set] } + this.membership = { + active: [...set], + initial: [...set], + } }) .catch(this.toastErrorHandler(this.$t('notification:user.roles.error'))) .finally(() => { diff --git a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue index 859d46463..4e45b6a44 100644 --- a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue @@ -952,25 +952,23 @@ export default { methods: { fetchRoles () { - if (this.options.filterPresets.length) { - this.fetchingRoles = true - - const rolesToResolve = this.options.filterPresets.reduce((acc, { roles }) => { - return acc.concat(roles) - }, []) - - Promise.all(rolesToResolve.map(roleID => { - if (this.resolvedRoles[roleID]) { - return Promise.resolve() - } - - return this.$SystemAPI.roleRead({ roleID }).then(role => { - this.resolvedRoles[roleID] = role - }) - })).finally(() => { - this.fetchingRoles = false - }) + if (!this.options.filterPresets.length) { + return } + + this.fetchingRoles = true + + const rolesToResolve = this.options.filterPresets.reduce((acc, { roles }) => { + return acc.concat(roles) + }, []) + + this.$SystemAPI.roleList({ roleID: rolesToResolve }).then(({ set }) => { + set.forEach(role => { + this.resolvedRoles[role.roleID] = role + }) + }).finally(() => { + this.fetchingRoles = false + }) }, onFilterRoleChange (filter, roles) {