Skip to content

Commit 82e0dd2

Browse files
committed
feat: Organization full page support
1 parent 2e76370 commit 82e0dd2

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import EventEmitter from "wolfy87-eventemitter";
2+
import OrganizationFullPage from "../src/OrganizationFullPage";
3+
import { IOrgFullPageLocationInitData, LocationType } from "../src/types";
4+
import { OrganizationDetails } from "../src/types/organization.types";
5+
6+
describe("OrganizationFullPage", () => {
7+
const mockConnection = {
8+
sendToParent: jest.fn().mockReturnValue(Promise.resolve({})),
9+
};
10+
const mockEmitter: EventEmitter = new EventEmitter();
11+
const mockData: IOrgFullPageLocationInitData = {
12+
type: LocationType.ORGANIZATION_FULL_PAGE,
13+
app_id: "app_id",
14+
installation_uid: "installation_uid",
15+
extension_uid: "extension_uid",
16+
region: "NA",
17+
stack: {} as any,
18+
user: {} as any,
19+
currentBranch: "currentBranch",
20+
organization: {} as OrganizationDetails,
21+
};
22+
const organizationFullPage = new OrganizationFullPage(
23+
mockData,
24+
mockConnection as any,
25+
mockEmitter
26+
);
27+
28+
afterEach(() => {
29+
jest.clearAllMocks();
30+
});
31+
32+
it("should return organization details", () => {
33+
expect(organizationFullPage.currentOrganization).toBe(mockData.organization);
34+
});
35+
36+
it("should handle missing organization details", () => {
37+
const invalidData: IOrgFullPageLocationInitData = {
38+
...mockData,
39+
organization: null as any, // check missing organization details
40+
};
41+
const invalidOrganizationFullPage = new OrganizationFullPage(
42+
invalidData,
43+
mockConnection as any,
44+
mockEmitter
45+
);
46+
expect(invalidOrganizationFullPage.currentOrganization).toBeNull();
47+
});
48+
});

src/OrganizationFullPage/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import postRobot from "post-robot";
2+
import EventEmitter from "wolfy87-eventemitter";
3+
import { OrganizationDetails } from "../types/organization.types";
4+
import { IOrgFullPageLocationInitData } from "../types";
5+
6+
class OrganizationFullPage {
7+
private _data: IOrgFullPageLocationInitData;
8+
private _connection: typeof postRobot;
9+
private _emitter: EventEmitter;
10+
11+
constructor(
12+
data: IOrgFullPageLocationInitData,
13+
connection: typeof postRobot,
14+
emitter: EventEmitter
15+
) {
16+
this._data = data;
17+
this._connection = connection;
18+
this._emitter = emitter;
19+
}
20+
21+
get currentOrganization(): OrganizationDetails {
22+
return this._data.organization;
23+
}
24+
}
25+
26+
export default OrganizationFullPage;

src/types.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import Stack from "./stack";
66
import { GenericObjectType } from "./types/common.types";
77
import { Entry } from "./types/entry.types";
88
import { Asset, ContentType, Schema, StackDetail } from "./types/stack.types";
9+
import { OrganizationDetails } from "./types/organization.types";
910
import { User } from "./types/user.types";
1011
import Window from "./window";
12+
import OrganizationFullPage from "./OrganizationFullPage";
1113

