Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0e33c77
Merge pull request #122 from contentstack/develop
MaitriGurey1 Oct 10, 2024
726f589
fix: resolve data file field handler
abhishek305 Oct 21, 2024
beb17b5
fix: PR feedback
abhishek305 Oct 21, 2024
4ab6a5b
fix: PR feedbacn optional chain
abhishek305 Oct 21, 2024
da6825e
Added Content type sidebar UI location
praveen-mohan-cs Oct 21, 2024
be6497e
sca-scan.yml
aravindbuilt Oct 22, 2024
e59ce41
jira.yml
aravindbuilt Oct 22, 2024
fe70f19
sast-scan.yml
aravindbuilt Oct 22, 2024
15206b3
Updated codeowners
aravindbuilt Oct 22, 2024
19b239c
Merge branch 'main' into staging
abhishek305 Oct 22, 2024
65fc727
fix: resolve data file field handler
abhishek305 Oct 21, 2024
a50a136
fix: PR feedback
abhishek305 Oct 21, 2024
0b79d1a
fix: PR feedbacn optional chain
abhishek305 Oct 21, 2024
218c8bd
Merge branch 'staging' of https://github.com/contentstack/app-sdk int…
praveen-mohan-cs Oct 24, 2024
59eb67e
Addressed PR comments
praveen-mohan-cs Oct 24, 2024
51577bb
Addressed PR comments
praveen-mohan-cs Oct 25, 2024
ee18192
Merge pull request #132 from contentstack/feat/DEVREL-203-content-typ…
praveen-mohan-cs Oct 25, 2024
e2ae3e6
Version bump
praveen-mohan-cs Oct 25, 2024
50303b1
Merge pull request #133 from contentstack/feat/DEVREL-203-content-typ…
praveen-mohan-cs Oct 25, 2024
5529760
Merge branch 'main' into staging
praveen-mohan-cs Oct 25, 2024
a15cecb
sca-scan.yml
aravindbuilt Jan 18, 2025
c576a67
jira.yml
aravindbuilt Jan 18, 2025
3a1c5de
sast-scan.yml
aravindbuilt Jan 18, 2025
1e23222
Updated codeowners
aravindbuilt Jan 18, 2025
19763e0
Merge branch 'main' into staging
abhishek305 Jan 20, 2025
2e76370
License update
abhishek305 Jan 20, 2025
82e0dd2
feat: Organization full page support
abhishek305 Jan 26, 2025
3785653
chore: version update
abhishek305 Jan 26, 2025
f10a29d
PR: feedback
abhishek305 Jan 27, 2025
9e20e26
Merge branch 'develop' into MKT-10640
abhishek305 Jan 29, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
project: ${{ secrets.JIRA_PROJECT }}
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }}
summary: |
${{ github.event.pull_request.title }}
Snyk | Vulnerability | ${{ github.event.repository.name }} | ${{ github.event.pull_request.title }}
description: |
PR: ${{ github.event.pull_request.html_url }}

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2024 Contentstack
Copyright (c) 2022-2025 Contentstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
90 changes: 48 additions & 42 deletions __test__/data/fileField.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,58 @@
},
"value": [
{
"uid": "blt78cdb7bdceb00332",
"created_at": "2019-05-27T06:25:46.929Z",
"updated_at": "2019-05-27T06:25:46.929Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "49385",
"tags": [],
"filename": "asdasdasd(1).png",
"url": "https://images.contentstack.io/v3/assets/blxxx/blt78cdb7bdceb00332/sadsadsASS/asdasdasd(1).png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "asdasdasd(1).png"
"file": {
"uid": "blt78cdb7bdceb00332",
"created_at": "2019-05-27T06:25:46.929Z",
"updated_at": "2019-05-27T06:25:46.929Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "49385",
"tags": [],
"filename": "asdasdasd(1).png",
"url": "https://images.contentstack.io/v3/assets/blxxx/blt78cdb7bdceb00332/sadsadsASS/asdasdasd(1).png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "asdasdasd(1).png"
}
},
{
"uid": "bltd40e27d1918972a4",
"created_at": "2019-05-27T06:22:42.426Z",
"updated_at": "2019-05-27T06:22:42.426Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "21748",
"tags": [],
"filename": "MVMT_Rallye_Green_Sandstone_3.png",
"url": "https://images.contentstack.io/v3/assets/blxxx/bltd40e27d1918972a4/5ceb8232231227de413bab12/MVMT_Rallye_Green_Sandstone_3.png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "MVMT_Rallye_Green_Sandstone_3.png"
"file": {
"uid": "bltd40e27d1918972a4",
"created_at": "2019-05-27T06:22:42.426Z",
"updated_at": "2019-05-27T06:22:42.426Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "21748",
"tags": [],
"filename": "MVMT_Rallye_Green_Sandstone_3.png",
"url": "https://images.contentstack.io/v3/assets/blxxx/bltd40e27d1918972a4/5ceb8232231227de413bab12/MVMT_Rallye_Green_Sandstone_3.png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "MVMT_Rallye_Green_Sandstone_3.png"
}
},
{
"uid": "blt236db5d7d0d2c2d1",
"created_at": "2019-05-27T06:22:39.763Z",
"updated_at": "2019-05-27T06:22:39.763Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "23804",
"tags": [],
"filename": "MVMT_Rallye_Green_Sandstone_2.png",
"url": "https://images.contentstack.io/v3/assets/blxxx/blt236db5d7d0d2c2d1/5ceb822f065d29344df9fd2d/MVMT_Rallye_Green_Sandstone_2.png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "MVMT_Rallye_Green_Sandstone_2.png"
"file": {
"uid": "blt236db5d7d0d2c2d1",
"created_at": "2019-05-27T06:22:39.763Z",
"updated_at": "2019-05-27T06:22:39.763Z",
"created_by": "asssa",
"updated_by": "asssa",
"content_type": "image/png",
"file_size": "23804",
"tags": [],
"filename": "MVMT_Rallye_Green_Sandstone_2.png",
"url": "https://images.contentstack.io/v3/assets/blxxx/blt236db5d7d0d2c2d1/5ceb822f065d29344df9fd2d/MVMT_Rallye_Green_Sandstone_2.png",
"ACL": [],
"is_dir": false,
"_version": 1,
"title": "MVMT_Rallye_Green_Sandstone_2.png"
}
}
],
"entry": {
Expand Down
5 changes: 2 additions & 3 deletions __test__/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ describe("Field", () => {
});

it("setFocus", () => {
field.setFocus()
field.setFocus();
expect(connection.sendToParent).toHaveBeenCalledWith("focus");

});
});

