-
Notifications
You must be signed in to change notification settings - Fork 3
TASK-1828883: adding support for SimpleTableManual #94
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 all commits
dd85cb9
3d5447c
9d977f5
7f44f1d
b1a822d
1f44244
ff9b40e
0a8a6c2
0dcce27
ced4e50
186af9a
c7b88c5
de5d6e3
8ec85bf
231042f
d80fec4
bc36f2c
55b18fb
bf2b646
18d26c1
1fb80a9
cc74416
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,58 @@ | ||
| package com.pega.constellation.sdk.kmp.core.components.containers | ||
|
|
||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.setValue | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentContext | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentEvent | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentId | ||
| import com.pega.constellation.sdk.kmp.core.api.HideableComponent | ||
| import com.pega.constellation.sdk.kmp.core.components.getBoolean | ||
| import com.pega.constellation.sdk.kmp.core.components.getJSONArray | ||
| import com.pega.constellation.sdk.kmp.core.components.getString | ||
| import com.pega.constellation.sdk.kmp.core.components.widgets.AlertBannerComponent | ||
| import com.pega.constellation.sdk.kmp.core.internal.ComponentManagerImpl.Companion.getComponentTyped | ||
| import kotlinx.serialization.json.JsonObject | ||
|
|
||
| class ModalViewContainerComponent(context: ComponentContext) : ContainerComponent(context), HideableComponent { | ||
| override var visible by mutableStateOf(false) | ||
| private set | ||
| var title by mutableStateOf("") | ||
| private set | ||
| var cancelButtonLabel by mutableStateOf("") | ||
| private set | ||
| var submitButtonLabel by mutableStateOf("") | ||
| private set | ||
| var alertBanners: List<AlertBannerComponent> by mutableStateOf(emptyList()) | ||
| private set | ||
|
|
||
| override fun applyProps(props: JsonObject) { | ||
| super.applyProps(props) | ||
| visible = props.getBoolean("visible") | ||
| title = props.getString("title") | ||
| cancelButtonLabel = props.getString("cancelLabel") | ||
| submitButtonLabel = props.getString("submitLabel") | ||
| val banners = props.getJSONArray("alertBanners") | ||
| val bannersIds = banners.mapWithIndex { getString(it).toInt() } | ||
| alertBanners = | ||
| bannersIds.mapNotNull { context.componentManager.getComponentTyped(ComponentId(it)) } | ||
| } | ||
|
|
||
| fun onCancelClick() { | ||
| context.sendComponentEvent(cancelEvent()) | ||
| } | ||
|
|
||
| fun onSubmitClick() { | ||
| context.sendComponentEvent(submitEvent()) | ||
| } | ||
|
|
||
| fun cancelEvent() = ComponentEvent( | ||
| type = "ModalViewContainerEvent", | ||
| eventData = mapOf("type" to "cancel") | ||
| ) | ||
|
|
||
| fun submitEvent() = ComponentEvent( | ||
| type = "ModalViewContainerEvent", | ||
| eventData = mapOf("type" to "submit") | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package com.pega.constellation.sdk.kmp.core.components.containers | ||
|
|
||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.setValue | ||
| import com.pega.constellation.sdk.kmp.core.api.BaseComponent | ||
| import com.pega.constellation.sdk.kmp.core.api.Component | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentContext | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentEvent | ||
| import com.pega.constellation.sdk.kmp.core.api.ComponentId | ||
| import com.pega.constellation.sdk.kmp.core.api.HideableComponent | ||
| import com.pega.constellation.sdk.kmp.core.components.getBoolean | ||
| import com.pega.constellation.sdk.kmp.core.components.getJSONArray | ||
| import com.pega.constellation.sdk.kmp.core.components.getString | ||
| import kotlinx.serialization.json.JsonObject | ||
| import kotlinx.serialization.json.jsonObject | ||
|
|
||
| class SimpleTableManualComponent(context: ComponentContext) : BaseComponent(context), HideableComponent { | ||
| override var visible by mutableStateOf(false) | ||
| private set | ||
| var label: String by mutableStateOf("") | ||
| private set | ||
| var displayMode by mutableStateOf(DisplayMode.DISPLAY_ONLY) | ||
| private set | ||
| var allowAddRows by mutableStateOf(true) | ||
| private set | ||
| var allowReorderRows by mutableStateOf(true) | ||
| private set | ||
| var addButtonLabel by mutableStateOf("") | ||
| private set | ||
| var columnNames by mutableStateOf(emptyList<String>()) | ||
| private set | ||
| var rows by mutableStateOf(emptyList<Row>()) | ||
| private set | ||
|
|
||
| override fun applyProps(props: JsonObject) { | ||
| visible = props.getBoolean("visible") | ||
| label = props.getString("label") | ||
| displayMode = DisplayMode.valueOf(props.getString("displayMode")) | ||
| allowAddRows = props.getBoolean("allowAddRows") | ||
| allowReorderRows = props.getBoolean("allowReorderRows") | ||
| addButtonLabel = props.getString("addButtonLabel") | ||
| columnNames = getColumnNames(props) | ||
| rows = getRows(props) | ||
| } | ||
|
|
||
| private fun getColumnNames(props: JsonObject): List<String> { | ||
| val columnsJsonArray = props.getJSONArray("columnLabels") | ||
| return columnsJsonArray.mapWithIndex { getString(it) } | ||
| } | ||
|
|
||
| private fun getRows(props: JsonObject): List<Row> = | ||
| props.getJSONArray("rows").map { jsonElement -> | ||
| val rowJsonObject = jsonElement.jsonObject | ||
| val componentIds = rowJsonObject.getJSONArray("cellComponentIds") | ||
| val ids = componentIds.mapWithIndex { getString(it).toInt() } | ||
| val cellComponents = context.componentManager.getComponents(ids.map { ComponentId(it) }) | ||
| Row( | ||
| cells = cellComponents.map { Cell(it) }, | ||
| showEditButton = rowJsonObject.getBoolean("showEditButton"), | ||
| showDeleteButton = rowJsonObject.getBoolean("showDeleteButton") | ||
| ) | ||
| } | ||
|
|
||
| fun addRow() = context.sendComponentEvent(simpleTableManualAddRowEvent()) | ||
|
|
||
| fun deleteRow(rowId: Int) = | ||
| context.sendComponentEvent(simpleTableManualDeleteRowEvent(rowId)) | ||
|
|
||
| fun reorderRow(fromIndex: Int, toIndex: Int) = | ||
| context.sendComponentEvent(simpleTableManualReorderRowEvent(fromIndex, toIndex)) | ||
|
|
||
| fun editRowInModal(rowId: Int) = | ||
| context.sendComponentEvent(simpleTableManualEditRowInModalEvent(rowId)) | ||
|
|
||
| fun addRowInModal() = | ||
| context.sendComponentEvent(simpleTableManualAddRowInModalEvent()) | ||
|
|
||
| private fun simpleTableManualAddRowEvent() = | ||
| ComponentEvent("SimpleTableManualEvent", eventData = mapOf("type" to "addRow")) | ||
|
|
||
| private fun simpleTableManualDeleteRowEvent(itemId: Int) = | ||
| ComponentEvent( | ||
| "SimpleTableManualEvent", | ||
| eventData = mapOf("type" to "deleteRow", "rowId" to itemId.toString()) | ||
| ) | ||
|
|
||
| private fun simpleTableManualReorderRowEvent(fromIndex: Int, toIndex: Int) = | ||
| ComponentEvent( | ||
| "SimpleTableManualEvent", eventData = mapOf( | ||
| "type" to "reorderRow", | ||
| "fromIndex" to fromIndex.toString(), "toIndex" to toIndex.toString() | ||
| ) | ||
| ) | ||
|
|
||
| private fun simpleTableManualEditRowInModalEvent(rowId: Int) = | ||
| ComponentEvent( | ||
| "SimpleTableManualEvent", eventData = mapOf( | ||
| "type" to "editRowInModal", | ||
| "rowId" to rowId.toString() | ||
| ) | ||
| ) | ||
|
|
||
| private fun simpleTableManualAddRowInModalEvent() = | ||
| ComponentEvent( | ||
| "SimpleTableManualEvent", eventData = mapOf( | ||
| "type" to "addRowInModal" | ||
| ) | ||
| ) | ||
|
|
||
| data class Row( | ||
| val cells: List<Cell>, | ||
| val showEditButton: Boolean, | ||
| val showDeleteButton: Boolean | ||
| ) | ||
|
|
||
| data class Cell(val component: Component) | ||
|
|
||
| enum class DisplayMode { | ||
| DISPLAY_ONLY, EDITABLE_IN_MODAL, EDITABLE_IN_ROW | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,9 @@ class GroupTest : ComposeTest(PegaVersion.v24_2_2) { | |
| waitForNode("Lists group heading", substring = true) | ||
| waitForNode("List group instructions", substring = true) | ||
| waitForNode("cars") | ||
| waitForNode("Encryption keys") | ||
|
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. Why this change?
Contributor
Author
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've fixed that. It was passing earlier because the table was not actually loaded and we had only 1 label of the view. |
||
| waitForNode("cars 1") | ||
| waitForNodes("Encryption keys", 2) // TODO: label displayed twice due to ISSUE-138617 | ||
| waitForNodes("AeroCrypt-AuroraCrypt", 2) // No idea why but test sees it twice even if it's once in UI | ||
| } | ||
|
|
||
| private fun ComposeUiTest.verifyListGroupGone() { | ||
|
|
||
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.
extra new line