diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts index d81430680b..5bd460df85 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts @@ -109,6 +109,7 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { isDisabled: boolean; private onDestroy$ = new Subject(); + currentTimeout: any; constructor(private identityGroupService: IdentityGroupService) { } @@ -117,8 +118,11 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { } ngOnChanges(changes: SimpleChanges) { + if (changes.preSelectGroups && this.hasPreSelectGroups()) { this.loadPreSelectGroups(); + } else { + this.searchGroupsControl.setValue(''); } if (changes.appName && this.isAppNameChanged(changes.appName)) { @@ -208,10 +212,19 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { this.preSelectGroups.forEach((group: IdentityGroupModel) => { this.selectedGroups.push(group); }); + const groups = this.removeDuplicatedGroups(this.selectedGroups); + this.selectedGroups = [...groups]; this.selectedGroups$.next(this.selectedGroups); } else { - this.searchGroupsControl.setValue(this.preSelectGroups[0]); - this.onSelect(this.preSelectGroups[0]); + + if (this.currentTimeout) { + clearTimeout(this.currentTimeout); + } + + this.currentTimeout = setTimeout(() => { + this.searchGroupsControl.setValue(this.preSelectGroups[0]); + this.onSelect(this.preSelectGroups[0]); + }, 0); } } @@ -262,6 +275,13 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { return group ? group.name : ''; } + private removeDuplicatedGroups(groups: IdentityGroupModel[]): IdentityGroupModel[] { + return groups.filter((group, index, self) => + index === self.findIndex((auxGroup) => { + return group.id === auxGroup.id; + })); + } + private hasPreSelectGroups(): boolean { return this.preSelectGroups && this.preSelectGroups.length > 0; } @@ -306,6 +326,7 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { } ngOnDestroy() { + clearTimeout(this.currentTimeout); this.onDestroy$.next(true); this.onDestroy$.complete(); } diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/people-cloud/people-cloud.component.ts b/lib/process-services-cloud/src/lib/task/start-task/components/people-cloud/people-cloud.component.ts index 28bc8d0fb2..7e44cef54b 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/people-cloud/people-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/components/people-cloud/people-cloud.component.ts @@ -107,6 +107,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { isFocused: boolean; invalidUsers: IdentityUserModel[] = []; + currentTimeout: any; + constructor(private identityUserService: IdentityUserService, private logService: LogService) { } @@ -140,6 +142,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } ngOnDestroy() { + clearTimeout(this.currentTimeout); this.onDestroy$.next(true); this.onDestroy$.complete(); } @@ -196,7 +199,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { private removeDuplicatedUsers(users: IdentityUserModel[]): IdentityUserModel[] { return users.filter((user, index, self) => - index === self.findIndex((auxUser) => user.id === auxUser.id)); + index === self.findIndex((auxUser) => { + return user.id === auxUser.id && user.username === auxUser.username; + })); } async filterPreselectUsers() { @@ -332,22 +337,26 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } else { this.loadMultiplePreselectUsers(); } - if (this.userInput) { - this.userInput.nativeElement.click(); - } } async loadNoValidationPreselectUsers() { let users: IdentityUserModel[]; users = this.removeDuplicatedUsers(this.preSelectUsers); - this.preSelectUsers = [...users]; if (this.isMultipleMode()) { this.selectedUsersSubject.next(this.preSelectUsers); } else { - this.searchUserCtrl.setValue(this.preSelectUsers[0]); + + if (this.currentTimeout) { + clearTimeout(this.currentTimeout); + } + + this.currentTimeout = setTimeout(() => { + this.searchUserCtrl.setValue(this.preSelectUsers[0]); + this.onSelect(this.preSelectUsers[0]); + }, 0); } }