Expand Down Expand Up @@ -131,7 +130,7 @@ describe("Field", () => {
singleFileField.getData()
);
expect(
fileFieldData.multiple.value.map((file) => file.uid)
fileFieldData.multiple.value.map(({ file }) => file.uid)
).toEqual(multipleFileField.getData());
});

Expand Down
2 changes: 1 addition & 1 deletion __test__/fieldModifierLocation/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("Field", () => {
singleFileField.getData()
);
expect(
fileFieldData.multiple.value.map((file) => file.uid)
fileFieldData.multiple.value.map(({ file }) => file.uid)
).toEqual(multipleFileField.getData());
});

Expand Down
36 changes: 36 additions & 0 deletions __test__/organizationFullPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IOrgFullPageLocationInitData, LocationType } from "../src/types";
import { OrganizationDetails } from "../src/types/organization.types";

const mockData: IOrgFullPageLocationInitData = {
type: LocationType.ORGANIZATION_FULL_PAGE,
app_id: "app_id",
installation_uid: "installation_uid",
extension_uid: "extension_uid",
region: "NA",
stack: {} as any,
user: {} as any,
currentBranch: "currentBranch",
organization: {} as OrganizationDetails,
};
const organizationFullPage = {
currentOrganization: mockData.organization,
};

afterEach(() => {
jest.clearAllMocks();
});

test("should return organization details", () => {
expect(organizationFullPage.currentOrganization).toBe(mockData.organization);
});

