Skip to content

Commit 34e9c31

Browse files
committed
overwrite component in embeds array if it existed before.
1 parent 6f56b37 commit 34e9c31

6 files changed

Lines changed: 31 additions & 12 deletions

File tree

‎dist/powerbi.js‎

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/powerbi.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/powerbi.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/service.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export declare class Service implements IService {
148148
* @returns {(Report | Tile)}
149149
*/
150150
find(uniqueId: string): Report | Tile | Dashboard;
151+
addOrOverwriteEmbed(component: embed.Embed, element: HTMLElement): void;
151152
/**
152153
* 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.
153154
*

‎src/service.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ export class Service implements IService {
170170
let powerBiElement = <IPowerBiElement>element;
171171
const component = new Create(this, powerBiElement, config);
172172
powerBiElement.powerBiEmbed = component;
173-
this.embeds.push(component);
173+
174+
this.addOrOverwriteEmbed(component, element);
174175

175176
return component;
176177
}
@@ -236,8 +237,8 @@ export class Service implements IService {
236237

237238
const component = new Component(this, element, config);
238239
element.powerBiEmbed = component;
239-
this.embeds.push(component);
240240

241+
this.addOrOverwriteEmbed(component, element);
241242
return component;
242243
}
243244

@@ -269,7 +270,8 @@ export class Service implements IService {
269270
const report = new Report(this, element, config, element.powerBiEmbed.iframe);
270271
report.load(<embed.IInternalEmbedConfiguration>config);
271272
element.powerBiEmbed = report;
272-
this.embeds.push(report);
273+
274+
this.addOrOverwriteEmbed(component, element);
273275

274276
return report;
275277
}
@@ -319,6 +321,15 @@ export class Service implements IService {
319321
return utils.find(x => x.config.uniqueId === uniqueId, this.embeds);
320322
}
321323

324+
addOrOverwriteEmbed(component: embed.Embed, element: HTMLElement): void {
325+
// remove embeds over the same div element.
326+
this.embeds = this.embeds.filter(function(embed) {
327+
return embed.element.id !== element.id;
328+
});
329+
330+
this.embeds.push(component);
331+
}
332+
322333
/**
323334
* 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.
324335
*

‎test/test.spec.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ describe('service', function () {
7878
it('embeds all components found in the DOM', function () {
7979
// Arrange
8080
const elements = [
81-
'<div powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=ABC123" powerbi-type="report"></div>',
82-
'<div powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=XYZ456" powerbi-type="report"></div>',
81+
'<div id="reportContainer1" powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=ABC123" powerbi-type="report"></div>',
82+
'<div id="reportContainer2" powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=XYZ456" powerbi-type="report"></div>',
8383
];
8484

8585
elements.forEach(element => {
@@ -3328,10 +3328,10 @@ describe('SDK-to-MockApp', function () {
33283328
logMessages
33293329
});
33303330

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

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

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

0 commit comments

Comments
 (0)