Skip to content
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
13 changes: 10 additions & 3 deletions dist/powerbi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/powerbi.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/powerbi.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export declare class Service implements IService {
* @returns {(Report | Tile)}
*/
find(uniqueId: string): Report | Tile | Dashboard;
addOrOverwriteEmbed(component: embed.Embed, element: HTMLElement): void;
/**
* Given an HTML element that has a component embedded within it, removes the component from the list of embedded components, removes the association between the element and the component, and removes the iframe.
*
Expand Down
17 changes: 14 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export class Service implements IService {
let powerBiElement = <IPowerBiElement>element;
const component = new Create(this, powerBiElement, config);
powerBiElement.powerBiEmbed = component;
this.embeds.push(component);

this.addOrOverwriteEmbed(component, element);

return component;
}
Expand Down Expand Up @@ -236,8 +237,8 @@ export class Service implements IService {

const component = new Component(this, element, config);
element.powerBiEmbed = component;
this.embeds.push(component);

this.addOrOverwriteEmbed(component, element);
return component;
}

Expand Down Expand Up @@ -269,7 +270,8 @@ export class Service implements IService {
const report = new Report(this, element, config, element.powerBiEmbed.iframe);
report.load(<embed.IInternalEmbedConfiguration>config);
element.powerBiEmbed = report;
this.embeds.push(report);

this.addOrOverwriteEmbed(component, element);

return report;
}
Expand Down Expand Up @@ -319,6 +321,15 @@ export class Service implements IService {
return utils.find(x => x.config.uniqueId === uniqueId, this.embeds);
}

addOrOverwriteEmbed(component: embed.Embed, element: HTMLElement): void {
// remove embeds over the same div element.
this.embeds = this.embeds.filter(function(embed) {
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't you removing the identical component before re-appending it? Each embed.load( will leave an orphaned component?

return embed.element.id !== element.id;
});

this.embeds.push(component);
}

/**
* Given an HTML element that has a component embedded within it, removes the component from the list of embedded components, removes the association between the element and the component, and removes the iframe.
*
Expand Down
8 changes: 4 additions & 4 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ describe('service', function () {
it('embeds all components found in the DOM', function () {
// Arrange
const elements = [
'<div powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=ABC123" powerbi-type="report"></div>',
'<div powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=XYZ456" powerbi-type="report"></div>',
'<div id="reportContainer1" powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=ABC123" powerbi-type="report"></div>',
'<div id="reportContainer2" powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=XYZ456" powerbi-type="report"></div>',
];

elements.forEach(element => {
Expand Down Expand Up @@ -3328,10 +3328,10 @@ describe('SDK-to-MockApp', function () {
logMessages
});

$element = $(`<div class="powerbi-report-container2"></div>`)
$element = $(`<div id="reportContainer1" class="powerbi-report-container2"></div>`)
.appendTo(document.body);

$element2 = $(`<div class="powerbi-report-container3"></div>`)
$element2 = $(`<div id="reportContainer2" class="powerbi-report-container3"></div>`)
.appendTo(document.body);

const iframeSrc = "base/test/utility/noop.html";
Expand Down