-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from 4 commits
6debde7
93b23ab
3acba52
90e9b28
82d1d9c
d4065b3
5fd5453
59b161a
1f212c6
df7f8cd
1d74c80
a2d6dc0
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,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; | ||
jyothishjose6190 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
jyothishjose6190 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public urlSafe?: SafeResourceUrl; | ||
| public constructor(public sanitizer: DomSanitizer) {} | ||
|
|
||
| public ngOnInit(): void { | ||
jyothishjose6190 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.source); | ||
|
||
| } | ||
| } | ||
| 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(); | ||
jyothishjose6190 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| 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 {} |
Uh oh!
There was an error while loading. Please reload this page.