diff --git a/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.scss b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.scss new file mode 100644 index 000000000..e2c1d2224 --- /dev/null +++ b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.scss @@ -0,0 +1,13 @@ +@import 'font'; +@import 'color-palette'; + +.code-cell { + @include code($gray-7); + @include ellipsis-overflow(); + background-color: $gray-2; + border-radius: 4px; + padding: 0 4px; + display: inline-block; + max-width: 100%; + vertical-align: text-bottom; +} diff --git a/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.test.ts b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.test.ts new file mode 100644 index 000000000..b433b158c --- /dev/null +++ b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.test.ts @@ -0,0 +1,40 @@ +import { FormattingModule } from '@hypertrace/common'; +import { createComponentFactory } from '@ngneat/spectator/jest'; +import { MockDirective } from 'ng-mocks'; +import { TooltipDirective } from '../../../../tooltip/tooltip.directive'; +import { TableCellStringParser } from '../../data-parsers/table-cell-string-parser'; +import { tableCellDataProvider, tableCellProviders } from '../../test/cell-providers'; +import { CodeTableCellRendererComponent } from './code-table-cell-renderer.component'; + +describe('Code table cell renderer component', () => { + const buildComponent = createComponentFactory({ + component: CodeTableCellRendererComponent, + imports: [FormattingModule], + providers: [ + tableCellProviders( + { + id: 'test' + }, + new TableCellStringParser(undefined!) + ) + ], + declarations: [MockDirective(TooltipDirective)], + shallow: true + }); + + test('should render a plain string', () => { + const spectator = buildComponent({ + providers: [tableCellDataProvider('test text')] + }); + + expect(spectator.element).toHaveText('test text'); + expect(spectator.query(TooltipDirective)?.content).toBe('test text'); + }); + + test('should render a missing string', () => { + const spectator = buildComponent(); + + expect(spectator.element).toHaveText('Unknown'); + expect(spectator.query(TooltipDirective)?.content).toBe('Unknown'); + }); +}); diff --git a/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.ts b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.ts new file mode 100644 index 000000000..bfdd20c69 --- /dev/null +++ b/projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.ts @@ -0,0 +1,23 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core'; +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-code-table-cell-renderer', + styleUrls: ['./code-table-cell-renderer.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, + template: ` +