218
218
class =" mb-0"
219
219
>
220
220
<c-input-select
221
- key =" roleID"
222
221
v-model =" add.roleID"
223
222
:data-test-id =" `select-${add.mode}-roles`"
224
223
:options =" availableRoles"
225
224
:get-option-key =" getOptionRoleKey"
226
- :multiple =" add.mode === 'eval'"
227
225
label =" name"
226
+ :multiple =" add.mode === 'eval'"
228
227
:disabled =" add.mode === 'eval' && !!add.userID"
229
228
:placeholder =" $t('ui.add.role.placeholder')"
230
229
/>
237
236
class =" mt-3 mb-0"
238
237
>
239
238
<c-input-select
240
- key =" userID"
241
239
v-model =" add.userID"
242
240
:data-test-id =" `select-${add.mode}-users`"
243
241
:disabled =" !!add.roleID.length"
244
- :get-option-key =" getOptionUserKey"
245
242
:options =" userOptions"
246
243
:get-option-label =" getUserLabel"
247
- label =" name"
248
244
:placeholder =" $t('ui.add.user.placeholder')"
245
+ :filterable =" false"
249
246
@search =" searchUsers"
250
247
/>
251
248
</b-form-group >
@@ -328,6 +325,8 @@ export default {
328
325
329
326
newRole: null ,
330
327
permissionChanges: [],
328
+
329
+ fetchedUsers: {},
331
330
}
332
331
},
333
332
@@ -380,6 +379,10 @@ export default {
380
379
this .searchUsers (' ' , () => {})
381
380
},
382
381
382
+ beforeDestroy () {
383
+ this .setDefaultValues ()
384
+ },
385
+
383
386
methods: {
384
387
checkRule (ID , res , op , access ) {
385
388
const key = ` ${ op} @${ res} `
@@ -426,15 +429,23 @@ export default {
426
429
427
430
this .$SystemAPI .userList ({ query, limit: 15 })
428
431
.then (({ set }) => {
429
- this .userOptions = set .map (m => Object .freeze (m))
432
+ this .userOptions = set .reduce ((acc , { userID, name, username, email }) => {
433
+ if (! this .fetchedUsers [userID]) {
434
+ this .fetchedUsers [userID] = name || username || email || ` <@${ userID} >`
435
+ }
436
+
437
+ acc .push (userID)
438
+
439
+ return acc
440
+ }, [])
430
441
})
431
442
.finally (() => {
432
443
loading (false )
433
444
})
434
445
},
435
446
436
- getUserLabel ({ userID, email, name, username } ) {
437
- return name || username || email || ` <@ ${ userID} > `
447
+ getUserLabel (userID ) {
448
+ return this . fetchedUsers [ userID]
438
449
},
439
450
440
451
getTranslation (resource , operation = ' ' ) {
@@ -461,7 +472,7 @@ export default {
461
472
},
462
473
463
474
onAdd () {
464
- this .$emit (' add' , this .add )
475
+ this .$emit (' add' , { ... this .add , userID : { userID : this . add . userID , name : this . fetchedUsers [ this . add . userID ] } } )
465
476
this .add = {
466
477
mode: ' edit' ,
467
478
roleID: [],
@@ -477,8 +488,14 @@ export default {
477
488
return roleID
478
489
},
479
490
480
- getOptionUserKey ({ userID }) {
481
- return userID
491
+ setDefaultValues () {
492
+ this .add = {}
493
+ this .modeOptions = []
494
+ this .userOptions = []
495
+ this .evaluatedPermissions = undefined
496
+ this .newRole = null
497
+ this .permissionChanges = []
498
+ this .fetchedUsers = {}
482
499
},
483
500
},
484
501
}
0 commit comments