test("should handle missing organization details", () => {
const invalidData: IOrgFullPageLocationInitData = {
...mockData,
organization: null as any, // check missing organization details
};
const invalidOrganizationFullPage = {
currentOrganization: invalidData.organization,
};
expect(invalidOrganizationFullPage.currentOrganization).toBeNull();
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/app-sdk",
"version": "2.2.0",
"version": "2.3.0",
"types": "dist/src/index.d.ts",
"description": "The Contentstack App SDK allows you to customize your Contentstack applications.",
"main": "dist/index.js",
Expand Down
71 changes: 71 additions & 0 deletions src/ContentTypeSidebarWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import EventEmitter from "wolfy87-eventemitter";
import postRobot from "post-robot";
import { IContentTypeSidebarInitData } from "./types";
import { ContentType } from "./types/stack.types";
import { GenericObjectType } from "./types/common.types";

/** Class representing a Content type Sidebar UI Location from Contentstack UI. */

class ContentTypeSidebarWidget {
/**
* @hideconstructor
*/

currentContentType: ContentType;
_emitter: EventEmitter;
_connection: typeof postRobot;
_changedData?: GenericObjectType;

constructor(
initializationData: IContentTypeSidebarInitData,
connection: typeof postRobot,
emitter: EventEmitter
) {
this.currentContentType = initializationData.currentContentType;

this._emitter = emitter;

this._connection = connection;

const thisContentType = this;

this._emitter.on("contentTypeSave", (event: { data: ContentType }) => {
thisContentType.currentContentType = event.data;
});

this.getData = this.getData.bind(this);
this.onSave = this.onSave.bind(this);
}

/**
* Get the current content type data.
* @returns {ContentTypeData} The current content type data.
*/
getData(): ContentType {
return this.currentContentType;
}

/**
* Executes the provided callback function every time a content type is saved.
* @param {function} callback - The function to be called when a content type is saved.
* @param {ContentType} arg0 - The content type data passed as an argument to the callback function when a content type is saved.
*/
onSave(callback: (arg0: ContentType) => void) {
const contentTypeObj = this;
if (callback && typeof callback === "function") {
contentTypeObj._emitter.on(
"contentTypeSave",
(event: { data: ContentType }) => {
callback(event.data);
}
);
this._emitter.emitEvent("_eventRegistration", [
{ name: "contentTypeSave" },
]);
} else {
throw Error("Callback must be a function");
}
}
}

export default ContentTypeSidebarWidget;
3 changes: 1 addition & 2 deletions src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import postRobot from "post-robot";
import { IFieldInitData, IFieldModifierLocationInitData } from "./types";
import { GenericObjectType } from "./types/common.types";
import { Schema } from "./types/stack.types";
import EventRegistry from "./EventRegistry";

const excludedDataTypesForSetField = [
"file",
Expand All @@ -21,7 +20,7 @@ function separateResolvedData(field: Field, value: GenericObjectType) {
resolvedData = value;
unResolvedData =
field.schema.multiple === true
? value.map((file: any) => file.uid)
? value.map(({ file }: GenericObjectType) => file?.uid)
: value.uid;
} else if (field.schema.multiple === true) {
resolvedData = [];
Expand Down
2 changes: 1 addition & 1 deletion src/fieldModifierLocation/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function separateResolvedData(
resolvedData = value;
unResolvedData =
field.schema.multiple === true
? value.map((file: any) => file.uid)
? value.map(({ file }: GenericObjectType) => file?.uid)
: value.uid;
} else if (field.schema.multiple === true) {
resolvedData = [];
Expand Down
23 changes: 22 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Stack from "./stack";
import { GenericObjectType } from "./types/common.types";
import { Entry } from "./types/entry.types";
import { Asset, ContentType, Schema, StackDetail } from "./types/stack.types";
import { OrganizationDetails } from "./types/organization.types";
import { User } from "./types/user.types";
import Window from "./window";

Expand Down Expand Up @@ -67,6 +68,10 @@ export declare interface IAppConfigWidget {
stack: Stack;
}

export declare interface IOrgFullPageLocation {
currentOrganization: OrganizationDetails;
}

export enum DashboardWidth {
FULL_WIDTH = "full_width",
HALF_WIDTH = "half_width",
Expand All @@ -81,6 +86,8 @@ export enum LocationType {
FULL_PAGE_LOCATION = "FULL_PAGE_LOCATION",
RTE = "RTE",
WIDGET = "WIDGET",
CONTENT_TYPE_SIDEBAR_WIDGET = "CONTENT_TYPE_SIDEBAR_WIDGET",
ORGANIZATION_FULL_PAGE = "ORGANIZATION_FULL_PAGE",
}

// Init data
Expand All @@ -97,6 +104,12 @@ declare interface ICommonInitData {
manifest?: Manifest;
}

export declare interface IOrgFullPageLocationInitData extends ICommonInitData {
organization: OrganizationDetails;
config?: GenericObjectType;
type: LocationType.ORGANIZATION_FULL_PAGE;
}

export declare interface IDashboardInitData extends ICommonInitData {
dashboard_width: DashboardWidth;
config?: GenericObjectType;
Expand Down Expand Up @@ -148,6 +161,12 @@ export declare interface IAssetSidebarInitData extends ICommonInitData {
type: LocationType.ASSET_SIDEBAR_WIDGET;
}

export declare interface IContentTypeSidebarInitData extends ICommonInitData {
config?: GenericObjectType;
currentContentType: ContentType;
type: LocationType.CONTENT_TYPE_SIDEBAR_WIDGET;
}

export declare interface IFieldModifierLocationInitData
extends ICommonInitData {
changedData: Entry;
Expand Down Expand Up @@ -194,7 +213,9 @@ export type InitializationData =
| IFieldModifierLocationInitData
| IFullPageLocationInitData
| IRTEInitData
| ISidebarInitData;
| ISidebarInitData
| IContentTypeSidebarInitData
| IOrgFullPageLocationInitData;

/**
* installation details API response
Expand Down
12 changes: 12 additions & 0 deletions src/types/organization.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GenericObjectType } from "./common.types";

export declare interface OrganizationDetails {
uid: string;
name: string;
owner_uid: string;
expires_on: string;
enabled: boolean;
created_at: string;
updated_at: string;
tags: string[];
}
Loading
Loading