Skip to content

Commit

Permalink
Merge pull request #3102 from wordpress-mobile/issue/12696-keep-json-…
Browse files Browse the repository at this point in the history
…values

[Custom Fields] Store Json values
  • Loading branch information
JorgeMucientes authored Oct 1, 2024
2 parents 06e2a17 + bd6d5b7 commit 373bc6d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ private fun ContentView(state: CustomFieldsState.Loaded) {
)
}
Spacer(modifier = Modifier.weight(1f))
IconButton({ fieldBeingEdited = customField }) {
Icon(Icons.Default.Edit, contentDescription = "Edit")
if (!customField.isJson) {
IconButton({ fieldBeingEdited = customField }) {
Icon(Icons.Default.Edit, contentDescription = "Edit")
}
}
IconButton({ state.onDelete(customField) }) {
Icon(Icons.Default.Delete, contentDescription = "Delete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import javax.inject.Inject

class StripProductMetaData @Inject internal constructor() {
operator fun invoke(metaData: List<WCMetaData>): List<WCMetaData> {
return metaData.filter { !it.isJson || SUPPORTED_KEYS.contains(it.key) }
return metaData.filter { it.isDisplayable || SUPPORTED_KEYS.contains(it.key) }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ data class WCMetaData(
private const val DISPLAY_KEY = "display_key"
private const val DISPLAY_VALUE = "display_value"

val SUPPORTED_KEYS: Set<String> = buildSet {
add(SubscriptionMetadataKeys.SUBSCRIPTION_RENEWAL)
add(BundleMetadataKeys.BUNDLED_ITEM_ID)
addAll(OrderAttributionInfoKeys.ALL_KEYS)
}

internal fun fromJson(json: JsonElement): WCMetaData? = runCatching {
val jsonObject = json.asJsonObject
WCMetaData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ internal class StripOrder @Inject constructor(private val gson: Gson) {
lineItems = gson.toJson(fatModel.getLineItemList().map { lineItemDto: LineItem ->
lineItemDto.copy(
metaData = lineItemDto.metaData
?.filter { it.isDisplayable || it.key in WCMetaData.SUPPORTED_KEYS }
?.filter {
it.isDisplayable
|| it.key == WCMetaData.BundleMetadataKeys.BUNDLED_ITEM_ID
}
)
}),
shippingLines = gson.toJson(fatModel.getShippingLineList()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package org.wordpress.android.fluxc.network.rest.wpcom.wc.order

import org.wordpress.android.fluxc.model.metadata.WCMetaData
import org.wordpress.android.fluxc.model.metadata.WCMetaData.OrderAttributionInfoKeys
import org.wordpress.android.fluxc.model.metadata.WCMetaData.SubscriptionMetadataKeys
import javax.inject.Inject

class StripOrderMetaData @Inject internal constructor() {
companion object {
private val SUPPORTED_KEYS: Set<String> = buildSet {
add(SubscriptionMetadataKeys.SUBSCRIPTION_RENEWAL)
addAll(OrderAttributionInfoKeys.ALL_KEYS)
}
}

operator fun invoke(metaData: List<WCMetaData>): List<WCMetaData> {
return metaData
.filter {
(it.isDisplayable || it.key in WCMetaData.SUPPORTED_KEYS)
&& !it.isJson
it.isDisplayable || it.key in SUPPORTED_KEYS
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StripOrderMetaDataTest {
}

@Test
fun `when Metadata value contains JSON, then remove it from the list`() {
fun `when Metadata value contains JSON and is displayable, then keep it in the list`() {
// Given
val rawMetadata = listOf(
WCMetaData(
Expand All @@ -64,15 +64,7 @@ class StripOrderMetaDataTest {
val result = sut(rawMetadata)

// Then
assertThat(result).isEqualTo(
listOf(
WCMetaData(
id = 2L,
key = "valid key",
value = "valid value"
)
)
)
assertThat(result.size).isEqualTo(2)
}

@Test
Expand Down

0 comments on commit 373bc6d

Please sign in to comment.