Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix popout widget issue when useDefaultPopoutUrl is not used (backport #1179) #1181

Merged
merged 1 commit into from
Jan 17, 2025
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
6 changes: 5 additions & 1 deletion apps/test-app/src/frontend/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ function createInitializer() {
toolbarOpacity: 0.5,
})
);
UiFramework.useDefaultPopoutUrl = true;

const urlParams = new URLSearchParams(window.location.search);
const useDefaultPopoutUrl =
urlParams.get("useDefaultPopoutUrl") === "0" ? false : true;
UiFramework.useDefaultPopoutUrl = useDefaultPopoutUrl;
await UiFramework.initializeStateFromUserSettingsProviders();

UiFramework.keyboardShortcuts.loadShortcuts(createKeyboardShortcuts());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/appui-react",
"comment": "Fix popout widget issue when `useDefaultPopoutUrl` is not enabled.",
"type": "none"
}
],
"packageName": "@itwin/appui-react"
}
20 changes: 20 additions & 0 deletions e2e-tests/tests/popout-widget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { test, expect } from "@playwright/test";
import {
WidgetState,
expectSavedFrontstageState,
expectTabInPanelSection,
floatingWidgetLocator,
openFrontstage,
panelSectionLocator,
Expand Down Expand Up @@ -264,3 +265,22 @@ test("useWidget hook", async ({ page }) => {
);
await expect(widgetText).toBeVisible();
});

for (const useDefaultPopoutUrl of [1, 0]) {
test(`should return popout widget to main window (useDefaultPopoutUrl=${useDefaultPopoutUrl})`, async ({
page,
}) => {
await page.goto(
`./blank?frontstageId=test-popout&useDefaultPopoutUrl=${useDefaultPopoutUrl}`
);

const tab = tabLocator(page, "Widget 1");
const widget = widgetLocator({ tab });

const popoutPage = await popoutWidget(widget);
await expect(popoutPage.getByText("Widget 1 content")).toBeVisible();

await popoutPage.close();
await expectTabInPanelSection(tab, "left", 0);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import type {
import { usePopoutsStore } from "../preview/reparent-popout-widgets/usePopoutsStore.js";
import type { TabState } from "../layout/state/TabState.js";

const childHtml = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
function addChildHTML(window: Window) {
const doc = window.document;

const meta = doc.createElement("meta");
meta.setAttribute("charset", "utf-8");
doc.head.appendChild(meta);

const style = doc.createElement("style");
style.textContent = `
html,
body {
height: 100%;
Expand All @@ -33,13 +37,17 @@ const childHtml = `<!DOCTYPE html>
#root {
height: 100%;
}
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>`;
`;
doc.head.appendChild(style);

const noScript = doc.createElement("noscript");
noScript.textContent = "You need to enable JavaScript to run this app.";
doc.body.appendChild(noScript);

const root = doc.createElement("div");
root.id = "root";
doc.body.appendChild(root);
}

/** @internal */
export interface InternalOpenChildWindowInfo extends OpenChildWindowInfo {
Expand Down Expand Up @@ -239,7 +247,7 @@ export class InternalChildWindowManager implements FrameworkChildWindows {
);
};
if (url.length === 0) {
childWindow.document.write(childHtml);
addChildHTML(childWindow);
onDOMContentLoaded();
} else {
childWindow.addEventListener("DOMContentLoaded", onDOMContentLoaded);
Expand Down
Loading