Repository navigation
Add dashboard embed SDK and tests - #31
Conversation
|
Hi wenwa, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
| 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 { |
There was a problem hiding this comment.
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.
5983ca6 to
1c6683f
Compare
|
|
||
| return this.service.hpm.post<void>('/report/load', config, { uid: this.config.uniqueId }, this.iframe.contentWindow) | ||
|
|
||
| var loadPath = '/report/load'; |
There was a problem hiding this comment.
use let instead of var. I thought this was a tslint rule but maybe i don't have it configured correctly.
|
Looks good to merge. Wallace Breza (@wbreza) any comments? |
3836e05 to
a8b0e7a
Compare
|
|
||
| let loadPath = '/report/load'; | ||
| if(embedConfig && embedConfig.type === 'dashboard') { | ||
| if(config && (<IEmbedConfiguration>config).type === 'dashboard') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') { ... }
There was a problem hiding this comment.
How will the overridden 'load' methods find out the load path info?
I imagined these two ways:
- Save on internal config
- 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.)
bb250a5 to
e29d521
Compare
0c25b50 to
d34a3cf
Compare
|
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: I saw there was a different code review to specifically validate dashboard load configuration and there was changes in the |
Add dashboard embed SDK and tests