-
Notifications
You must be signed in to change notification settings - Fork 3
Added Content type sidebar UI location #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
praveen-mohan-cs
merged 4 commits into
staging
from
feat/DEVREL-203-content-type-ui-location
Oct 25, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
da6825e
Added Content type sidebar UI location
praveen-mohan-cs 218c8bd
Merge branch 'staging' of https://github.com/contentstack/app-sdk int…
praveen-mohan-cs 59eb67e
Addressed PR comments
praveen-mohan-cs 51577bb
Addressed PR comments
praveen-mohan-cs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
praveen-mohan-cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const contentTypeObj = this; | ||
if (callback && typeof callback === "function") { | ||
contentTypeObj._emitter.on( | ||
praveen-mohan-cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"contentTypeSave", | ||
(event: { data: ContentType }) => { | ||
callback(event.data); | ||
} | ||
); | ||
this._emitter.emitEvent("_eventRegistration", [ | ||
{ name: "contentTypeSave" }, | ||
]); | ||
} else { | ||
throw Error("Callback must be a function"); | ||
} | ||
} | ||
} | ||
|
||
export default ContentTypeSidebarWidget; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.