-
Notifications
You must be signed in to change notification settings - Fork 11
feat: conditional container widget #348
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 3 commits
7fd2b1f
7b32858
4df22db
97d893a
ff753d3
556277d
de81fd6
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 'mixins'; | ||
|
||
.conditional-widget { | ||
width: 100%; | ||
height: 100%; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ChangeDetectionStrategy, Component, ViewChild, ViewContainerRef } from '@angular/core'; | ||
import { ModelJson, Renderer } from '@hypertrace/hyperdash'; | ||
import { Observable } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { WidgetRenderer } from '../widget-renderer'; | ||
import { ConditionalModel } from './conditional.model'; | ||
|
||
@Renderer({ modelClass: ConditionalModel }) | ||
@Component({ | ||
selector: 'ht-conditional-widget', | ||
styleUrls: ['./conditional-widget-renderer.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<div class="conditional-widget"> | ||
<ng-container [hdaDashboardModel]="this.getModel() | async"> </ng-container> | ||
</div> | ||
` | ||
}) | ||
export class ConditionalWidgetRendererComponent extends WidgetRenderer<ConditionalModel> { | ||
@ViewChild('containerContent', { read: ViewContainerRef, static: true }) | ||
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. Doesn't appear used |
||
public container!: ViewContainerRef; | ||
|
||
public getModel(): Observable<ModelJson> { | ||
return this.model.getModel().pipe(takeUntil(this.destroyed$)); | ||
} | ||
|
||
protected fetchData(): Observable<ModelJson> { | ||
return this.getModel(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { DashboardCoreModule } from '@hypertrace/hyperdash-angular'; | ||
import { ConditionalWidgetRendererComponent } from './conditional-widget-renderer.component'; | ||
import { ConditionalModel } from './conditional.model'; | ||
|
||
@NgModule({ | ||
declarations: [ConditionalWidgetRendererComponent], | ||
imports: [ | ||
CommonModule, | ||
DashboardCoreModule.with({ | ||
models: [ConditionalModel], | ||
renderers: [ConditionalWidgetRendererComponent] | ||
}) | ||
] | ||
}) | ||
export class ConditionalWidgetModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Model, ModelApi, ModelJson, ModelProperty, PLAIN_OBJECT_PROPERTY } from '@hypertrace/hyperdash'; | ||
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
@Model({ | ||
type: 'conditional' | ||
}) | ||
export class ConditionalModel { | ||
@ModelProperty({ | ||
key: 'true', | ||
type: PLAIN_OBJECT_PROPERTY.type, | ||
required: true | ||
}) | ||
public true!: ModelJson; | ||
|
||
@ModelProperty({ | ||
key: 'false', | ||
type: PLAIN_OBJECT_PROPERTY.type, | ||
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. ModelTemplatePropertyType.TYPE |
||
required: true | ||
}) | ||
public false!: ModelJson; | ||
|
||
@ModelInject(MODEL_API) | ||
private readonly api!: ModelApi; | ||
|
||
public getData(): Observable<boolean> { | ||
return this.api.getData<boolean>(); | ||
} | ||
|
||
public getModel(): Observable<ModelJson> { | ||
return this.getData().pipe(map(result => (result ? this.true : this.false))); | ||
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. Based on how we're using this in the renderer, we should hydrate this modelJson, and return a real model - something like |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Observable } from 'rxjs'; | ||
import { GraphQlDataSourceModel } from '../graphql-data-source.model'; | ||
|
||
export abstract class ConditionalDataSourceModel extends GraphQlDataSourceModel<boolean> { | ||
public abstract getData(): Observable<boolean>; | ||
} |
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.
do we need the div? the instantiated widget should have its own container