From b8ecd6dab2c3b426ffadbae82c1a521840cee347 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 14:46:15 +0300 Subject: [PATCH] Fix `FrontstageDef.create()` to handle `FrontstageProvider` shaped objects (#906) (#908) * Fix `FrontstageDef.create()` if a non-instance `FrontstageProvider` is used. * rush change (cherry picked from commit 11c52beada9515b19c42a9a302e13780b46ed086) Co-authored-by: GerardasB <10091419+GerardasB@users.noreply.github.com> --- ...ntstage-provider-fix_2024-07-10-09-47.json | 10 ++++++ .../appui-react/frontstage/FrontstageDef.tsx | 5 ++- .../test/frontstage/FrontstageDef.test.tsx | 32 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 common/changes/@itwin/appui-react/frontstage-provider-fix_2024-07-10-09-47.json diff --git a/common/changes/@itwin/appui-react/frontstage-provider-fix_2024-07-10-09-47.json b/common/changes/@itwin/appui-react/frontstage-provider-fix_2024-07-10-09-47.json new file mode 100644 index 00000000000..3e0f039d924 --- /dev/null +++ b/common/changes/@itwin/appui-react/frontstage-provider-fix_2024-07-10-09-47.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/appui-react", + "comment": "Fix `FrontstageDef.create()` if a non-instance `FrontstageProvider` is used.", + "type": "none" + } + ], + "packageName": "@itwin/appui-react" +} \ No newline at end of file diff --git a/ui/appui-react/src/appui-react/frontstage/FrontstageDef.tsx b/ui/appui-react/src/appui-react/frontstage/FrontstageDef.tsx index 89b0e919eec..f9470023e00 100644 --- a/ui/appui-react/src/appui-react/frontstage/FrontstageDef.tsx +++ b/ui/appui-react/src/appui-react/frontstage/FrontstageDef.tsx @@ -55,7 +55,7 @@ import type { WidgetConfig } from "../widgets/WidgetConfig"; import type { WidgetControl } from "../widgets/WidgetControl"; import { getWidgetState, WidgetDef, WidgetType } from "../widgets/WidgetDef"; import { WidgetState } from "../widgets/WidgetState"; -import { FrontstageProvider } from "./FrontstageProvider"; +import type { FrontstageProvider } from "./FrontstageProvider"; import { InternalFrontstageManager } from "./InternalFrontstageManager"; import { StageUsage } from "./StageUsage"; import type { Frontstage } from "./Frontstage"; @@ -327,8 +327,7 @@ export class FrontstageDef { const def = new FrontstageDef(); let config; - // eslint-disable-next-line deprecation/deprecation - if (providerOrFrontstage instanceof FrontstageProvider) { + if ("frontstageConfig" in providerOrFrontstage) { def._frontstageProvider = providerOrFrontstage; config = providerOrFrontstage.frontstageConfig(); } else { diff --git a/ui/appui-react/src/test/frontstage/FrontstageDef.test.tsx b/ui/appui-react/src/test/frontstage/FrontstageDef.test.tsx index 987193ac724..850ea6d00a2 100644 --- a/ui/appui-react/src/test/frontstage/FrontstageDef.test.tsx +++ b/ui/appui-react/src/test/frontstage/FrontstageDef.test.tsx @@ -196,6 +196,38 @@ describe("FrontstageDef", () => { expect(spy).toHaveBeenCalledWith("t1"); }); + describe("create", () => { + it("should create from FrontstageProvider instance", async () => { + const frontstageDef = await FrontstageDef.create( + new (class Provider extends FrontstageProvider { + public override get id(): string { + return "provider-1"; + } + public override frontstageConfig(): FrontstageConfig { + return { + id: "frontstage-1", + contentGroup: TestUtils.TestContentGroup1, + version: 123, + }; + } + })() + ); + expect(frontstageDef.version).toEqual(123); + }); + + it("should create from FrontstageProvider object", async () => { + const frontstageDef = await FrontstageDef.create({ + id: "provider-1", + frontstageConfig: () => ({ + id: "frontstage-1", + contentGroup: TestUtils.TestContentGroup1, + version: 123, + }), + }); + expect(frontstageDef.version).toEqual(123); + }); + }); + describe("onWidgetStateChangedEvent", () => { it("should open a hidden widget", async () => { const activeFrontstageDef = new FrontstageDef();