mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
code improvements
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
import { FullNamePipe } from './full-name.pipe';
|
||||
|
||||
describe('FullNamePipe', () => {
|
||||
|
||||
let pipe: FullNamePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -31,27 +30,27 @@ describe('FullNamePipe', () => {
|
||||
});
|
||||
|
||||
it('should return only firstName as fullName when there is no lastName ', () => {
|
||||
const user = {firstName : 'Abc'};
|
||||
const user = { firstName: 'Abc' };
|
||||
expect(pipe.transform(user)).toBe('Abc');
|
||||
});
|
||||
|
||||
it('should return only lastName as fullName when there is no firstName ', () => {
|
||||
const user = {lastName : 'Xyz'};
|
||||
const user = { lastName: 'Xyz' };
|
||||
expect(pipe.transform(user)).toBe('Xyz');
|
||||
});
|
||||
|
||||
it('should return fullName when firstName and lastName are available', () => {
|
||||
const user = {firstName : 'Abc', lastName : 'Xyz'};
|
||||
const user = { firstName: 'Abc', lastName: 'Xyz' };
|
||||
expect(pipe.transform(user)).toBe('Abc Xyz');
|
||||
});
|
||||
|
||||
it('should return username when firstName and lastName are not available', () => {
|
||||
const user = {firstName : '', lastName : '', username: 'username'};
|
||||
const user = { firstName: '', lastName: '', username: 'username' };
|
||||
expect(pipe.transform(user)).toBe('username');
|
||||
});
|
||||
|
||||
it('should return user eamil when firstName, lastName and username are not available', () => {
|
||||
const user = {firstName : '', lastName : '', username: '', email: 'abcXyz@gmail.com'};
|
||||
it('should return user email when firstName, lastName and username are not available', () => {
|
||||
const user = { firstName: '', lastName: '', username: '', email: 'abcXyz@gmail.com' };
|
||||
expect(pipe.transform(user)).toBe('abcXyz@gmail.com');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,25 +18,17 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { UserLike } from './user-like.interface';
|
||||
|
||||
@Pipe({
|
||||
name: 'fullName',
|
||||
standalone: true
|
||||
})
|
||||
@Pipe({
|
||||
name: 'fullName',
|
||||
standalone: true
|
||||
})
|
||||
export class FullNamePipe implements PipeTransform {
|
||||
transform(user: UserLike): string {
|
||||
return this.buildFullName(user) ? this.buildFullName(user) : this.buildFromUsernameOrEmail(user);
|
||||
}
|
||||
|
||||
buildFullName(user: UserLike): string {
|
||||
const fullName: string[] = [];
|
||||
|
||||
fullName.push(user?.firstName);
|
||||
fullName.push(user?.lastName);
|
||||
|
||||
return fullName.join(' ').trim();
|
||||
}
|
||||
|
||||
buildFromUsernameOrEmail(user: UserLike): string {
|
||||
return (user?.username || user?.email) ?? '';
|
||||
const fullName = `${user?.firstName || ''} ${user?.lastName || ''}`.trim();
|
||||
return fullName || user?.username || user?.email || '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,7 @@
|
||||
|
||||
import { ExtensionElement } from './extension-element';
|
||||
|
||||
export interface DataColumnTypes {
|
||||
text: string;
|
||||
image: string;
|
||||
date: string;
|
||||
json: string;
|
||||
icon: string;
|
||||
fileSize: string;
|
||||
location: string;
|
||||
boolean: string;
|
||||
amount: string;
|
||||
number: string;
|
||||
}
|
||||
|
||||
export type DataColumnType = keyof DataColumnTypes;
|
||||
export type DataColumnType = 'text' | 'image' | 'date' | 'json' | 'icon' | 'fileSize' | 'location' | 'boolean' | 'amount' | 'number';
|
||||
|
||||
export interface DocumentListPresetRef extends ExtensionElement {
|
||||
key: string;
|
||||
|
||||
@@ -38,6 +38,7 @@ import { ComponentSelectionMode } from '../../types';
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { IdentityUserServiceInterface } from '../services/identity-user.service.interface';
|
||||
import { IDENTITY_USER_SERVICE_TOKEN } from '../services/identity-user-service.token';
|
||||
import { UserLike } from '../../../../../core/src/lib/pipes/user-like.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-cloud-people',
|
||||
@@ -141,6 +142,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@ViewChild('userInput')
|
||||
private userInput: ElementRef<HTMLInputElement>;
|
||||
|
||||
private fullNamePipe = new FullNamePipe();
|
||||
private searchUsers: IdentityUserModel[] = [];
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
@@ -409,8 +411,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
return this.invalidUsers && this.invalidUsers.length > 0;
|
||||
}
|
||||
|
||||
getDisplayName(user): string {
|
||||
return FullNamePipe.prototype.transform(user);
|
||||
getDisplayName(user: UserLike): string {
|
||||
return this.fullNamePipe.transform(user);
|
||||
}
|
||||
|
||||
private isMultipleMode(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user