1214
export declare interface IDashboardWidget {
1315
frame: Window;
@@ -67,6 +69,10 @@ export declare interface IAppConfigWidget {
6769
stack: Stack;
6870
}
6971

72+
export declare interface IOrgFullPageLocation {
73+
organization: OrganizationFullPage;
74+
}
75+
7076
export enum DashboardWidth {
7177
FULL_WIDTH = "full_width",
7278
HALF_WIDTH = "half_width",
@@ -82,6 +88,7 @@ export enum LocationType {
8288
RTE = "RTE",
8389
WIDGET = "WIDGET",
8490
CONTENT_TYPE_SIDEBAR_WIDGET = "CONTENT_TYPE_SIDEBAR_WIDGET",
91+
ORGANIZATION_FULL_PAGE = "ORGANIZATION_FULL_PAGE",
8592
}
8693

8794
// Init data
@@ -98,6 +105,12 @@ declare interface ICommonInitData {
98105
manifest?: Manifest;
99106
}
100107

108+
export declare interface IOrgFullPageLocationInitData extends ICommonInitData {
109+
organization: OrganizationDetails;
110+
config?: GenericObjectType;
111+
type: LocationType.ORGANIZATION_FULL_PAGE;
112+
}
113+
101114
export declare interface IDashboardInitData extends ICommonInitData {
102115
dashboard_width: DashboardWidth;
103116
config?: GenericObjectType;
@@ -202,7 +215,8 @@ export type InitializationData =
202215
| IFullPageLocationInitData
203216
| IRTEInitData
204217
| ISidebarInitData
205-
| IContentTypeSidebarInitData;
218+
| IContentTypeSidebarInitData
219+
| IOrgFullPageLocationInitData;
206220

207221
/**
208222
* installation details API response

src/types/organization.types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { GenericObjectType } from "./common.types";
2+
3+
export declare interface OrganizationDetails {
4+
uid: string;
5+
name: string;
6+
plan_id: string;
7+
owner_uid: string;
8+
is_transfer_set: boolean;
9+
expires_on: string;
10+
enabled: boolean;
11+
is_over_usage_allowed: boolean;
12+
created_at: string;
13+
updated_at: string;
14+
settings: GenericObjectType;
15+
tags: string[];
16+
plan?: {
17+
plan_id: string;
18+
name: string;
19+
message: string;
20+
price: string;
21+
features: {
22+
uid: string;
23+
name: string;
24+
enabled: boolean;
25+
limit: number;
26+
max_limit: number;
27+
is_required: boolean;
28+
depends_on: string[];
29+
}[];
30+
created_at: string;
31+
updated_at: string;
32+
blockedAssetTypes: any[];
33+
};
34+
}

src/uiLocation.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import EventEmitter from "wolfy87-eventemitter";
33

44
import AssetSidebarWidget from "./AssetSidebarWidget";
55
import ContentTypeSidebarWidget from "./ContentTypeSidebarWidget";
6+
import OrganizationFullPage from "./OrganizationFullPage";
67
import { IRTEPluginInitializer } from "./RTE/types";
78
import { AppConfig } from "./appConfig";
89
import Entry from "./entry";
@@ -26,6 +27,7 @@ import {
2627
LocationType,
2728
Manifest,
2829
Region,
30+
IOrgFullPageLocation,
2931
} from "./types";
3032
import { GenericObjectType } from "./types/common.types";
3133
import { User } from "./types/user.types";
@@ -117,6 +119,7 @@ class UiLocation {
117119
FullPage: IFullPageLocation | null;
118120
FieldModifierLocation: IFieldModifierLocation | null;
119121
ContentTypeSidebarWidget: ContentTypeSidebarWidget | null;
122+
OrganizationFullPage: IOrgFullPageLocation | null;
120123
};
121124

122125
constructor(initData: InitializationData) {
@@ -155,6 +158,7 @@ class UiLocation {
155158
FullPage: null,
156159
FieldModifierLocation: null,
157160
ContentTypeSidebarWidget: null,
161+
OrganizationFullPage: null
158162
};
159163

160164
window["postRobot"] = postRobot;
@@ -262,6 +266,17 @@ class UiLocation {
262266
break;
263267
}
264268

269+
case LocationType.ORGANIZATION_FULL_PAGE: {
270+
this.location.OrganizationFullPage = {
271+
organization: new OrganizationFullPage(
272+
initializationData,
273+
postRobot,
274+
emitter
275+
),
276+
};
277+
break;
278+
}
279+
265280
case LocationType.CONTENT_TYPE_SIDEBAR_WIDGET: {
266281
this.location.ContentTypeSidebarWidget =
267282
new ContentTypeSidebarWidget(

0 commit comments

Comments
 (0)