Skip to content

Add dashboard embed SDK and tests - #31

Merged
Matt Mazzola (mattmazzola) merged 1 commit into
microsoft:devfrom
wenwa:wenwa/dashboardEmbedSdk
Aug 31, 2016
Merged

Matt Mazzola (mattmazzola) merged 1 commit into
microsoft:devfrom
wenwa:wenwa/dashboardEmbedSdk

Conversation

@wenwa

@wenwa wenwa commented Aug 18, 2016

Copy link
Copy Markdown
Contributor

Add dashboard embed SDK and tests

@msftclas

Hi wenwa, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Joey Wang). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas Microsoft Contribution License Agreements (msftclas) added the documentation Improvements or additions to documentation label Aug 18, 2016
Comment thread test/utility/mockDashboardEmbed.ts Outdated
import * as models from 'powerbi-models';
import { mockAppSpyObj, mockApp } from './mockApp';

export function setupDashboardEmbedMockApp(iframeContentWindow: Window, parentWindow: Window, logMessages: boolean, name: string = 'MockAppWindowPostMessageProxy'): Hpm.HttpPostMessage {

@mattmazzola Matt Mazzola (mattmazzola) Aug 19, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you choose to make a new mock app?

It looks like most of this code is copied form the original mock app and just changed the router to have a /dashboard/load handler. It looks like this could be consolidated which would be less maintenance. I think all you need is the code which adds the handler to the router. Maybe rename the mockReportEmbed file to mockEmbed so it appears to be generic and re-usable for all types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@wenwa
wenwa force-pushed the wenwa/dashboardEmbedSdk branch from 5983ca6 to 1c6683f Compare August 23, 2016 21:00
Comment thread src/embed.ts Outdated

return this.service.hpm.post<void>('/report/load', config, { uid: this.config.uniqueId }, this.iframe.contentWindow)

var loadPath = '/report/load';

@mattmazzola Matt Mazzola (mattmazzola) Aug 29, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use let instead of var. I thought this was a tslint rule but maybe i don't have it configured correctly.

@mattmazzola

Copy link
Copy Markdown
Contributor

Looks good to merge. Wallace Breza (@wbreza) any comments?

@wenwa
wenwa force-pushed the wenwa/dashboardEmbedSdk branch from 3836e05 to a8b0e7a Compare August 29, 2016 23:38
Comment thread src/embed.ts Outdated

let loadPath = '/report/load';
if(embedConfig && embedConfig.type === 'dashboard') {
if(config && (<IEmbedConfiguration>config).type === 'dashboard') {

@mattmazzola Matt Mazzola (mattmazzola) Aug 30, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Casting here a is sign there is design problem. It should not be allowed to access the type property.

Since the embed has already been called and the object is constructed it's currently not possible to change types dynamically. As it is written, I think this would allow a Report object to have dashboard embedded in its iframe which would be very confusing and i'm not sure what problems would occur.

Since embed has already been called at this point in the life-cycle the type should be known on the internal config object. config: IInternalEmbedConfiguration.

I think this problem occurred because we're inside the Embed class which has a load method intended to be generic for all embeds, but the url path is dependent on the type / class. The pieces of information that are specific to each type should be in the concrete classes Report or Dashboard so they can diverge in their implementation.

Perhaps override the load method in those classes and each would make the call to the super.load(....) using their specific url path.

Since the type is determined in the embed method so should the load path, and the code should guarantee the two pieces of information are fixed together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I understand your proposal on the fix. How will the overridden 'load' methods find out the load path info? Through this.config:IInternalEmbedConfiguration in embed? Also wouldn't we have a lot of duplicated code in 3 load methods? All we want to change is the load path and I think the ideal place to differentiate is still in embed.

Technically you can't really prevent the user from doing crazy things such as embed a dashboard in a report iFrame...but it would just not work and user should be able to fix that relatively easily.

My proposal is to just fix it as:
if(this.config && this.config.type === 'dashboard') { ... }

@mattmazzola Matt Mazzola (mattmazzola) Aug 31, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How will the overridden 'load' methods find out the load path info?
I imagined these two ways:

  1. Save on internal config
  2. Save as loadPath class member.
    It could also be supplied as optional argument but that doesn't solve the problem and still allows the type of the thing embedded to be changed independently of the object type. I think the main point is that the type and the load path should be coupled together, but as it is written now it technically works but is brittle design.

wouldn't we have a lot of duplicated code in 3 load methods?
No, we should try to avoid duplication. The important part is the call to hpm which should still be in the abstract base embed class.

All we want to change is the load path and I think the ideal place to differentiate is still in embed.

There is an existing programming model using objects and separate files for report and dashboard to express their differences. It's better to keep consistency and have conceptual integrity across the library than to add things with conflicting philosophies even if you think they are better. My personal preference would have been using the service for everything and using a more generic functional approach where there would be no dashboard or report classes only methods to invoke which send messages to an iframe but that is not what was agreed upon. A lot of developers still like OOP.

Technically you can't really prevent the user from doing crazy things such as embed a dashboard in a report iFrame

I think you're confusing two different ideas. Yes, they can always do what they want with the iframe, but our SDK should not allow itself to be put in a bad state or allow the user to perform unsafe operations. I think we should throw an exception in the embed code to protect the developers and then step back and re-design to better handle dynamically switching from one embed type to the other. I think it's too much work to do now and I don't see the use case for it . Josh might have specific examples, but I think embedding is almost always going to be based on the context of the host application. (E.g. on this page it makes sense embed a dashboard, but this page it makes sense to embed a report. If you were two swap the report with the dashboard it would not feel correct in context of host application.)

@wenwa
wenwa force-pushed the wenwa/dashboardEmbedSdk branch from bb250a5 to e29d521 Compare August 31, 2016 00:14
@wenwa
wenwa force-pushed the wenwa/dashboardEmbedSdk branch from 0c25b50 to d34a3cf Compare August 31, 2016 00:48
@mattmazzola

Copy link
Copy Markdown
Contributor

For some reason Github isn't letting me add line note since it's not something you changed.

There is a line to validate the load configuration:
const errors = models.validateLoad(config);

I saw there was a different code review to specifically validate dashboard load configuration and there was changes in the powerbi-models repo for. Do you also need to validate differently based on the type or is this Ok as is?

@mattmazzola
Matt Mazzola (mattmazzola) merged commit 1005e03 into microsoft:dev Aug 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants