Skip to content

Commit 0f0a314

Browse files
committed
Merged PR 43673: In playground, Allow modifying embed URL after bootstrap
In playground, Allow modifying embed URL after bootstrap
1 parent 7373a71 commit 0f0a314

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

demo/code-demo/scripts/session_utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const SessionKeys = {
66
EmbedId : "embedId",
77
GroupId : "groupId",
88
IsSampleReport: "isSampleReport",
9-
QnaQuestion: "qnaQuestion"
9+
QnaQuestion: "qnaQuestion",
10+
EntityIsAlreadyEmbedded: "EntityIsAlreadyEmbedded",
1011
};
1112

1213
function GetParameterByName(name, url) {
@@ -45,7 +46,7 @@ function SetTextBoxesFromSessionOrUrlParam(accessTokenSelector, embedUrlSelector
4546
{
4647
accessToken = GetSession(SessionKeys.AccessToken);
4748
}
48-
49+
4950
var embedUrl = GetParameterByName(SessionKeys.EmbedUrl);
5051
if (!embedUrl)
5152
{

demo/v2-demo/scripts/report.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,16 @@ function EmbedAreaMobileView() {
620620

621621
// Check if run button was clicked in the other mode and wasn't clicked on the new mode
622622
if ($(classPrefix + "Container iframe").length && !$(classPrefix + "MobileContainer iframe").length) {
623+
// It's not enough to check the number of iframes because of the bootstrap feature.
624+
if (GetSession(SessionKeys.EntityIsAlreadyEmbedded)) {
623625
let runFunc = getEmbedCode(mode, entityType);
624626
if ($('#interact-tab').hasClass(active_tabs_li)) {
625627
runFunc = updateRunFuncSessionParameters(runFunc);
626628
eval(runFunc);
627629
} else {
628630
runFunc();
629631
}
632+
}
630633
}
631634
}
632635

demo/v2-demo/scripts/utils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ function SetCode(func) {
5959
let oldFunc = runFunc;
6060
runFunc = function() {
6161
oldFunc();
62+
63+
SetSession(SessionKeys.EntityIsAlreadyEmbedded, true);
64+
6265
$('#interact-tab').addClass('enableTransition');
6366
setTimeout(function() {
6467
$('#interact-tab').addClass('changeColor');
@@ -69,6 +72,7 @@ function SetCode(func) {
6972
$('#btnRunCode').off('click');
7073
$('#btnRunCode').click(function() {
7174
showEmbedContainer();
75+
removeIframeIfUrlIsChanged();
7276
elementClicked('#btnRunCode');
7377
runFunc();
7478
});
@@ -169,6 +173,21 @@ function showEmbedContainer() {
169173
$(activeContainer).css({"visibility":"visible"});
170174
}
171175

176+
function removeIframeIfUrlIsChanged() {
177+
const activeContainer = getActiveEmbedContainer();
178+
if (!activeContainer || !activeContainer.powerBiEmbed || !activeContainer.powerBiEmbed.iframe) {
179+
return;
180+
}
181+
182+
let existingIframeUrl = removeUidFromUrl(activeContainer.powerBiEmbed.iframe.src);
183+
let embedUrl = GetSession(SessionKeys.EmbedUrl);
184+
185+
if (embedUrl !== existingIframeUrl) {
186+
// textbox has changed, delete the iframe and avoid the bootstrap.
187+
powerbi.reset(activeContainer);
188+
}
189+
}
190+
172191
function SetAuthoringPageActive(report) {
173192
return new Promise(function(resolve, reject) {
174193

@@ -196,3 +215,14 @@ function SetAuthoringPageActive(report) {
196215
});
197216
});
198217
}
218+
219+
function removeUidFromUrl(url) {
220+
const uidRegEx = /uid="?([^&]+)"?/
221+
const uidMatch = url.match(uidRegEx);
222+
223+
if (uidMatch) {
224+
return url.replace("&" + uidMatch[0], "");
225+
}
226+
227+
return url;
228+
}

0 commit comments

Comments
 (0)