@@ -6,9 +6,9 @@ import androidx.compose.runtime.setValue
66import com.pega.constellation.sdk.kmp.core.api.BaseComponent
77import com.pega.constellation.sdk.kmp.core.api.Component
88import com.pega.constellation.sdk.kmp.core.api.ComponentContext
9+ import com.pega.constellation.sdk.kmp.core.api.ComponentEvent
910import com.pega.constellation.sdk.kmp.core.api.ComponentId
1011import com.pega.constellation.sdk.kmp.core.components.getBoolean
11- import com.pega.constellation.sdk.kmp.core.components.getInt
1212import com.pega.constellation.sdk.kmp.core.components.getJSONArray
1313import com.pega.constellation.sdk.kmp.core.components.getString
1414import kotlinx.serialization.json.JsonObject
@@ -21,6 +21,12 @@ class SimpleTableManualComponent(context: ComponentContext) : BaseComponent(cont
2121 private set
2222 var displayMode by mutableStateOf(DisplayMode .DISPLAY_ONLY )
2323 private set
24+ var allowAddRows by mutableStateOf(true )
25+ private set
26+ var allowReorderRows by mutableStateOf(true )
27+ private set
28+ var addButtonLabel by mutableStateOf(" " )
29+ private set
2430 var columnNames by mutableStateOf(emptyList<String >())
2531 private set
2632 var rows by mutableStateOf(emptyList<Row >())
@@ -30,6 +36,9 @@ class SimpleTableManualComponent(context: ComponentContext) : BaseComponent(cont
3036 visible = props.getBoolean(" visible" )
3137 label = props.getString(" label" )
3238 displayMode = DisplayMode .valueOf(props.getString(" displayMode" ))
39+ allowAddRows = props.getBoolean(" allowAddRows" )
40+ allowReorderRows = props.getBoolean(" allowReorderRows" )
41+ addButtonLabel = props.getString(" addButtonLabel" )
3342 columnNames = getColumnNames(props)
3443 rows = getRows(props)
3544 }
@@ -46,10 +55,43 @@ class SimpleTableManualComponent(context: ComponentContext) : BaseComponent(cont
4655 val componentIds = rowJsonObject.getJSONArray(" cellComponentIds" )
4756 val ids = componentIds.mapWithIndex { getString(it).toInt() }
4857 val cellComponents = context.componentManager.getComponents(ids.map { ComponentId (it) })
49- Row (rowJsonObject.getInt(" id" ), cellComponents.map { Cell (it) })
58+ Row (
59+ cells = cellComponents.map { Cell (it) },
60+ showEditButton = rowJsonObject.getBoolean(" showEditButton" ),
61+ showDeleteButton = rowJsonObject.getBoolean(" showDeleteButton" )
62+ )
5063 }
5164
52- data class Row (val id : Int , val cells : List <Cell >)
65+ fun addRow () = context.sendComponentEvent(ComponentEvent .simpleTableManualAddRow())
66+
67+ fun deleteRow (rowId : Int ) =
68+ context.sendComponentEvent(ComponentEvent .simpleTableManualDeleteRow(rowId))
69+
70+ fun reorderRow (fromIndex : Int , toIndex : Int ) =
71+ context.sendComponentEvent(ComponentEvent .simpleTableManualReorderRow(fromIndex, toIndex))
72+
73+ private fun ComponentEvent.Companion.simpleTableManualAddRow () =
74+ ComponentEvent (" SimpleTableManualEvent" , eventData = mapOf (" type" to " addRow" ))
75+
76+ private fun ComponentEvent.Companion.simpleTableManualDeleteRow (itemId : Int ) =
77+ ComponentEvent (
78+ " SimpleTableManualEvent" ,
79+ eventData = mapOf (" type" to " deleteRow" , " rowId" to itemId.toString())
80+ )
81+
82+ private fun ComponentEvent.Companion.simpleTableManualReorderRow (fromIndex : Int , toIndex : Int ) =
83+ ComponentEvent (
84+ " SimpleTableManualEvent" , eventData = mapOf (
85+ " type" to " reorderRow" ,
86+ " fromIndex" to fromIndex.toString(), " toIndex" to toIndex.toString()
87+ )
88+ )
89+
90+ data class Row (
91+ val cells : List <Cell >,
92+ val showEditButton : Boolean ,
93+ val showDeleteButton : Boolean
94+ )
5395
5496 data class Cell (val component : Component )
5597
0 commit comments