Allow for more customization of adf-cloud-people component (#10056)

* Allow for more customization of adf-cloud-people component

* Update documentation
This commit is contained in:
Robert Duda 2024-08-07 13:55:39 +02:00 committed by GitHub
parent 794eee144d
commit 5930a27bbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 4 deletions

View File

@ -35,6 +35,10 @@ Allows one or more users to be selected (with auto-suggestion) based on the inpu
| roles | `string[]` | | Role names of the users to be listed. | | roles | `string[]` | | Role names of the users to be listed. |
| searchUserCtrl | `FormControl<any>` | | FormControl to search the user | | searchUserCtrl | `FormControl<any>` | | FormControl to search the user |
| title | `string` | | Placeholder translation key | | title | `string` | | Placeholder translation key |
| hideInputOnSingleSelection | `boolean` | false | Hide the input field when a user is selected in single selection mode. The input will be shown again when the user is removed using the icon on the chip. |
| formFieldAppearance | [`MatFormFieldAppearance`](https://material.angular.io/components/form-field/api#MatFormFieldAppearance) | "fill" | Material form field appearance (fill / outline). |
| formFieldSubscriptSizing | [`SubscriptSizing`](https://material.angular.io/components/form-field/api#SubscriptSizing) | "fixed" | Material form field subscript sizing (fixed / dynamic). |
| showErrors | `boolean` | true | Show errors under the form field. |
| userChipsCtrl | `UntypedFormControl` | | FormControl to list of users | | userChipsCtrl | `UntypedFormControl` | | FormControl to list of users |
| validate | `boolean` | false | This flag enables the validation on the preSelectUsers passed as input. In case the flag is true the components call the identity service to verify the validity of the information passed as input. Otherwise, no check will be done. | | validate | `boolean` | false | This flag enables the validation on the preSelectUsers passed as input. In case the flag is true the components call the identity service to verify the validity of the information passed as input. Otherwise, no check will be done. |

View File

@ -1,5 +1,11 @@
<form> <form>
<mat-form-field [floatLabel]="'auto'" class="adf-people-cloud" [class.adf-invalid]="hasError() && isDirty()"> <mat-form-field
[appearance]="formFieldAppearance"
[subscriptSizing]="formFieldSubscriptSizing"
[floatLabel]="'auto'"
class="adf-people-cloud"
[class.adf-invalid]="hasError() && isDirty()"
>
<ng-content select="[label]"></ng-content> <ng-content select="[label]"></ng-content>
<mat-chip-grid #userMultipleChipList [disabled]="isReadonly() || isValidationLoading()" data-automation-id="adf-cloud-people-chip-list"> <mat-chip-grid #userMultipleChipList [disabled]="isReadonly() || isValidationLoading()" data-automation-id="adf-cloud-people-chip-list">
<mat-chip-row <mat-chip-row
@ -58,7 +64,7 @@
mode="indeterminate"> mode="indeterminate">
</mat-progress-bar> </mat-progress-bar>
<div class="adf-error-container"> <div class="adf-error-container" *ngIf="showErrors">
<mat-error *ngIf="hasPreselectError() && !isValidationLoading()" [@transitionMessages]="subscriptAnimationState" class="adf-error"> <mat-error *ngIf="hasPreselectError() && !isValidationLoading()" [@transitionMessages]="subscriptAnimationState" class="adf-error">
<mat-icon class="adf-error-icon">error_outline</mat-icon> <mat-icon class="adf-error-icon">error_outline</mat-icon>
<div class="adf-error-text">{{ 'ADF_CLOUD_USERS.ERROR.NOT_FOUND' | translate : { userName : validateUsersMessage } }}</div> <div class="adf-error-text">{{ 'ADF_CLOUD_USERS.ERROR.NOT_FOUND' | translate : { userName : validateUsersMessage } }}</div>

View File

@ -28,7 +28,8 @@ import {
OnDestroy, OnDestroy,
ViewChild, ViewChild,
ElementRef, ElementRef,
Inject Inject,
AfterViewInit
} from '@angular/core'; } from '@angular/core';
import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, takeUntil } from 'rxjs/operators'; import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, takeUntil } from 'rxjs/operators';
@ -38,6 +39,7 @@ import { ComponentSelectionMode } from '../../types';
import { IdentityUserModel } from '../models/identity-user.model'; import { IdentityUserModel } from '../models/identity-user.model';
import { IdentityUserServiceInterface } from '../services/identity-user.service.interface'; import { IdentityUserServiceInterface } from '../services/identity-user.service.interface';
import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.token'; import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.token';
import { MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field';
@Component({ @Component({
selector: 'adf-cloud-people', selector: 'adf-cloud-people',
@ -52,7 +54,7 @@ import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.t
providers: [FullNamePipe], providers: [FullNamePipe],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy { export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy, AfterViewInit {
/** Name of the application. If specified, this shows the users who have access to the app. */ /** Name of the application. If specified, this shows the users who have access to the app. */
@Input() @Input()
appName: string; appName: string;
@ -122,6 +124,31 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
@Input() @Input()
title: string; title: string;
/**
* Hide the matInput associated with the chip grid when a single user is selected in single selection mode.
* The input will be shown again when the user is removed using the icon on the chip.
*/
@Input()
hideInputOnSingleSelection = false;
/**
* Material form field appearance (fill / outline)
*/
@Input()
formFieldAppearance: MatFormFieldAppearance = 'fill';
/**
* Material form field subscript sizing (fixed / dynamic)
*/
@Input()
formFieldSubscriptSizing: SubscriptSizing = 'fixed';
/**
* Show errors under the form field
*/
@Input()
showErrors: boolean = true;
/** Emitted when a user is selected. */ /** Emitted when a user is selected. */
@Output() @Output()
selectUser = new EventEmitter<IdentityUserModel>(); selectUser = new EventEmitter<IdentityUserModel>();
@ -190,6 +217,14 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
} }
} }
ngAfterViewInit(): void {
if (this.hideInputOnSingleSelection) {
if (this.selectedUsers.length === 1 && this.isSingleMode() && this.userInput) {
this.userInput.nativeElement.style.display = 'none';
}
}
}
private initSearch(): void { private initSearch(): void {
this.initializeStream(); this.initializeStream();
this.typingUniqueValueNotEmpty$ this.typingUniqueValueNotEmpty$
@ -341,6 +376,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
} else { } else {
this.invalidUsers = []; this.invalidUsers = [];
this.selectedUsers = [user]; this.selectedUsers = [user];
if (this.hideInputOnSingleSelection) {
this.userInput.nativeElement.style.display = 'none';
}
} }
this.userInput.nativeElement.value = ''; this.userInput.nativeElement.value = '';
@ -358,6 +396,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
this.changedUsers.emit(this.selectedUsers); this.changedUsers.emit(this.selectedUsers);
if (this.selectedUsers.length === 0) { if (this.selectedUsers.length === 0) {
this.userChipsControlValue(''); this.userChipsControlValue('');
if (this.hideInputOnSingleSelection) {
this.userInput.nativeElement.style.display = 'block';
}
} else { } else {
this.userChipsControlValue(this.selectedUsers[0].username); this.userChipsControlValue(this.selectedUsers[0].username);
} }