Skip to content

Commit 4bf4b08

Browse files
author
Kaushik Shetty
committed
doc: add jsdoc and fix return type for asset sidebar widget
1 parent af37430 commit 4bf4b08

File tree

2 files changed

+61
-27
lines changed

2 files changed

+61
-27
lines changed

src/AssetSidebarWidget.ts

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,62 @@ class AssetSidebarWidget {
5454
this.replaceAsset = this.replaceAsset.bind(this);
5555
}
5656

57-
getData() {
57+
/**
58+
* Get the current asset data.
59+
* @returns {AssetData} The current asset data.
60+
*/
61+
getData(): AssetType {
5862
return this.currentAsset;
5963
}
6064

65+
/**
66+
* Set data for the asset.
67+
* @param {Partial<setAssetDto>} asset - The partial asset data to set.
68+
* @returns {Promise<void>} A promise that resolves when the data is set successfully.
69+
*/
6170
async setData(asset: Partial<setAssetDto>): Promise<void> {
62-
this._connection.sendToParent("setData", asset);
71+
await this._connection.sendToParent("setData", asset);
6372
}
6473

74+
/**
75+
* Synchronize the asset with the parent application in the Contentstack UI.
76+
* @returns {Promise<void>} A promise that resolves when the synchronization is complete.
77+
*/
6578
async syncAsset(): Promise<void> {
66-
this._connection.sendToParent("syncAsset");
79+
await this._connection.sendToParent("syncAsset");
6780
}
6881

82+
/**
83+
* Update the width of the Asset Sidebar widget in the Contentstack UI.
84+
* @param {number} width - The new width of the asset sidebar.
85+
* @throws {Error} Throws an error if the width parameter is not a number.
86+
* @returns {Promise<void>} A promise that resolves when the width is updated successfully.
87+
*/
6988
async updateWidth(width: number): Promise<void> {
7089
if (typeof width !== "number") {
7190
throw new Error("Width must be a number");
7291
}
73-
this._connection.sendToParent("updateAssetSidebarWidth", width as any);
92+
await this._connection.sendToParent(
93+
"updateAssetSidebarWidth",
94+
width as any
95+
);
7496
}
7597

76-
async replaceAsset(file: File): Promise<any> {
98+
/**
99+
* Replace the current asset with a new file.
100+
* @param {File} file - The file to be used as the replacement asset.
101+
* @returns {Promise<void>} A promise that resolves when the replacement is complete.
102+
*/
103+
async replaceAsset(file: File): Promise<void> {
77104
const asset = Asset(this._emitter);
78-
return asset.handleUpload([file], "replace");
105+
await asset.handleUpload([file], "replace");
79106
}
80107

81108
/**
82-
* This function executes the callback function every time an asset is saved.
83-
* @param {function} callback The function to be called when an asset is saved.
109+
* Executes the provided callback function every time an asset is saved.
110+
* @param {function} callback - The function to be called when an asset is saved.
111+
* @param {AssetType} arg0 - The asset data passed as an argument to the callback function when an asset is saved.
84112
*/
85-
86113
onSave(callback: (arg0: AssetType) => void) {
87114
const assetObj = this;
88115
if (callback && typeof callback === "function") {
@@ -95,10 +122,11 @@ class AssetSidebarWidget {
95122
}
96123

97124
/**
98-
* The field.onChange() function is called when another extension programmatically changes the data of the current extension field using the field.setData() function. This function is only available for extension fields that support the following data types: text, number, boolean, or date.
99-
* @param {function} callback The function to be called when an asset is edited/changed.
125+
* The `field.onChange()` function is called when another extension programmatically changes the data of the current extension field using the `field.setData()` function.
126+
* This function is only available for extension fields that support the following data types: text, number, boolean, or date.
127+
* @param {function} callback - The function to be called when the asset is edited/changed.
128+
* @param {AssetType} arg0 - The asset data passed as an argument to the callback function when the asset is edited/changed.
100129
*/
101-
102130
onChange(callback: (arg0: AssetType) => void) {
103131
const assetObj = this;
104132
if (callback && typeof callback === "function") {
@@ -112,9 +140,9 @@ class AssetSidebarWidget {
112140

113141
/**
114142
* The onPublish() function executes the callback function every time an asset has been published with the respective payload.
115-
* @param {function} callback The function to be called when an asset is published.
143+
* @param {function} callback - The function to be called when an asset is published.
144+
* @param {AssetType} arg0 - The data of the published asset passed as an argument to the callback function.
116145
*/
117-
118146
onPublish(callback: (arg0: AssetType) => void) {
119147
const assetObj = this;
120148
if (callback && typeof callback === "function") {
@@ -127,10 +155,10 @@ class AssetSidebarWidget {
127155
}
128156

129157
/**
130-
* The onUnPublish() function executes the callback function every time an asset has been unpublished with the respective payload.
131-
* @param {function} callback The function to be called when an asset is un published.
158+
* The `onUnPublish()` function executes the provided callback every time an asset is unpublished.
159+
* @param {function} callback - The function to be called when an asset is unpublished.
160+
* @param {AssetType} arg0 - The data of the unpublished asset passed as an argument to the callback function.
132161
*/
133-
134162
onUnPublish(callback: (arg0: AssetType) => void) {
135163
const assetObj = this;
136164
if (callback && typeof callback === "function") {
@@ -142,4 +170,5 @@ class AssetSidebarWidget {
142170
}
143171
}
144172
}
145-
export default AssetSidebarWidget;
173+
174+
export default AssetSidebarWidget;

src/appConfig/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import Stack from "../stack";
21
import postRobot from "post-robot";
3-
import { IInstallationData, ValidationOptions, IAppConfigInitData } from "../types";
4-
import { GenericObjectType } from "../types/common.types";
2+
3+
import Stack from "../stack";
4+
import {
5+
IInstallationData,
6+
ValidationOptions,
7+
IAppConfigInitData,
8+
} from "../types";
59
import generateErrorMessages, { ERROR_MESSAGES } from "../utils/errorMessages";
610
import { onData, onError } from "../utils/utils";
711

8-
912
export declare interface AppConfigAdditionalData {
1013
currentBranch: string;
1114
}
12-
1315

1416
/**
1517
* Class representing the current stack in Contentstack UI.
@@ -30,9 +32,9 @@ export class AppConfig {
3032
this._data = data;
3133
this._connection = connection;
3234
this._emitter = emitter;
35+
this._additionalData = additionalData;
3336

3437
this.setValidity = this.setValidity.bind(this);
35-
this._additionalData = additionalData;
3638
}
3739

3840
stack = () => {
@@ -43,9 +45,12 @@ export class AppConfig {
4345

4446
setInstallationData = (
4547
installationData: IInstallationData
46-
): Promise<GenericObjectType> => {
48+
): Promise<IInstallationData> => {
4749
return this._connection
48-
.sendToParent("setInstallationData", installationData)
50+
.sendToParent<IInstallationData>(
51+
"setInstallationData",
52+
installationData
53+
)
4954
.then(onData)
5055
.catch(onError);
5156
};
@@ -61,7 +66,7 @@ export class AppConfig {
6166
* Sets the validation state of the app. If the validation is false, the Contentstack App Config
6267
* will not allow saving the configuration. The message will be displayed if provided.
6368
* @param {boolean} isValid - The validation state of the app.
64-
* @param {object} options - Additional options to be sent to the parent.
69+
* @param {ValidationOptions} options - Additional options to be sent to the parent.
6570
* @returns {Promise<void>} - A promise that resolves to void.
6671
*/
6772
async setValidity(

0 commit comments

Comments
 (0)