-
Notifications
You must be signed in to change notification settings - Fork 11
feat: string enum table cell renderer #787
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 all 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,19 @@ | ||
@import 'font'; | ||
@import 'color-palette'; | ||
|
||
:host { | ||
overflow: hidden; | ||
} | ||
|
||
.string-enum-cell { | ||
@include ellipsis-overflow(); | ||
@include body-1-regular($gray-7); | ||
|
||
&.first-column { | ||
@include body-1-medium($gray-9); | ||
} | ||
} | ||
|
||
.clickable { | ||
@include link-hover(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { FormattingModule } from '@hypertrace/common'; | ||
import { byText, createComponentFactory } from '@ngneat/spectator/jest'; | ||
import { TableCellStringParser } from '../../data-parsers/table-cell-string-parser'; | ||
import { tableCellColumnProvider, tableCellDataProvider, tableCellProviders } from '../../test/cell-providers'; | ||
import { StringEnumTableCellRendererComponent } from './string-enum-table-cell-renderer.component'; | ||
|
||
describe('String Enum table cell renderer component', () => { | ||
const buildComponent = createComponentFactory({ | ||
component: StringEnumTableCellRendererComponent, | ||
imports: [FormattingModule], | ||
providers: [ | ||
tableCellProviders( | ||
{ | ||
id: 'test' | ||
}, | ||
new TableCellStringParser(undefined!) | ||
) | ||
], | ||
shallow: true | ||
}); | ||
|
||
test('should render a plain string', () => { | ||
const spectator = buildComponent({ | ||
providers: [tableCellDataProvider('test-text')] | ||
}); | ||
|
||
expect(spectator.element).toHaveText('Test text'); | ||
}); | ||
|
||
test('should render a missing string', () => { | ||
const spectator = buildComponent(); | ||
|
||
expect(spectator.element).toHaveText(''); | ||
}); | ||
|
||
test('should add clickable class for clickable columns', () => { | ||
const spectator = buildComponent({ | ||
providers: [ | ||
tableCellDataProvider('test-text'), | ||
tableCellColumnProvider({ | ||
id: 'test', | ||
onClick: () => { | ||
/* NOOP */ | ||
} | ||
}) | ||
] | ||
}); | ||
|
||
expect(spectator.query(byText('Test text'))).toHaveClass('clickable'); | ||
}); | ||
|
||
test('should not add clickable class for columns without a click handler', () => { | ||
const spectator = buildComponent({ | ||
providers: [tableCellDataProvider('TEST_TEXT')] | ||
}); | ||
|
||
expect(spectator.query(byText('Test text'))).not.toHaveClass('clickable'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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-string-enum-table-cell-renderer', | ||
styleUrls: ['./string-enum-table-cell-renderer.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<div | ||
[ngClass]="{ clickable: this.clickable, 'first-column': this.isFirstColumn }" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what advantage do we get compared to directly supplying the startcased enum value to a regular string cell renderer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing other than this does the text presentation for you. It has been coming up more and more, so this is a convenience, but it also feels (at least to me) more correct to have the presentation logic in the cell renderer rather than pre-formatting it before passing it in. |
||
class="string-enum-cell" | ||
[htTooltip]="this.value" | ||
> | ||
{{ this.value | htDisplayStringEnum }} | ||
</div> | ||
` | ||
}) | ||
@TableCellRenderer({ | ||
type: CoreTableCellRendererType.StringEnum, | ||
alignment: TableCellAlignmentType.Left, | ||
parser: CoreTableCellParserType.String | ||
}) | ||
export class StringEnumTableCellRendererComponent extends TableCellRendererBase<string> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: IMO, the name 'String Enum' is not very clear. Or we can at least add similar comments from
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always struggle with names, but also always open to suggestions. I've added the comment in my local. That should help some. Not worth holding up this PR for, but I'll commit them in whatever next HT PR I have. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,21 @@ h1 { | |
box-sizing: border-box; | ||
} | ||
|
||
strong { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this change, but needed for another. |
||
font-weight: 500; | ||
} | ||
|
||
em { | ||
font-style: normal; | ||
background: $gray-2; | ||
border-radius: 4px; | ||
padding: 2px 4px; | ||
} | ||
|
||
q { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are these for? |
||
color: $gray-5; | ||
} | ||
|
||
mark { | ||
background-color: $color-text-highlight; | ||
color: $gray-9; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?