-
Notifications
You must be signed in to change notification settings - Fork 3
TASK-1816943: Added support for startingFields for WKWebView based en… #52
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
Changes from 5 commits
ec7a2da
8b64205
9c74514
e32a89b
634eaa9
30b9313
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.pega.constellation.sdk.kmp.core | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.json.JsonObject | ||
|
|
||
| /** | ||
| * Represents various actions that can be performed using the Constellation SDK. | ||
| */ | ||
| @Serializable | ||
| sealed class ConstellationSdkAction { | ||
|
|
||
| @Serializable | ||
| @SerialName("CreateCase") | ||
| data class CreateCase( | ||
| val caseClassName: String, | ||
| val startingFields: JsonObject? = null | ||
| ) : ConstellationSdkAction() | ||
|
|
||
| @Serializable | ||
| @SerialName("OpenAssignment") | ||
| data class OpenAssignment( | ||
| val assignmentId: String | ||
| ) : ConstellationSdkAction() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.pega.constellation.sdk.kmp.core.internal | ||
|
|
||
| import com.pega.constellation.sdk.kmp.core.Log | ||
| import kotlinx.serialization.json.JsonArray | ||
| import kotlinx.serialization.json.JsonElement | ||
| import kotlinx.serialization.json.JsonObject | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
|
|
||
| private const val TAG = "JsonHelper" | ||
|
|
||
| fun Any.toJsonElement(): JsonElement? = when (this) { | ||
|
||
| is String -> JsonPrimitive(this) | ||
| is Int -> JsonPrimitive(this) | ||
| is Double -> JsonPrimitive(this) | ||
| is Float -> JsonPrimitive(this) | ||
| is Boolean -> JsonPrimitive(this) | ||
| is List<*> -> { | ||
| val jsonElements = this.mapNotNull { | ||
| it?.toJsonElement() ?: run { | ||
| val type = it?.let { it::class } ?: "null" | ||
| Log.w(TAG, "Unsupported type $type, cannot convert to JsonElement.") | ||
|
||
| null | ||
| } | ||
| } | ||
| JsonArray(jsonElements) | ||
| } | ||
| is Map<*, *> -> { | ||
| val map = this.entries.mapNotNull { (key, value) -> | ||
| (key as? String)?.let { k -> | ||
| value?.toJsonElement()?.let { v -> k to v } | ||
| } ?: run { | ||
| val keyType = key?.let { it::class } ?: "null" | ||
| val valueType = value?.let { it::class } ?: "null" | ||
| Log.w(TAG, "Unsupported key type <$keyType> or value type <$valueType>, cannot convert to JsonElement.") | ||
| null | ||
| } | ||
| }.toMap() | ||
| JsonObject(map) | ||
| } | ||
| else -> { | ||
| Log.w(TAG, "Unsupported type ${this::class}, cannot convert to JsonElement.") | ||
| null | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { initPlatforms } from './init-platforms.js'; | |
| import { initialRender } from './initial-render.js'; | ||
| import { bootstrap } from './bootstrap.js' | ||
| import { createCase } from './create-case.js'; | ||
| import { openAssignment } from './open-assignment.js'; | ||
| import { getSdkComponentMap } from '../dxcomponents/mappings/sdk-component-map.js'; | ||
| import { bridge } from '../bridge/native-bridge.js'; | ||
| import { subscribeForEvents } from './init-events.js'; | ||
|
|
@@ -17,11 +18,20 @@ async function init(sdkConfig, componentsOverridesStr) { | |
| initPlatforms(componentsOverridesStr); | ||
| const config = JSON.parse(sdkConfig); | ||
| await bootstrap(config.url, config.version, onPCoreReady); | ||
| await createCase(config.caseClassName, config.startingFields); | ||
|
|
||
| if (config.action.type === "CreateCase") { | ||
| await createCase(config.action.caseClassName, config.action.startingFields); | ||
| } else if (config.action.type === "OpenAssignment") { | ||
| await openAssignment(config.action.assignmentId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that it is okay for now, but in the future we should consider making it possible to "interact" with the application/engine instead of just reinitializing everything each time we want to open or create something. |
||
| } else { | ||
| const errorMessage = "Unknown action type: " + config.action.type; | ||
| throw new Error(errorMessage); | ||
| } | ||
|
|
||
| console.log(TAG, "Constellation SDK initialization completed"); | ||
| bridge.onReady(); | ||
| } catch (error) { | ||
| const errorMessage = "Constellation SDK initialization failed! " + (error?.message ?? "") | ||
| const errorMessage = "Constellation SDK initialization failed! " + (error?.message ?? ""); | ||
| console.error(errorMessage); | ||
| bridge.onError("InitError", errorMessage); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export async function openAssignment(assignmentId) { | ||
|
|
||
| const options = { | ||
| pageName: 'pyEmbedAssignment' | ||
| }; | ||
|
|
||
| console.log("[OpenAssignment]", "Opening assignment: " + assignmentId); | ||
| await PCore.getMashupApi().openAssignment(assignmentId, PCore.getConstants().APP.APP, options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, that's so simple 😎 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be implementation-detail of specific engine. I'd move it to
engine-webview > commonMainand make it internal, as it is not something to be used by SDK clients. Btw - commonMain sourceset was recently created here: https://github.com/pegasystems/constellation-mobile-sdk/pull/49/files#diff-2398e22a8cacbeea18a4b5885f734cb50ef9029a687327c36481db76d377e40a