Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions projects/observability/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,7 @@ export * from './shared/components/bar-gauge/bar-gauge.module';

// Time Range utils
export * from './shared/utils/time-range';

// I-frame
export * from './shared/components//iframe/iframe.component';
export * from './shared/components/iframe/iframe.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';

import { IFrameComponent } from './iframe.component';

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

const createComponent = createComponentFactory<IFrameComponent>({
component: IFrameComponent,
shallow: true
});

test('should render the iframe', () => {
spectator = createComponent();
expect(spectator.query('iframe')).toExist();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
selector: 'ht-iframe',
template: `<iframe width="100%" height="100%" frameBorder="0" [src]="urlSafe"></iframe>`,
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['./iframe.component.scss']
})
export class IFrameComponent implements OnInit {
@Input() public source: string = '';
@Input() public title?: string;

public urlSafe?: SafeResourceUrl;
public constructor(public sanitizer: DomSanitizer) {}

public ngOnInit(): void {
this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.source);
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably would not want to bypass security like this inside a dumb component - would leave it to the place where the URL originates to decide whether it's safe to do this, and instead take in a SafeResourceUrl rather than a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to widget

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { IFrameComponent } from './iframe.component';

@NgModule({
declarations: [IFrameComponent],
imports: [CommonModule],
exports: [IFrameComponent]
})
export class IFrameModule {}
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 component', () => {
spectator = createComponent();
expect(spectator.query('ht-iframe')).toExist();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { WidgetRenderer } from '@hypertrace/dashboards';
import { Renderer } from '@hypertrace/hyperdash';
import { Observable, of } from 'rxjs';

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

@Renderer({ modelClass: IFrameWidgetModel })
@Component({
selector: 'ht-iframe-widget-renderer',
template: ` <ht-iframe [source]="this.model.source" [title]="this.model.title"></ht-iframe> `,
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['./iframe-widget-renderer.component.scss']
})
export class IframeWidgetRendererComponent extends WidgetRenderer<IFrameWidgetModel> implements OnInit {
protected fetchData(): Observable<unknown> {
return of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Model, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';

@Model({
type: 'iframe-widget'
})
export class IFrameWidgetModel {
@ModelProperty({
key: 'title',
type: STRING_PROPERTY.type
})
public title: string = '';

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

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

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-widget/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 {}