[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();
}