[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;
private onDestroy$ = new Subject<boolean>();
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();
}

View File

@@ -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);
}
}