From 12d068c228b2424c58c27b8da72bf0b486da9590 Mon Sep 17 00:00:00 2001 From: siva kumar Date: Thu, 2 Jan 2020 18:39:27 +0530 Subject: [PATCH] [AAE-1344] [FE] - Removed all pre-selected users on removing of single pre-selected user. (#5350) * [AAE-1344] [FE] - Removed all preselected users on removing of single pre-selected user. * * Fixed Search problem on admin manage permision dialog * * Fixed failing unit test. * * Fixed failing unit test on group component --- .../components/group-cloud.component.html | 2 +- .../components/group-cloud.component.spec.ts | 21 ++++--- .../group/components/group-cloud.component.ts | 4 +- .../components/people-cloud.component.html | 2 +- .../components/people-cloud.component.spec.ts | 56 +++++++------------ .../components/people-cloud.component.ts | 31 ++++++---- 6 files changed, 56 insertions(+), 60 deletions(-) diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.html b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.html index 7c1306bad5..155e0d0425 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.html +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.html @@ -1,6 +1,6 @@
- {{ (title || 'ADF_CLOUD_GROUPS.SEARCH-GROUP') | translate }} + {{ (title || 'ADF_CLOUD_GROUPS.SEARCH-GROUP') | translate }} { expect(component instanceof GroupCloudComponent).toBeTruthy(); }); + it('should populate placeholder when title is present', async(() => { + component.title = 'TITLE_KEY'; + fixture.detectChanges(); + const matLabel: HTMLInputElement = element.querySelector('#adf-group-cloud-title-id'); + fixture.whenStable().then( () => { + fixture.detectChanges(); + expect(matLabel.textContent).toEqual('TITLE_KEY'); + }); + })); + describe('Search group', () => { beforeEach(async(() => { @@ -135,17 +145,6 @@ describe('GroupCloudComponent', () => { done(); }); }); - - it('should populate placeholder when title is present', (done) => { - component.title = 'TITLE_KEY'; - fixture.detectChanges(); - const matLabel: HTMLInputElement = element.querySelector('mat-label'); - fixture.whenStable().then( () => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual('TITLE_KEY'); - done(); - }); - }); }); describe('when application name defined', () => { 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 202dde6466..11d48a9130 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 @@ -26,7 +26,8 @@ import { Input, SimpleChanges, OnChanges, - OnDestroy + OnDestroy, + ChangeDetectionStrategy } from '@angular/core'; import { FormControl } from '@angular/forms'; import { trigger, state, style, transition, animate } from '@angular/animations'; @@ -48,6 +49,7 @@ import { IdentityGroupModel, IdentityGroupSearchParam, IdentityGroupService } fr ]) ]) ], + changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.html b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.html index b18d1939ff..b282ae016f 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.html +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.html @@ -1,6 +1,6 @@
- {{ title | translate }} + {{ title | translate }} { expect(component instanceof PeopleCloudComponent).toBe(true, 'should create PeopleCloudComponent'); }); + it('should populate placeholder when title is present', async(() => { + component.title = 'TITLE_KEY'; + fixture.detectChanges(); + const matLabel: HTMLInputElement = fixture.nativeElement.querySelector('#adf-people-cloud-title-id'); + fixture.whenStable().then( () => { + fixture.detectChanges(); + expect(matLabel.textContent).toEqual('TITLE_KEY'); + }); + })); + + it('should not populate placeholder when title is not present', async(() => { + fixture.detectChanges(); + const matLabel: HTMLInputElement = fixture.nativeElement.querySelector('#adf-people-cloud-title-id'); + fixture.detectChanges(); + fixture.whenStable().then( () => { + fixture.detectChanges(); + expect(matLabel.textContent).toEqual(''); + }); + })); + describe('Search user', () => { beforeEach(async(() => { @@ -136,27 +156,6 @@ describe('PeopleCloudComponent', () => { done(); }); }); - - it('should populate placeholder when title is present', (done) => { - component.title = 'TITLE_KEY'; - fixture.detectChanges(); - const matLabel: HTMLInputElement = element.querySelector('mat-label'); - fixture.whenStable().then( () => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual('TITLE_KEY'); - done(); - }); - }); - - it('should not populate placeholder when title is present', (done) => { - const matLabel: HTMLInputElement = element.querySelector('mat-label'); - fixture.detectChanges(); - fixture.whenStable().then( () => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual(''); - done(); - }); - }); }); describe('when application name defined', () => { @@ -654,21 +653,6 @@ describe('PeopleCloudComponent', () => { }); }); - it('should populate placeholder when title is present', () => { - fixture.detectChanges(); - component.title = 'ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE'; - const inputHTMLElement: HTMLInputElement = element.querySelector('mat-label'); - fixture.detectChanges(); - expect(inputHTMLElement.textContent).toEqual('ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE'); - }); - - it('should not populate placeholder when title is present', () => { - fixture.detectChanges(); - const inputHTMLElement: HTMLInputElement = element.querySelector('mat-label'); - fixture.detectChanges(); - expect(inputHTMLElement.textContent).toEqual(''); - }); - it('should remove duplicated preselcted users when a user is duplicated', () => { spyOn(identityService, 'findUserById').and.returnValue(of(mockUsers[0])); component.mode = 'multiple'; diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts index eac1be95a0..c38e6bd8f2 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts @@ -16,7 +16,7 @@ */ import { FormControl } from '@angular/forms'; -import { Component, OnInit, Output, EventEmitter, ViewEncapsulation, Input, ViewChild, ElementRef, SimpleChanges, OnChanges, OnDestroy } from '@angular/core'; +import { Component, OnInit, Output, EventEmitter, ViewEncapsulation, Input, ViewChild, ElementRef, SimpleChanges, OnChanges, OnDestroy, ChangeDetectionStrategy } from '@angular/core'; import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, map, takeUntil } from 'rxjs/operators'; import { FullNamePipe, IdentityUserModel, IdentityUserService, LogService } from '@alfresco/adf-core'; @@ -36,6 +36,7 @@ import { trigger, state, style, transition, animate } from '@angular/animations' ]) ], providers: [FullNamePipe], + changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) @@ -123,7 +124,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } ngOnInit() { - this.selectedUsers = [...this.preSelectUsers]; + if (this.hasPreSelectUsers()) { + this.selectedUsers = [...this.preSelectUsers]; + } this.initSubjects(); this.initSearch(); @@ -351,13 +354,10 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } async loadNoValidationPreselectUsers() { - let users: IdentityUserModel[]; - - users = this.removeDuplicatedUsers(this.preSelectUsers); - this.preSelectUsers = [...users]; + this.selectedUsers = [...this.removeDuplicatedUsers(this.preSelectUsers)]; if (this.isMultipleMode()) { - this.selectedUsersSubject.next(this.preSelectUsers); + this.selectedUsersSubject.next(this.selectedUsers); } else { if (this.currentTimeout) { @@ -365,8 +365,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { } this.currentTimeout = setTimeout(() => { - this.searchUserCtrl.setValue(this.preSelectUsers[0]); - this.onSelect(this.preSelectUsers[0]); + this.searchUserCtrl.setValue(this.selectedUsers[0]); + this.onSelect(this.selectedUsers[0]); }, 0); } } @@ -385,13 +385,24 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { const users = await this.validatePreselectUsers(); if (users && users.length > 0) { this.checkPreselectValidationErrors(); - this.selectedUsers = [...users]; + this.selectedUsers = [...this.alignPreselectedReadonlyUsersAfterValidation(users)]; this.selectedUsersSubject.next(this.selectedUsers); } else { this.checkPreselectValidationErrors(); } } + private alignPreselectedReadonlyUsersAfterValidation(users: IdentityUserModel[]) { + this.preSelectUsers.forEach((preSelectedUser, index) => { + if (users[index]) { + if ((preSelectedUser.id === users[index].id) || (preSelectedUser.username === users[index].username)) { + users[index].readonly = preSelectedUser.readonly; + } + } + }); + return users; + } + public checkPreselectValidationErrors() { if (this.invalidUsers.length > 0) { this.warning.emit({