mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3629] Fix involved user bug on People Widget (#3858)
This commit is contained in:
committed by
Eugenio Romano
parent
54cca45ec1
commit
67785cba54
@@ -13,8 +13,11 @@
|
|||||||
[formControl]="searchTerm"
|
[formControl]="searchTerm"
|
||||||
placeholder="{{field.placeholder}}"
|
placeholder="{{field.placeholder}}"
|
||||||
[matAutocomplete]="auto">
|
[matAutocomplete]="auto">
|
||||||
<mat-autocomplete class="adf-people-widget-list" #auto="matAutocomplete" (optionSelected)="onItemSelect($event.option.value)">
|
<mat-autocomplete class="adf-people-widget-list"
|
||||||
<mat-option *ngFor="let user of users$ | async; let i = index" [value]="getDisplayName(user)">
|
#auto="matAutocomplete"
|
||||||
|
(optionSelected)="onItemSelect($event.option.value)"
|
||||||
|
[displayWith]="getDisplayName">
|
||||||
|
<mat-option *ngFor="let user of users$ | async; let i = index" [value]="user">
|
||||||
<div class="adf-people-widget-row" id="adf-people-widget-user-{{i}}">
|
<div class="adf-people-widget-row" id="adf-people-widget-user-{{i}}">
|
||||||
<div [outerHTML]="user | usernameInitials:'adf-people-widget-pic'"></div>
|
<div [outerHTML]="user | usernameInitials:'adf-people-widget-pic'"></div>
|
||||||
<div *ngIf="user.pictureId" class="adf-people-widget-image-row">
|
<div *ngIf="user.pictureId" class="adf-people-widget-image-row">
|
||||||
|
@@ -143,6 +143,22 @@ describe('PeopleWidgetComponent', () => {
|
|||||||
expect(widget.groupId).toBe('<id>');
|
expect(widget.groupId).toBe('<id>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display involved user in task form', async() => {
|
||||||
|
widget.field.value = new UserProcessModel({
|
||||||
|
id: 'people-id',
|
||||||
|
firstName: 'John',
|
||||||
|
lastName: 'Doe',
|
||||||
|
email: 'john@test.com'
|
||||||
|
});
|
||||||
|
widget.ngOnInit();
|
||||||
|
|
||||||
|
const involvedUser = fixture.debugElement.nativeElement.querySelector('input[data-automation-id="adf-people-search-input"]');
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(involvedUser.value).toBe('John Doe');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when template is ready', () => {
|
describe('when template is ready', () => {
|
||||||
|
|
||||||
let fakeUserResult = [
|
let fakeUserResult = [
|
||||||
|
@@ -53,7 +53,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
searchTerm = new FormControl();
|
searchTerm = new FormControl();
|
||||||
errorMsg = '';
|
errorMsg = '';
|
||||||
searchTerms$: Observable<string> = this.searchTerm.valueChanges;
|
searchTerms$: Observable<any> = this.searchTerm.valueChanges;
|
||||||
|
|
||||||
users$ = this.searchTerms$.pipe(
|
users$ = this.searchTerms$.pipe(
|
||||||
tap(() => {
|
tap(() => {
|
||||||
@@ -61,7 +61,8 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
}),
|
}),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
switchMap((searchTerm) => {
|
switchMap((searchTerm) => {
|
||||||
return this.formService.getWorkflowUsers(searchTerm, this.groupId)
|
let value = searchTerm.email ? this.getDisplayName(searchTerm) : searchTerm;
|
||||||
|
return this.formService.getWorkflowUsers(value, this.groupId)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(err => {
|
catchError(err => {
|
||||||
this.errorMsg = err.message;
|
this.errorMsg = err.message;
|
||||||
@@ -70,7 +71,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
map((list: UserProcessModel[]) => {
|
map((list: UserProcessModel[]) => {
|
||||||
let value = this.searchTerm.value;
|
let value = this.searchTerm.value.email ? this.getDisplayName(this.searchTerm.value) : this.searchTerm.value;
|
||||||
this.checkUserAndValidateForm(list, value);
|
this.checkUserAndValidateForm(list, value);
|
||||||
return list;
|
return list;
|
||||||
})
|
})
|
||||||
@@ -83,7 +84,9 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
this.searchTerm.setValue(this.getDisplayName(this.field.value));
|
if (this.field.value) {
|
||||||
|
this.searchTerm.setValue(this.field.value);
|
||||||
|
}
|
||||||
if (this.field.readOnly) {
|
if (this.field.readOnly) {
|
||||||
this.searchTerm.disable();
|
this.searchTerm.disable();
|
||||||
}
|
}
|
||||||
@@ -128,10 +131,9 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemSelect(item) {
|
onItemSelect(item: UserProcessModel) {
|
||||||
if (item) {
|
if (item) {
|
||||||
this.field.value = item;
|
this.field.value = item;
|
||||||
this.searchTerm.setValue(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user