-
Notifications
You must be signed in to change notification settings - Fork 11
Summary list component #706
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
983f8bf
67ca901
472f652
c5f9c38
5ac7f1a
f6e778d
1f94365
843d189
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,6 @@ | ||
| import { PrimitiveValue } from '@hypertrace/common'; | ||
|
|
||
| export interface SummaryItem { | ||
| label: string; | ||
| value: PrimitiveValue | PrimitiveValue[]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| @import 'mixins'; | ||
|
|
||
| .summary-list { | ||
| padding: 16px; | ||
|
|
||
| .summary-header { | ||
| display: flex; | ||
| align-items: center; | ||
| padding-top: 4px; | ||
| padding-bottom: 16px; | ||
| border-bottom: 1px solid $gray-2; | ||
|
|
||
| .summary-icon { | ||
| color: $gray-7; | ||
| padding-right: 8px; | ||
| } | ||
|
|
||
| .summary-title { | ||
| @include body-2-medium($gray-7); | ||
| } | ||
| } | ||
|
|
||
| .summary-value-title { | ||
| @include body-2-medium($gray-7); | ||
| display: block; | ||
| padding-top: 16px; | ||
| } | ||
|
|
||
| .summary-value-list { | ||
| list-style-type: none; | ||
| margin: 0; | ||
| padding: 0; | ||
|
|
||
| .summary-value { | ||
| @include body-2-regular($gray-7); | ||
| padding-top: 3px; | ||
|
|
||
| &:first-child { | ||
| padding-top: 6px; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { IconType } from '@hypertrace/assets-library'; | ||
| import { IconComponent, LabelComponent, SummaryListComponent } from '@hypertrace/components'; | ||
| import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; | ||
| import { MockComponent } from 'ng-mocks'; | ||
|
|
||
| describe('Summary List component', () => { | ||
| let spectator: SpectatorHost<SummaryListComponent>; | ||
|
|
||
| const createHost = createHostFactory({ | ||
| component: SummaryListComponent, | ||
|
Contributor
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. For a component with inputs and ouputs, using a hostfactory allows you to provide inputs and then verify it rendered correctly. This test only verifies the logic directly rather than for a given set of inputs it renders the html we want - that's what we're generally looking for in a component's tests - the functions are implementation details. |
||
| shallow: true, | ||
| declarations: [MockComponent(IconComponent), MockComponent(LabelComponent)] | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| spectator = createHost( | ||
| ` | ||
| <ht-summary-list | ||
| [title]="title" | ||
| [icon]="icon" | ||
| [items]="items" | ||
| ></ht-summary-list>`, | ||
| { | ||
| hostProps: { | ||
| title: 'My Title', | ||
| icon: IconType.Add, | ||
| items: [ | ||
| { | ||
| label: 'number', | ||
| value: 0 | ||
| }, | ||
| { | ||
| label: 'Number-Array', | ||
| value: [0, 1, 2] | ||
| }, | ||
| { | ||
| label: 'STRING', | ||
| value: 'zero' | ||
| }, | ||
| { | ||
| label: 'STRING_ARRAY', | ||
| value: ['zero', 'one', 'two', 'three'] | ||
| }, | ||
| { | ||
| label: 'bOOleAN', | ||
| value: true | ||
| }, | ||
| { | ||
| label: 'boolean-array', | ||
| value: [true, false] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('sets title and icon', () => { | ||
| expect(spectator.query('.summary-icon', { read: IconComponent })?.icon).toEqual(IconType.Add); | ||
| expect(spectator.query('.summary-title', { read: LabelComponent })?.label).toEqual('My Title'); | ||
| }); | ||
|
|
||
| test('formats label', () => { | ||
| const labelComponents = spectator.queryAll('.summary-value-title', { read: LabelComponent }); | ||
| expect(labelComponents.map(c => c.label)).toEqual([ | ||
| 'Number', | ||
| 'Number Array', | ||
| 'String', | ||
| 'String Array', | ||
| 'Boolean', | ||
| 'Boolean Array' | ||
| ]); | ||
| }); | ||
|
|
||
| test('gets value array', () => { | ||
| const values = spectator.queryAll('li').map(e => e.textContent); | ||
| expect(values).toEqual(['0', '0', '1', '2', 'zero', 'zero', 'one', 'two', 'three', 'true', 'true', 'false']); | ||
|
Contributor
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.
Contributor
Author
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. It was worth updating this test just to see that video. |
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
| import { IconType } from '@hypertrace/assets-library'; | ||
| import { PrimitiveValue } from '@hypertrace/common'; | ||
| import { startCase } from 'lodash-es'; | ||
| import { SummaryItem } from './summary-list-api'; | ||
|
|
||
| @Component({ | ||
| selector: 'ht-summary-list', | ||
|
Contributor
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 don't love the name (when do I ever?). We already have a list-view, card-list, summary-values, table - so from the names, it's not clear how this one is different and when to use which.
Contributor
Author
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. Yeah, I was scanning through our components and thinking the same thing. Open to suggestions. :-)
Contributor
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. Ah, of course - my own words turned against me. In that case, carry on. |
||
| styleUrls: ['./summary-list.component.scss'], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: ` | ||
| <div class="summary-list full-container"> | ||
| <div class="summary-header" *ngIf="this.title || this.icon"> | ||
| <ht-icon class="summary-icon" [icon]="this.icon"></ht-icon> | ||
| <ht-label class="summary-title" [label]="this.title"></ht-label> | ||
| </div> | ||
| <ng-container *ngFor="let item of this.items"> | ||
| <ht-label class="summary-value-title" [label]="this.getFormattedLabel(item.label)"></ht-label> | ||
| <ul class="summary-value-list"> | ||
| <li class="summary-value" *ngIf="this.getValuesArray(item.value).length === 0">None</li> | ||
| <li class="summary-value" *ngFor="let value of this.getValuesArray(item.value)">{{ value }}</li> | ||
| </ul> | ||
| </ng-container> | ||
| </div> | ||
| ` | ||
| }) | ||
| export class SummaryListComponent { | ||
| @Input() | ||
| public title?: string; | ||
|
|
||
| @Input() | ||
| public icon?: IconType; | ||
|
|
||
| @Input() | ||
| public items?: SummaryItem[] = []; | ||
|
|
||
| public getFormattedLabel(label: string): string { | ||
| return startCase(label.toLowerCase()); | ||
| } | ||
|
|
||
| public getValuesArray(value: PrimitiveValue | PrimitiveValue[]): PrimitiveValue[] { | ||
| return Array.isArray(value) ? value : [value]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { CommonModule } from '@angular/common'; | ||
| import { NgModule } from '@angular/core'; | ||
| import { FormattingModule } from '@hypertrace/common'; | ||
| import { IconModule } from '../icon/icon.module'; | ||
| import { LabelModule } from '../label/label.module'; | ||
| import { LoadAsyncModule } from '../load-async/load-async.module'; | ||
| import { SummaryListComponent } from './summary-list.component'; | ||
|
|
||
| @NgModule({ | ||
| declarations: [SummaryListComponent], | ||
| exports: [SummaryListComponent], | ||
| imports: [CommonModule, LoadAsyncModule, FormattingModule, LabelModule, IconModule] | ||
| }) | ||
| export class SummaryListModule {} |
Uh oh!
There was an error while loading. Please reload this page.