Skip to content

Commit 4fab2c8

Browse files
authored
fix: update display string conversion logic (#686)
* fix: update display string conversion logic
1 parent 2c36aa8 commit 4fab2c8

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

projects/common/src/utilities/formatters/string/string-formatter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ describe('String formatter', () => {
2121
test('can convert to display string', () => {
2222
// tslint:disable-next-line: no-null-keyword
2323
expect(displayString(null)).toBe('-');
24-
expect(displayString(undefined)).toBe('Unknown');
25-
expect(displayString('')).toBe('Unknown');
24+
expect(displayString(undefined)).toBe('-');
25+
expect(displayString('')).toBe('');
2626
expect(displayString('value')).toBe('value');
2727
expect(displayString(15)).toBe('15');
2828
expect(displayString({})).toBe('Object');
29-
expect(displayString([undefined])).toBe('[Unknown]');
29+
expect(displayString([undefined])).toBe('[-]');
3030
expect(displayString(() => 'hi')).toBe('Function');
3131
expect(displayString(Symbol('test symbol'))).toBe('Symbol(test symbol)');
3232
expect(displayString(false)).toBe('false');

projects/common/src/utilities/formatters/string/string-formatter.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { isEmpty } from 'lodash-es';
2-
31
export const titleCaseFromKebabCase = (kebabCaseString: string): string =>
42
kebabCaseString
53
.split('-')
@@ -19,17 +17,13 @@ export const displayString = (provided?: unknown): string => {
1917

2018
switch (typeof provided) {
2119
case 'object':
22-
return Array.isArray(provided)
23-
? `[${provided.map(displayString).join(', ')}]`
24-
: provided === null
25-
? 'Unknown'
26-
: 'Object';
20+
return Array.isArray(provided) ? `[${provided.map(displayString).join(', ')}]` : 'Object';
2721
case 'undefined':
28-
return 'Unknown';
22+
return '-';
2923
case 'function':
3024
return 'Function';
3125
case 'string':
32-
return isEmpty(provided) ? 'Unknown' : provided;
26+
return provided;
3327
case 'boolean':
3428
case 'number':
3529
case 'bigint':

projects/components/src/table/cells/data-renderers/code/code-table-cell-renderer.component.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Code table cell renderer component', () => {
3434
test('should render a missing string', () => {
3535
const spectator = buildComponent();
3636

37-
expect(spectator.element).toHaveText('Unknown');
38-
expect(spectator.query(TooltipDirective)?.content).toBe('Unknown');
37+
expect(spectator.element).toHaveText('-');
38+
expect(spectator.query(TooltipDirective)?.content).toBe('-');
3939
});
4040
});

projects/components/src/table/cells/data-renderers/string-array/string-array-table-cell-renderer.component.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FormattingModule } from '@hypertrace/common';
12
import { TableCellNoOpParser } from '@hypertrace/components';
23
import { createComponentFactory } from '@ngneat/spectator/jest';
34
import { tableCellDataProvider, tableCellProviders } from '../../test/cell-providers';
@@ -6,6 +7,7 @@ import { StringArrayTableCellRendererComponent } from './string-array-table-cell
67
describe('String array table cell renderer component', () => {
78
const buildComponent = createComponentFactory({
89
component: StringArrayTableCellRendererComponent,
10+
imports: [FormattingModule],
911
providers: [
1012
tableCellProviders(
1113
{

projects/components/src/table/cells/data-renderers/string-array/string-array-table-cell-renderer.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { TableCellAlignmentType } from '../../types/table-cell-alignment-type';
2020
changeDetection: ChangeDetectionStrategy.OnPush,
2121
template: `
2222
<div class="string-array-cell" [htTooltip]="summaryTooltip">
23-
<span class="first-item">{{ this.firstItem }}</span>
23+
<span class="first-item">{{ this.firstItem | htDisplayString }}</span>
2424
<span class="summary-text">{{ this.summaryText }}</span>
2525
2626
<ng-template #summaryTooltip>
@@ -51,7 +51,7 @@ export class StringArrayTableCellRendererComponent extends TableCellRendererBase
5151
public ngOnInit(): void {
5252
super.ngOnInit();
5353

54-
this.firstItem = this.value[0] ?? '-';
54+
this.firstItem = this.value[0];
5555
this.summaryText = this.value.length > 1 ? `+${this.value.length - 1}` : '';
5656
}
5757
}

0 commit comments

Comments
 (0)