Skip to content

Commit f5d7615

Browse files
authored
Merge branch 'main' into nav-hyperlinks
2 parents 586bab8 + cc56d63 commit f5d7615

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

projects/assets-library/assets/styles/_color-palette.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ $color-health-red: $red-5;
9898
$color-health-unknown: $gray-7;
9999

100100
// Risk
101+
$color-risk-critical: $purple-6;
101102
$color-risk-high: $red-5;
102103
$color-risk-medium: $brown-1;
103104
$color-risk-low: $gray-6;

projects/common/src/color/color.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const enum Color {
1414
Gray9 = '#080909',
1515
Green2 = '#c3f3db',
1616
Green3 = '#95eabe',
17+
Green5 = '#27C675',
1718
Orange3 = '#FDC088',
1819
Orange5 = '#fb8b24',
1920
Purple2 = '#f2d0f5',

projects/components/src/select/select.component.test.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { HttpClientTestingModule } from '@angular/common/http/testing';
22
import { fakeAsync, flush } from '@angular/core/testing';
3+
import { By } from '@angular/platform-browser';
34
import { IconLibraryTestingModule, IconType } from '@hypertrace/assets-library';
45
import { NavigationService } from '@hypertrace/common';
6+
import { IconComponent } from '@hypertrace/components';
57
import { createHostFactory, mockProvider, SpectatorHost } from '@ngneat/spectator/jest';
8+
import { MockComponent } from 'ng-mocks';
69
import { EMPTY } from 'rxjs';
710
import { SelectControlOptionPosition } from './select-control-option.component';
811
import { SelectJustify } from './select-justify';
@@ -14,6 +17,7 @@ describe('Select Component', () => {
1417
component: SelectComponent,
1518
imports: [SelectModule, HttpClientTestingModule, IconLibraryTestingModule],
1619
declareComponent: false,
20+
declarations: [MockComponent(IconComponent)],
1721
providers: [
1822
mockProvider(NavigationService, {
1923
navigation$: EMPTY,
@@ -27,7 +31,7 @@ describe('Select Component', () => {
2731
const selectionOptions = [
2832
{ label: 'first', value: 'first-value' },
2933
{ label: 'second', value: 'second-value' },
30-
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!' }
34+
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!', icon: 'test-icon', iconColor: 'red' }
3135
];
3236

3337
test('should display initial selection', fakeAsync(() => {
@@ -146,12 +150,56 @@ describe('Select Component', () => {
146150
const optionElements = spectator.queryAll('.select-option', { root: true });
147151
spectator.click(optionElements[2]);
148152

149-
expect(onChange).toHaveBeenCalledTimes(1);
150153
expect(onChange).toHaveBeenCalledWith(selectionOptions[2].value);
151154
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[2].selectedLabel!);
152155
flush();
153156
}));
154157

158+
test('should set trigger-prefix-icon correctly', fakeAsync(() => {
159+
spectator = hostFactory(
160+
`
161+
<ht-select [icon]="icon">
162+
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value" [icon]="option.icon" [iconColor]="option.iconColor">
163+
</ht-select-option>
164+
</ht-select>`,
165+
{
166+
hostProps: {
167+
options: selectionOptions,
168+
icon: 'select-level-icon'
169+
}
170+
}
171+
);
172+
spectator.tick();
173+
174+
// No selection -> select component level icon and no color
175+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe(
176+
'select-level-icon'
177+
);
178+
// tslint:disable-next-line:no-null-keyword
179+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe(null);
180+
181+
// Selection with no icon -> default icon and no color
182+
spectator.click('.trigger-content');
183+
let optionElements = spectator.queryAll('.select-option', { root: true });
184+
spectator.click(optionElements[1]);
185+
spectator.tick();
186+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe(
187+
'select-level-icon'
188+
);
189+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe(undefined);
190+
191+
// Selection with icon and color
192+
spectator.click('.trigger-content');
193+
optionElements = spectator.queryAll('.select-option', { root: true });
194+
spectator.click(optionElements[2]);
195+
spectator.tick();
196+
197+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.icon).toBe('test-icon');
198+
expect(spectator.debugElement.query(By.css('.trigger-prefix-icon')).componentInstance.color).toBe('red');
199+
200+
flush();
201+
}));
202+
155203
test('should set correct label alignment', fakeAsync(() => {
156204
spectator = hostFactory(
157205
`

projects/components/src/select/select.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ import { SelectSize } from './select-size';
5555
class="trigger-content menu-with-border"
5656
[ngClass]="[this.justifyClass]"
5757
>
58-
<ht-icon *ngIf="this.icon" class="trigger-prefix-icon" [icon]="this.icon" [size]="this.iconSize">
58+
<ht-icon
59+
*ngIf="this.getPrefixIcon(selected)"
60+
class="trigger-prefix-icon"
61+
[icon]="this.getPrefixIcon(selected)"
62+
[size]="this.iconSize"
63+
[color]="selected?.iconColor"
64+
>
5965
</ht-icon>
6066
<ht-label class="trigger-label" [label]="selected?.selectedLabel || selected?.label || this.placeholder">
6167
</ht-label>
@@ -204,6 +210,10 @@ export class SelectComponent<V> implements AfterContentInit, OnChanges {
204210
}
205211
}
206212

213+
public getPrefixIcon(selectedOption: SelectOption<V> | undefined): string | undefined {
214+
return selectedOption?.icon ?? this.icon;
215+
}
216+
207217
public ngOnChanges(changes: TypedSimpleChanges<this>): void {
208218
if (this.items !== undefined && changes.selected !== undefined) {
209219
this.selected$ = this.buildObservableOfSelected();

projects/components/src/summay-card/summary-card.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
&.gray {
4343
background-color: $gray-6;
4444
}
45+
46+
&.purple {
47+
background-color: $purple-6;
48+
}
4549
}
4650
}
4751

@@ -67,6 +71,10 @@
6771
&.gray {
6872
color: $gray-6;
6973
}
74+
75+
&.purple {
76+
color: $purple-6;
77+
}
7078
}
7179

7280
.footer {

projects/components/src/summay-card/summary-card.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
export const enum SummaryCardColor {
33
Red = 'red',
44
Brown = 'brown',
5-
Gray = 'gray'
5+
Gray = 'gray',
6+
Purple = 'purple'
67
}
78

89
export interface SummaryValue {

0 commit comments

Comments
 (0)