Skip to content

feat: i-frame component created #1408

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

Merged
merged 12 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/observability/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@angular/common": "^12.2.1",
"@angular/core": "^12.2.1",
"@angular/material": "^12.2.1",
"@angular/platform-browser": "^12.2.1",
"@angular/cdk": "^12.2.1",
"lodash-es": "^4.17.15",
"@angular/router": "^12.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mockDashboardWidgetProviders } from '@hypertrace/dashboards/testing';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';

import { IframeWidgetRendererComponent } from './iframe-widget-renderer.component';

describe('IFrame Widget Renderer Component', () => {
let spectator: Spectator<IframeWidgetRendererComponent>;

const createComponent = createComponentFactory<IframeWidgetRendererComponent>({
component: IframeWidgetRendererComponent,
providers: [...mockDashboardWidgetProviders({})],
shallow: true
});

test('should use iframe', () => {
spectator = createComponent();
expect(spectator.query('iframe')).toExist();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { WidgetRenderer } from '@hypertrace/dashboards';
import { Renderer } from '@hypertrace/hyperdash';
import { RendererApi, RENDERER_API } from '@hypertrace/hyperdash-angular';
import { EMPTY, Observable } from 'rxjs';

import { IFrameWidgetModel } from './iframe-widget.model';

@Renderer({ modelClass: IFrameWidgetModel })
@Component({
selector: 'ht-iframe-widget-renderer',
template: ` <iframe width="100%" height="100%" frameBorder="0" [src]="urlSafe"></iframe> `,
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['./iframe-widget-renderer.component.scss']
})
export class IframeWidgetRendererComponent extends WidgetRenderer<IFrameWidgetModel> implements OnInit {
public urlSafe?: SafeResourceUrl;

public constructor(
public sanitizer: DomSanitizer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: private readonly sanitizer: DomSanitizer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do this in a follow up

@Inject(RENDERER_API) api: RendererApi<IFrameWidgetModel>,
changeDetector: ChangeDetectorRef
) {
super(api, changeDetector);
}
public ngOnInit(): void {
this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.model.source);
}
protected fetchData(): Observable<unknown> {
return EMPTY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Model, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';

@Model({
type: 'iframe-widget'
})
export class IFrameWidgetModel {
@ModelProperty({
key: 'source',
type: STRING_PROPERTY.type
})
public source: string = '';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { DashboardCoreModule } from '@hypertrace/hyperdash-angular';
import { IframeWidgetRendererComponent } from './iframe-widget-renderer.component';
import { IFrameWidgetModel } from './iframe-widget.model';

@NgModule({
declarations: [IframeWidgetRendererComponent],
imports: [
CommonModule,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line? Prettier should catch this

DashboardCoreModule.with({
models: [IFrameWidgetModel],
renderers: [IframeWidgetRendererComponent]
})
]
})
export class IframeWidgetModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ObservabilityTableCellRendererModule } from '../../components/table/obs
import { CartesianWidgetModule } from './charts/cartesian-widget/cartesian-widget.module';
import { DonutWidgetModule } from './donut/donut-widget.module';
import { GaugeWidgetModule } from './gauge/gauge-widget.module';
import { IframeWidgetModule } from './iframe/iframe-widget.module';
import { MetricDisplayWidgetModule } from './metric-display/metric-display-widget.module';
import { RadarWidgetModule } from './radar/radar-widget.module';
import { TopNWidgetModule } from './top-n/top-n-widget.module';
Expand All @@ -17,7 +18,8 @@ import { TopologyWidgetModule } from './topology/topology-widget.module';
ObservabilityTableCellRendererModule,
DonutWidgetModule,
CartesianWidgetModule,
GaugeWidgetModule
GaugeWidgetModule,
IframeWidgetModule
]
})
export class ObservabilityDashboardWidgetsModule {}