Skip to content

Commit 53ab06e

Browse files
TASK-1786159: add support for add/edit row in popup
- adding ModalViewContainerComponent
1 parent ee0d047 commit 53ab06e

File tree

15 files changed

+727
-31
lines changed

15 files changed

+727
-31
lines changed

core/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/core/components/ComponentRegistry.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.FlowContain
1818
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.Group
1919
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.Integer
2020
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.ListView
21+
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.ModalViewContainer
2122
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.OneColumn
2223
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.Phone
2324
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes.RadioButtons
@@ -41,6 +42,7 @@ import com.pega.constellation.sdk.kmp.core.components.containers.FieldGroupTempl
4142
import com.pega.constellation.sdk.kmp.core.components.containers.FlowContainerComponent
4243
import com.pega.constellation.sdk.kmp.core.components.containers.GroupComponent
4344
import com.pega.constellation.sdk.kmp.core.components.containers.ListViewComponent
45+
import com.pega.constellation.sdk.kmp.core.components.containers.ModalViewContainerComponent
4446
import com.pega.constellation.sdk.kmp.core.components.containers.OneColumnComponent
4547
import com.pega.constellation.sdk.kmp.core.components.containers.RegionComponent
4648
import com.pega.constellation.sdk.kmp.core.components.containers.RootContainerComponent
@@ -94,6 +96,7 @@ object ComponentRegistry {
9496
Def(Group) { GroupComponent(it) },
9597
Def(Integer) { IntegerComponent(it) },
9698
Def(ListView) { ListViewComponent(it) },
99+
Def(ModalViewContainer) { ModalViewContainerComponent(it) },
97100
Def(OneColumn) { OneColumnComponent(it) },
98101
Def(Phone) { PhoneComponent(it) },
99102
Def(RadioButtons) { RadioButtonsComponent(it) },

core/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/core/components/ComponentTypes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ object ComponentTypes {
1414
val FlowContainer = ComponentType("FlowContainer")
1515
val Group = ComponentType("Group")
1616
val ListView = ComponentType("ListView")
17+
val ModalViewContainer = ComponentType("ModalViewContainer")
1718
val OneColumn = ComponentType("OneColumn")
1819
val Region = ComponentType("Region")
1920
val RootContainer = ComponentType("RootContainer")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.pega.constellation.sdk.kmp.core.components.containers
2+
3+
import androidx.compose.runtime.getValue
4+
import androidx.compose.runtime.mutableStateOf
5+
import androidx.compose.runtime.setValue
6+
import com.pega.constellation.sdk.kmp.core.api.ComponentContext
7+
import com.pega.constellation.sdk.kmp.core.api.ComponentEvent
8+
import com.pega.constellation.sdk.kmp.core.components.getBoolean
9+
import com.pega.constellation.sdk.kmp.core.components.getString
10+
import kotlinx.serialization.json.JsonObject
11+
12+
class ModalViewContainerComponent(context: ComponentContext) : ContainerComponent(context) {
13+
var visible by mutableStateOf(false)
14+
var title by mutableStateOf("")
15+
private set
16+
var cancelButtonLabel by mutableStateOf("")
17+
private set
18+
var submitButtonLabel by mutableStateOf("")
19+
private set
20+
21+
override fun applyProps(props: JsonObject) {
22+
super.applyProps(props)
23+
visible = props.getBoolean("visible")
24+
title = props.getString("title")
25+
cancelButtonLabel = props.getString("cancelLabel")
26+
submitButtonLabel = props.getString("submitLabel")
27+
}
28+
29+
fun onCancelClick() {
30+
context.sendComponentEvent(cancelEvent())
31+
}
32+
33+
fun onSubmitClick() {
34+
context.sendComponentEvent(submitEvent())
35+
}
36+
37+
fun cancelEvent() = ComponentEvent(
38+
type = "ModalViewContainerEvent",
39+
eventData = mapOf("type" to "cancel")
40+
)
41+
fun submitEvent() = ComponentEvent(
42+
type = "ModalViewContainerEvent",
43+
eventData = mapOf("type" to "submit")
44+
)
45+
}

core/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/core/components/containers/RootContainer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class RootContainerComponent(context: ComponentContext) : BaseComponent(context)
2020
private set
2121
var dialogConfig: Dialog.Config? by mutableStateOf(null)
2222
private set
23+
var modalViewContainer: ModalViewContainerComponent? by mutableStateOf(null)
24+
private set
2325

2426
fun presentDialog(config: Dialog.Config) {
2527
dialogConfig = config
@@ -33,8 +35,10 @@ class RootContainerComponent(context: ComponentContext) : BaseComponent(context)
3335

3436
override fun applyProps(props: JsonObject) {
3537
val viewContainerId = ComponentId(props.getString("viewContainer").toInt())
36-
val httpMessagesArray = props.getJSONArray("httpMessages")
3738
viewContainer = context.componentManager.getComponentTyped(viewContainerId)
39+
val modalViewContainerId = ComponentId(props.getString("modalViewContainer").toInt())
40+
modalViewContainer = context.componentManager.getComponentTyped(modalViewContainerId)
41+
val httpMessagesArray = props.getJSONArray("httpMessages")
3842
httpMessages = httpMessagesArray.mapWithIndex {
3943
val httpMessage = getJsonObject(it)
4044
val type = httpMessage.getString("type")

core/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/core/components/containers/SimpleTableManual.kt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,52 @@ class SimpleTableManualComponent(context: ComponentContext) : BaseComponent(cont
6262
)
6363
}
6464

65-
fun addRow() = context.sendComponentEvent(ComponentEvent.simpleTableManualAddRow())
65+
fun addRow() = context.sendComponentEvent(simpleTableManualAddRowEvent())
6666

6767
fun deleteRow(rowId: Int) =
68-
context.sendComponentEvent(ComponentEvent.simpleTableManualDeleteRow(rowId))
68+
context.sendComponentEvent(simpleTableManualDeleteRowEvent(rowId))
6969

7070
fun reorderRow(fromIndex: Int, toIndex: Int) =
71-
context.sendComponentEvent(ComponentEvent.simpleTableManualReorderRow(fromIndex, toIndex))
71+
context.sendComponentEvent(simpleTableManualReorderRowEvent(fromIndex, toIndex))
7272

73-
private fun ComponentEvent.Companion.simpleTableManualAddRow() =
73+
fun editRowInModal(rowId: Int) =
74+
context.sendComponentEvent(simpleTableManualEditRowInModalEvent(rowId))
75+
76+
fun addRowInModal() =
77+
context.sendComponentEvent(simpleTableManualAddRowInModalEvent())
78+
79+
private fun simpleTableManualAddRowEvent() =
7480
ComponentEvent("SimpleTableManualEvent", eventData = mapOf("type" to "addRow"))
7581

76-
private fun ComponentEvent.Companion.simpleTableManualDeleteRow(itemId: Int) =
82+
private fun simpleTableManualDeleteRowEvent(itemId: Int) =
7783
ComponentEvent(
7884
"SimpleTableManualEvent",
7985
eventData = mapOf("type" to "deleteRow", "rowId" to itemId.toString())
8086
)
8187

82-
private fun ComponentEvent.Companion.simpleTableManualReorderRow(fromIndex: Int, toIndex: Int) =
88+
private fun simpleTableManualReorderRowEvent(fromIndex: Int, toIndex: Int) =
8389
ComponentEvent(
8490
"SimpleTableManualEvent", eventData = mapOf(
8591
"type" to "reorderRow",
8692
"fromIndex" to fromIndex.toString(), "toIndex" to toIndex.toString()
8793
)
8894
)
8995

96+
private fun simpleTableManualEditRowInModalEvent(rowId: Int) =
97+
ComponentEvent(
98+
"SimpleTableManualEvent", eventData = mapOf(
99+
"type" to "editRowInModal",
100+
"rowId" to rowId.toString()
101+
)
102+
)
103+
104+
private fun simpleTableManualAddRowInModalEvent() =
105+
ComponentEvent(
106+
"SimpleTableManualEvent", eventData = mapOf(
107+
"type" to "addRowInModal"
108+
)
109+
)
110+
90111
data class Row(
91112
val cells: List<Cell>,
92113
val showEditButton: Boolean,

core/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/core/components/widgets/Unsupported.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import com.pega.constellation.sdk.kmp.core.api.ComponentContextImpl
1010
import com.pega.constellation.sdk.kmp.core.api.ComponentType
1111
import com.pega.constellation.sdk.kmp.core.api.HideableComponent
1212
import com.pega.constellation.sdk.kmp.core.components.ComponentTypes
13-
import com.pega.constellation.sdk.kmp.core.components.getBoolean
14-
import com.pega.constellation.sdk.kmp.core.components.getString
13+
import com.pega.constellation.sdk.kmp.core.components.optBoolean
14+
import com.pega.constellation.sdk.kmp.core.components.optString
1515
import com.pega.constellation.sdk.kmp.core.components.widgets.UnsupportedComponent.Cause.MISSING_JAVASCRIPT_IMPLEMENTATION
1616
import com.pega.constellation.sdk.kmp.core.components.widgets.UnsupportedComponent.Cause.UNKNOWN_CAUSE
1717
import kotlinx.serialization.json.JsonObject
@@ -30,9 +30,9 @@ class UnsupportedComponent(
3030
private set
3131

3232
override fun applyProps(props: JsonObject) {
33-
type = ComponentType(props.getString("type"))
33+
type = ComponentType(props.optString("type", this.type.type))
3434
cause = MISSING_JAVASCRIPT_IMPLEMENTATION
35-
visible = props.getBoolean("visible")
35+
visible = props.optBoolean("visible", visible)
3636
}
3737

3838
enum class Cause {

engine-webview/src/androidMain/kotlin/com/pega/constellation/sdk/kmp/engine/webview/android/interceptor/WebViewNetworkInterceptor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ internal class WebViewNetworkInterceptor(
4141
}
4242

4343
fun setRequestBody(body: String) {
44+
Log.e("DEBUG", "Setting request body: $body")
4445
requestBody.set(body)
4546
}
4647

4748
private fun OkHttpClient.execute(request: WebResourceRequest): Response {
49+
if (request.method == "POST" || request.method == "PATCH") {
50+
Log.e("DEBUG", "OkHttpClient.execute for: ${request.method} to ${request.url}, requestBody: $requestBody")
51+
}
4852
val body = requestBody.takeIf { request.method in listOf("POST", "PATCH") }
4953
?.getAndSet(null)
5054
?.toRequestBody()

0 commit comments

Comments
 (0)