[ADF-4041] - fix People/Group preselected issues (#4866)

* [ADF-4041] - fix People/Group preselected issues

* [ADF-4041] - remove duplicated groups

* [ADF-4041] - fix lint

* [ADF-4041] - fix label overlay

* [ADF-4041] - lint

* [ADF-4041] - PR changes

* clear timeout

* remove unused property

* clear timeout

* fix default preselect user
This commit is contained in:
Silviu Popa
2019-09-05 20:47:41 +03:00
committed by Denys Vuika
parent d5e7c0066b
commit 4d7c07ef93
2 changed files with 38 additions and 8 deletions

View File

@@ -109,6 +109,7 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
isDisabled: boolean; isDisabled: boolean;
private onDestroy$ = new Subject<boolean>(); private onDestroy$ = new Subject<boolean>();
currentTimeout: any;
constructor(private identityGroupService: IdentityGroupService) { } constructor(private identityGroupService: IdentityGroupService) { }
@@ -117,8 +118,11 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes.preSelectGroups && this.hasPreSelectGroups()) { if (changes.preSelectGroups && this.hasPreSelectGroups()) {
this.loadPreSelectGroups(); this.loadPreSelectGroups();
} else {
this.searchGroupsControl.setValue('');
} }
if (changes.appName && this.isAppNameChanged(changes.appName)) { if (changes.appName && this.isAppNameChanged(changes.appName)) {
@@ -208,10 +212,19 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
this.preSelectGroups.forEach((group: IdentityGroupModel) => { this.preSelectGroups.forEach((group: IdentityGroupModel) => {
this.selectedGroups.push(group); this.selectedGroups.push(group);
}); });
const groups = this.removeDuplicatedGroups(this.selectedGroups);
this.selectedGroups = [...groups];
this.selectedGroups$.next(this.selectedGroups); this.selectedGroups$.next(this.selectedGroups);
} else { } else {
if (this.currentTimeout) {
clearTimeout(this.currentTimeout);
}
this.currentTimeout = setTimeout(() => {
this.searchGroupsControl.setValue(this.preSelectGroups[0]); this.searchGroupsControl.setValue(this.preSelectGroups[0]);
this.onSelect(this.preSelectGroups[0]); this.onSelect(this.preSelectGroups[0]);
}, 0);
} }
} }
@@ -262,6 +275,13 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
return group ? group.name : ''; 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 { private hasPreSelectGroups(): boolean {
return this.preSelectGroups && this.preSelectGroups.length > 0; return this.preSelectGroups && this.preSelectGroups.length > 0;
} }
@@ -306,6 +326,7 @@ export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
clearTimeout(this.currentTimeout);
this.onDestroy$.next(true); this.onDestroy$.next(true);
this.onDestroy$.complete(); this.onDestroy$.complete();
} }

View File

@@ -107,6 +107,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
isFocused: boolean; isFocused: boolean;
invalidUsers: IdentityUserModel[] = []; invalidUsers: IdentityUserModel[] = [];
currentTimeout: any;
constructor(private identityUserService: IdentityUserService, private logService: LogService) { constructor(private identityUserService: IdentityUserService, private logService: LogService) {
} }
@@ -140,6 +142,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
clearTimeout(this.currentTimeout);
this.onDestroy$.next(true); this.onDestroy$.next(true);
this.onDestroy$.complete(); this.onDestroy$.complete();
} }
@@ -196,7 +199,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
private removeDuplicatedUsers(users: IdentityUserModel[]): IdentityUserModel[] { private removeDuplicatedUsers(users: IdentityUserModel[]): IdentityUserModel[] {
return users.filter((user, index, self) => 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() { async filterPreselectUsers() {
@@ -332,22 +337,26 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
} else { } else {
this.loadMultiplePreselectUsers(); this.loadMultiplePreselectUsers();
} }
if (this.userInput) {
this.userInput.nativeElement.click();
}
} }
async loadNoValidationPreselectUsers() { async loadNoValidationPreselectUsers() {
let users: IdentityUserModel[]; let users: IdentityUserModel[];
users = this.removeDuplicatedUsers(this.preSelectUsers); users = this.removeDuplicatedUsers(this.preSelectUsers);
this.preSelectUsers = [...users]; this.preSelectUsers = [...users];
if (this.isMultipleMode()) { if (this.isMultipleMode()) {
this.selectedUsersSubject.next(this.preSelectUsers); this.selectedUsersSubject.next(this.preSelectUsers);
} else { } else {
if (this.currentTimeout) {
clearTimeout(this.currentTimeout);
}
this.currentTimeout = setTimeout(() => {
this.searchUserCtrl.setValue(this.preSelectUsers[0]); this.searchUserCtrl.setValue(this.preSelectUsers[0]);
this.onSelect(this.preSelectUsers[0]);
}, 0);
} }
} }