diff --git a/public/app/core/components/user_group_picker.ts b/public/app/core/components/user_group_picker.ts index 07b2ebcef38..185184d857d 100644 --- a/public/app/core/components/user_group_picker.ts +++ b/public/app/core/components/user_group_picker.ts @@ -16,8 +16,27 @@ export class UserGroupPickerCtrl { /** @ngInject */ constructor(private backendSrv, private $scope, $sce, private uiSegmentSrv) { - this.userGroupSegment = this.uiSegmentSrv.newSegment({value: 'Choose User Group', selectMode: true}); this.debouncedSearchUserGroups = _.debounce(this.searchUserGroups, 500, {'leading': true, 'trailing': false}); + this.resetUserGroupSegment(); + } + + resetUserGroupSegment() { + this.userGroupId = null; + + const userGroupSegment = this.uiSegmentSrv.newSegment({value: 'Choose User Group', selectMode: true, fake: true}); + if (!this.userGroupSegment) { + this.userGroupSegment = userGroupSegment; + } else { + this.userGroupSegment.value = userGroupSegment.value; + this.userGroupSegment.html = userGroupSegment.html; + this.userGroupSegment.value = userGroupSegment.value; + } + } + + userGroupIdChanged(newVal) { + if (!newVal) { + this.resetUserGroupSegment(); + } } searchUserGroups(query: string) { @@ -50,8 +69,12 @@ export function userGroupPicker() { bindToController: true, controllerAs: 'ctrl', scope: { - userGroupSegment: '=', userGroupId: '=', + }, + link: function(scope, elem, attrs, ctrl) { + scope.$watch("ctrl.userGroupId", (newVal, oldVal) => { + ctrl.userGroupIdChanged(newVal); + }); } }; } diff --git a/public/app/core/components/user_picker.ts b/public/app/core/components/user_picker.ts index f12fa9a241d..9697bae4dda 100644 --- a/public/app/core/components/user_picker.ts +++ b/public/app/core/components/user_picker.ts @@ -17,8 +17,21 @@ export class UserPickerCtrl { /** @ngInject */ constructor(private backendSrv, private $scope, $sce, private uiSegmentSrv) { - this.userSegment = this.uiSegmentSrv.newSegment({value: 'Choose User', selectMode: true}); + this.userSegment = this.uiSegmentSrv.newSegment({value: 'Choose User', selectMode: true, fake: true}); this.debouncedSearchUsers = _.debounce(this.searchUsers, 500, {'leading': true, 'trailing': false}); + this.userId = null; + this.resetUserSegment(); + } + + resetUserSegment() { + const userSegment = this.uiSegmentSrv.newSegment({value: 'Choose User', selectMode: true, fake: true}); + if (!this.userSegment) { + this.userSegment = userSegment; + } else { + this.userSegment.value = userSegment.value; + this.userSegment.html = userSegment.html; + this.userSegment.value = userSegment.value; + } } searchUsers(query: string) { @@ -44,11 +57,16 @@ export class UserPickerCtrl { }); } + userIdChanged(newVal) { + if (!newVal) { + this.resetUserSegment(); + } + } + private userKey(user: User) { return this.uiSegmentSrv.newSegment(user.login + ' - ' + user.email); } - } export interface User { @@ -66,9 +84,12 @@ export function userPicker() { bindToController: true, controllerAs: 'ctrl', scope: { - userSegment: '=', - userLogin: '=', userId: '=', + }, + link: function(scope, elem, attrs, ctrl) { + scope.$watch("ctrl.userId", (newVal, oldVal) => { + ctrl.userIdChanged(newVal); + }); } }; } diff --git a/public/app/features/dashboard/acl/acl.html b/public/app/features/dashboard/acl/acl.html index 1d4110b1dca..ab3393c92ec 100644 --- a/public/app/features/dashboard/acl/acl.html +++ b/public/app/features/dashboard/acl/acl.html @@ -8,11 +8,11 @@