Skip to content

Commit 8276198

Browse files
authored
feat: conditional container widget (#348)
* feat: conditional container widget * feat: conditional widget * fix: pr comments * fix: import order
1 parent 46b4982 commit 8276198

File tree

10 files changed

+87
-5
lines changed

10 files changed

+87
-5
lines changed

projects/dashboards/src/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './properties/primitives/string-property-editor.component';
77
export * from './properties/dashboard-properties.module';
88

99
// Repeat
10-
export { ModelTemplatePropertyType } from './widgets/repeat/property-types/model-template-type';
10+
export { ModelTemplatePropertyType } from './properties/property-types/model-template-type';
1111

1212
export * from './persistence/dashboard-persistence.service';
1313
export * from './widgets/widget-renderer';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { Renderer } from '@hypertrace/hyperdash';
3+
import { Observable } from 'rxjs';
4+
import { takeUntil } from 'rxjs/operators';
5+
import { WidgetRenderer } from '../widget-renderer';
6+
import { ConditionalModel } from './conditional.model';
7+
8+
@Renderer({ modelClass: ConditionalModel })
9+
@Component({
10+
selector: 'ht-conditional-widget',
11+
changeDetection: ChangeDetectionStrategy.OnPush,
12+
template: ` <ng-container [hdaDashboardModel]="this.getChildModel() | async"> </ng-container> `
13+
})
14+
export class ConditionalWidgetRendererComponent extends WidgetRenderer<ConditionalModel> {
15+
public getChildModel(): Observable<object> {
16+
return this.model.getChildModel().pipe(takeUntil(this.destroyed$));
17+
}
18+
19+
protected fetchData(): Observable<object> {
20+
return this.getChildModel();
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { CommonModule } from '@angular/common';
2+
import { NgModule } from '@angular/core';
3+
import { DashboardCoreModule } from '@hypertrace/hyperdash-angular';
4+
import { ConditionalWidgetRendererComponent } from './conditional-widget-renderer.component';
5+
import { ConditionalModel } from './conditional.model';
6+
7+
@NgModule({
8+
declarations: [ConditionalWidgetRendererComponent],
9+
imports: [
10+
CommonModule,
11+
DashboardCoreModule.with({
12+
models: [ConditionalModel],
13+
renderers: [ConditionalWidgetRendererComponent]
14+
})
15+
]
16+
})
17+
export class ConditionalWidgetModule {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Model, ModelApi, ModelJson, ModelProperty } from '@hypertrace/hyperdash';
2+
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
3+
import { Observable } from 'rxjs';
4+
import { map } from 'rxjs/operators';
5+
import { ModelTemplatePropertyType } from '../../properties/property-types/model-template-type';
6+
7+
@Model({
8+
type: 'conditional'
9+
})
10+
export class ConditionalModel {
11+
@ModelProperty({
12+
key: 'true',
13+
type: ModelTemplatePropertyType.TYPE,
14+
required: true
15+
})
16+
public true!: ModelJson;
17+
18+
@ModelProperty({
19+
key: 'false',
20+
type: ModelTemplatePropertyType.TYPE,
21+
required: true
22+
})
23+
public false!: ModelJson;
24+
25+
@ModelInject(MODEL_API)
26+
private readonly api!: ModelApi;
27+
28+
public getData(): Observable<boolean> {
29+
return this.api.getData<boolean>();
30+
}
31+
32+
public getChildModel(): Observable<object> {
33+
return this.getData().pipe(map(result => this.api.createChild(result ? this.true : this.false)));
34+
}
35+
}

projects/dashboards/src/widgets/dashboard-widgets.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3+
import { ConditionalWidgetModule } from './conditional/conditional-widget.module';
34
import { ContainerWidgetModule } from './container/container-widget.module';
45
import { DividerWidgetModule } from './divider/divider-widget.module';
56
import { GreetingLabelWidgetModule } from './greeting-label/greeting-label-widget.module';
@@ -18,7 +19,8 @@ import { TextWidgetModule } from './text/text-widget.module';
1819
JsonWidgetModule,
1920
RepeatModule,
2021
TextWidgetModule,
21-
GreetingLabelWidgetModule
22+
GreetingLabelWidgetModule,
23+
ConditionalWidgetModule
2224
]
2325
})
2426
export class DashboardWidgetsModule {}

projects/dashboards/src/widgets/repeat/repeat.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
1010
import { Observable, of } from 'rxjs';
1111
import { map, tap } from 'rxjs/operators';
1212
import { StaticDataSource } from '../../data/static/static-data-source.model';
13+
import { ModelTemplatePropertyType } from '../../properties/property-types/model-template-type';
1314
import { AutoContainerLayoutModel } from '../container/layout/auto/auto-container-layout.model';
1415
import { ContainerLayout } from '../container/layout/container-layout';
15-
import { ModelTemplatePropertyType } from './property-types/model-template-type';
1616

1717
@Model({
1818
type: 'repeat'

projects/dashboards/src/widgets/repeat/repeat.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NgModule, Type } from '@angular/core';
33
import { ModelPropertyTypeRegistrationInformation } from '@hypertrace/hyperdash';
44
import { DashboardCoreModule } from '@hypertrace/hyperdash-angular';
55
import { StaticDataSourceModule } from '../../data/static/static-data-source.module';
6-
import { ModelTemplatePropertyType } from './property-types/model-template-type';
6+
import { ModelTemplatePropertyType } from '../../properties/property-types/model-template-type';
77
import { RepeatRendererComponent } from './repeat-renderer.component';
88
import { RepeatModel } from './repeat.model';
99

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Observable } from 'rxjs';
2+
import { GraphQlDataSourceModel } from '../graphql-data-source.model';
3+
4+
export abstract class ConditionalDataSourceModel extends GraphQlDataSourceModel<boolean> {
5+
public abstract getData(): Observable<boolean>;
6+
}

projects/distributed-tracing/src/shared/dashboard/data/graphql/table/table-data-source.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { GraphQlArgumentValue } from '@hypertrace/graphql-client';
33
import { ModelProperty, NUMBER_PROPERTY } from '@hypertrace/hyperdash';
44
import { Observable, of as observableOf } from 'rxjs';
55
import { map } from 'rxjs/operators';
6-
import { GraphQlFilter } from '../../../../../shared/graphql/model/schema/filter/graphql-filter';
76
import { GraphQlFieldFilter } from '../../../../graphql/model/schema/filter/field/graphql-field-filter';
7+
import { GraphQlFilter } from '../../../../graphql/model/schema/filter/graphql-filter';
88
import { toGraphQlOperator } from '../../../../services/filter-builder/graphql-filter-builder.service';
99
import { SpecificationBackedTableColumnDef } from '../../../widgets/table/table-widget-column.model';
1010
import { GraphQlDataSourceModel } from '../graphql-data-source.model';

0 commit comments

Comments
 (0)