Skip to content

Commit

Permalink
Fix FrontstageDef.create() to handle FrontstageProvider shaped ob…
Browse files Browse the repository at this point in the history
…jects (#906) (#908)

* Fix `FrontstageDef.create()` if a non-instance `FrontstageProvider` is used.

* rush change

(cherry picked from commit 11c52be)

Co-authored-by: GerardasB <10091419+GerardasB@users.noreply.github.com>
  • Loading branch information
mergify[bot] and GerardasB committed Jul 10, 2024
1 parent 114120b commit b8ecd6d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 2 additions & 3 deletions ui/appui-react/src/appui-react/frontstage/FrontstageDef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions ui/appui-react/src/test/frontstage/FrontstageDef.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b8ecd6d

Please sign in to comment.