Skip to content

Commit

Permalink
[AAE-17103] Update IconCellComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktord2000 committed Oct 23, 2023
1 parent b4fa42c commit 46892e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('IconCellComponent', () => {

fixture = TestBed.createComponent(IconCellComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

describe('Initialization', () => {
Expand Down Expand Up @@ -81,11 +80,8 @@ describe('IconCellComponent', () => {
});

describe('UI', () => {
it('should render icon element in case of non-empty string (icon name validation NOT included)', () => {
it('should render icon element in case of non-empty string', () => {
renderAndCheckResult('group', true, 'group');
renderAndCheckResult('groupe', true, 'groupe');
renderAndCheckResult('0', true, '0');
renderAndCheckResult('true', true, 'true');
});

describe('should NOT render icon element in case of', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,32 @@ import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component';
import { TypeofPipe } from '../../../pipes/typeof.pipe';
import { takeUntil } from 'rxjs/operators';

@Component({
standalone: true,
imports: [CommonModule, MatIconModule, TypeofPipe],
imports: [CommonModule, MatIconModule],
selector: 'adf-icon-cell',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-container *ngIf="value$ | async as value">
<mat-icon [title]="tooltip" *ngIf="(value | adfTypeof) === 'string'" aria-hidden="true">{{ value }}</mat-icon>
<ng-container *ngIf="icon">
<mat-icon [title]="tooltip" aria-hidden="true">{{ icon }}</mat-icon>
</ng-container>
`,
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-content-cell' }
})
export class IconCellComponent extends DataTableCellComponent implements OnInit {
protected icon: string = '';

ngOnInit(): void {
this.value$.pipe(takeUntil(this.onDestroy$)).subscribe((value) => {
this.icon = this.validateIconValue(value) ? value : '';
});
super.ngOnInit();
}

private validateIconValue(value: any): boolean {
return typeof value === 'string';
};
}

0 comments on commit 46892e6

Please sign in to comment.