Skip to content

Commit 5aadb52

Browse files
author
Patricio Albizu
committed
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into UnableToClickTopology
2 parents 2dfb578 + d113815 commit 5aadb52

File tree

6 files changed

+94
-26
lines changed

6 files changed

+94
-26
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/d3-transition": "1.1.5",
4343
"apollo-angular": "^2.4.0",
4444
"core-js": "^3.9.1",
45-
"d3-array": "^2.11.0",
45+
"d3-array": "^2.12.0",
4646
"d3-axis": "^2.1.0",
4747
"d3-brush": "^1.1.6",
4848
"d3-color": "^1.4.0",

projects/observability/src/shared/components/card-list/card-list.component.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@import 'mixins';
22

3+
@mixin grouped-style($color) {
4+
box-shadow: 0 3px 0 -1px $color, 0 4px 0 -1px $gray-2;
5+
}
6+
37
.ht-card-list {
48
display: flex;
59
flex-direction: column;
@@ -23,16 +27,31 @@
2327
background: $blue-1;
2428
border: 1px solid $blue-2;
2529

30+
&.grouped-style {
31+
margin-bottom: 8px;
32+
@include grouped-style($blue-1);
33+
}
34+
2635
&:hover {
2736
background: $blue-2;
2837
border: 1px solid $blue-5;
38+
39+
&.grouped-style {
40+
margin-bottom: 8px;
41+
@include grouped-style($blue-2);
42+
}
2943
}
3044
}
3145

3246
&:hover {
3347
background: $gray-1;
3448
border: 1px solid $gray-2;
3549
}
50+
51+
&.grouped-style {
52+
margin-bottom: 8px;
53+
@include grouped-style($gray-1);
54+
}
3655
}
3756

3857
.list {

projects/observability/src/shared/components/card-list/card-list.component.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,46 @@ describe('Card List component', () => {
6262
expect(spectator.query('.selected-card')).not.toBe(cardElements[1]);
6363
expect(spectator.query('.selected-card')).not.toBe(cardElements[2]);
6464
});
65+
66+
test('should apply grouped style class', () => {
67+
const data = [
68+
{
69+
name: 'first',
70+
grouped: true
71+
},
72+
{
73+
name: 'second',
74+
grouped: false
75+
},
76+
{
77+
name: 'third',
78+
grouped: false
79+
}
80+
];
81+
82+
spectator = createHost(
83+
`
84+
<ht-card-list [mode]="mode">
85+
<ht-card-container *ngFor="let cardData of this.data; first" showGroupedStyle="cardData.grouped">
86+
<div class="custom-card">
87+
<div class="title">{{cardData.name}}</div>
88+
</div>
89+
</ht-card-container>
90+
</ht-card-list>
91+
`,
92+
{
93+
hostProps: {
94+
data: data,
95+
mode: CardListMode.Card
96+
}
97+
}
98+
);
99+
100+
// Test selection style
101+
const cardElements = spectator.queryAll('.card');
102+
spectator.click(cardElements[0]);
103+
expect(spectator.query('.grouped-style')).toBe(cardElements[0]);
104+
expect(spectator.query('.grouped-style')).not.toBe(cardElements[1]);
105+
expect(spectator.query('.grouped-style')).not.toBe(cardElements[2]);
106+
});
65107
});

projects/observability/src/shared/components/card-list/card-list.component.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ChangeDetectionStrategy, Component, ContentChildren, Input, QueryList } from '@angular/core';
1+
import { AfterContentInit, ChangeDetectionStrategy, Component, ContentChildren, Input, QueryList } from '@angular/core';
2+
import { queryListAndChanges$ } from '@hypertrace/common';
3+
import { Observable } from 'rxjs';
4+
import { map } from 'rxjs/operators';
25
import { CardContainerComponent } from './container/card-container.component';
36

47
@Component({
@@ -7,8 +10,13 @@ import { CardContainerComponent } from './container/card-container.component';
710
<div class="ht-card-list">
811
<div
912
class="content"
10-
[ngClass]="this.getCardStyle(card)"
11-
*ngFor="let card of this.cards"
13+
[ngClass]="{
14+
card: this.mode === '${CardListMode.Card}',
15+
list: this.mode === '${CardListMode.List}',
16+
'selected-card': this.selectedCard === card,
17+
'grouped-style': card.showGroupedStyle
18+
}"
19+
*ngFor="let card of this.cards$ | async"
1220
(click)="this.onCardClicked(card)"
1321
>
1422
<ng-container *ngTemplateOutlet="card.content"></ng-container>
@@ -18,27 +26,23 @@ import { CardContainerComponent } from './container/card-container.component';
1826
styleUrls: ['./card-list.component.scss'],
1927
changeDetection: ChangeDetectionStrategy.OnPush
2028
})
21-
export class CardListComponent {
22-
@ContentChildren(CardContainerComponent)
23-
public readonly cards!: QueryList<CardContainerComponent>;
24-
29+
export class CardListComponent implements AfterContentInit {
2530
@Input()
2631
public mode?: CardListMode = CardListMode.List;
2732

28-
public selectedCard?: CardContainerComponent;
33+
@ContentChildren(CardContainerComponent)
34+
private readonly cards!: QueryList<CardContainerComponent>;
2935

30-
public onCardClicked(card: CardContainerComponent): void {
31-
this.selectedCard = this.selectedCard === card ? undefined : card;
32-
}
36+
public cards$!: Observable<CardContainerComponent[]>;
3337

34-
public getCardStyle(card: CardContainerComponent): string[] {
35-
const classes: string[] = [this.mode ?? CardListMode.List];
38+
public ngAfterContentInit(): void {
39+
this.cards$ = queryListAndChanges$(this.cards).pipe(map(list => list.toArray()));
40+
}
3641

37-
if (this.selectedCard === card) {
38-
classes.push('selected-card');
39-
}
42+
public selectedCard?: CardContainerComponent;
4043

41-
return classes;
44+
public onCardClicked(card: CardContainerComponent): void {
45+
this.selectedCard = this.selectedCard === card ? undefined : card;
4246
}
4347
}
4448

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { ChangeDetectionStrategy, Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
22
import { ContentHolder, CONTENT_HOLDER_TEMPLATE } from '@hypertrace/components';
33

44
@Component({
55
selector: 'ht-card-container',
66
template: CONTENT_HOLDER_TEMPLATE,
77
changeDetection: ChangeDetectionStrategy.OnPush
88
})
9-
export class CardContainerComponent extends ContentHolder {}
9+
export class CardContainerComponent extends ContentHolder {
10+
@Input()
11+
public showGroupedStyle: boolean = false;
12+
}

0 commit comments

Comments
 (0)