-
Notifications
You must be signed in to change notification settings - Fork 11
feat: string array cell renderer #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @import 'font'; | ||
| @import 'color-palette'; | ||
|
|
||
| .string-array-cell { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
|
|
||
| .first-item { | ||
| padding-right: 8px; | ||
| } | ||
|
|
||
| .summary-text { | ||
| padding: 0 6px; | ||
| background-color: $gray-2; | ||
| border-radius: 4px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { TableCellNoOpParser } from '@hypertrace/components'; | ||
| import { createComponentFactory } from '@ngneat/spectator/jest'; | ||
| import { tableCellDataProvider, tableCellProviders } from '../../test/cell-providers'; | ||
| import { StringArrayTableCellRendererComponent } from './string-array-table-cell-renderer.component'; | ||
|
|
||
| describe('String array table cell renderer component', () => { | ||
| const buildComponent = createComponentFactory({ | ||
| component: StringArrayTableCellRendererComponent, | ||
| providers: [ | ||
| tableCellProviders( | ||
| { | ||
| id: 'test' | ||
| }, | ||
| new TableCellNoOpParser(undefined!) | ||
| ) | ||
| ], | ||
|
|
||
| shallow: true | ||
| }); | ||
|
|
||
| test('should render an array with one item as expected', () => { | ||
| const spectator = buildComponent({ | ||
| providers: [tableCellDataProvider(['first-item'])] | ||
| }); | ||
|
|
||
| expect(spectator.query('.first-item')).toHaveText('first-item'); | ||
| expect(spectator.query('.summary-text')).toHaveText(''); | ||
| }); | ||
|
|
||
| test('should render an empty array as expected', () => { | ||
| const spectator = buildComponent({ | ||
| providers: [tableCellDataProvider([])] | ||
| }); | ||
|
|
||
| expect(spectator.query('.first-item')).toHaveText('-'); | ||
| expect(spectator.query('.summary-text')).toHaveText(''); | ||
| }); | ||
|
|
||
| test('should render array with multiple items as expected', () => { | ||
| const spectator = buildComponent({ | ||
| providers: [tableCellDataProvider(['first-item', 'second-item', 'third-item'])] | ||
| }); | ||
|
|
||
| expect(spectator.query('.first-item')).toHaveText('first-item'); | ||
| expect(spectator.query('.summary-text')).toHaveText('+2'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { ChangeDetectionStrategy, Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core'; | ||
| import { TableColumnConfig, TableRow } from '../../../table-api'; | ||
| import { | ||
| TABLE_CELL_DATA, | ||
| TABLE_COLUMN_CONFIG, | ||
| TABLE_COLUMN_INDEX, | ||
| TABLE_DATA_PARSER, | ||
| TABLE_ROW_DATA | ||
| } from '../../table-cell-injection'; | ||
| import { TableCellParserBase } from '../../table-cell-parser-base'; | ||
| import { TableCellRenderer } from '../../table-cell-renderer'; | ||
| import { TableCellRendererBase } from '../../table-cell-renderer-base'; | ||
| import { CoreTableCellParserType } from '../../types/core-table-cell-parser-type'; | ||
| import { CoreTableCellRendererType } from '../../types/core-table-cell-renderer-type'; | ||
| import { TableCellAlignmentType } from '../../types/table-cell-alignment-type'; | ||
|
|
||
| @Component({ | ||
| selector: 'ht-string-array-table-cell-renderer', | ||
| styleUrls: ['./string-array-table-cell-renderer.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <div class="string-array-cell"> | ||
| <span class="first-item">{{ this.firstItem }}</span> | ||
| <span class="summary-text" [htTooltip]="this.summaryTooltip">{{ this.summaryText }}</span> | ||
|
||
|
|
||
| <ng-template #summaryTooltipElement> | ||
| <div *ngFor="let value of this.value.slice(1, this.value.length)">{{ value }}</div> | ||
aaron-steinfeld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ng-template> | ||
| </div> | ||
| ` | ||
| }) | ||
| @TableCellRenderer({ | ||
| type: CoreTableCellRendererType.StringArray, | ||
| alignment: TableCellAlignmentType.Left, | ||
| parser: CoreTableCellParserType.NoOp | ||
| }) | ||
| export class StringArrayTableCellRendererComponent extends TableCellRendererBase<string[]> implements OnInit { | ||
| public firstItem!: string; | ||
| public summaryText!: string; | ||
|
|
||
| @ViewChild('summaryTooltipElement') | ||
| public summaryTooltip!: TemplateRef<unknown>; | ||
|
|
||
| public constructor( | ||
| @Inject(TABLE_COLUMN_CONFIG) columnConfig: TableColumnConfig, | ||
| @Inject(TABLE_COLUMN_INDEX) index: number, | ||
| @Inject(TABLE_DATA_PARSER) parser: TableCellParserBase<string[], string[], unknown>, | ||
| @Inject(TABLE_CELL_DATA) cellData: string[], | ||
| @Inject(TABLE_ROW_DATA) rowData: TableRow | ||
| ) { | ||
| super(columnConfig, index, parser, cellData, rowData); | ||
| } | ||
|
|
||
| public ngOnInit(): void { | ||
| super.ngOnInit(); | ||
|
|
||
| this.firstItem = this.value[0] ?? '-'; | ||
| this.summaryText = this.value.length > 1 ? `+${this.value.length - 1}` : ''; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.