-
Notifications
You must be signed in to change notification settings - Fork 135
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
[Custom Fields] Read-only mode for JSON values #12708
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
val jsonFormatted = remember(customField.value) { | ||
runCatching { | ||
if (customField.value.trimStart().startsWith("[")) { | ||
JSONArray(customField.value).toString(4) | ||
} else { | ||
JSONObject(customField.value).toString(4) | ||
} | ||
}.getOrDefault(customField.value) | ||
} | ||
|
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.
I didn't add this formatting logic to the ViewModel because it's UI only, and uses an Android specific class org.json.*
, let me know if you have some concerns with this approach.
OutlinedTextField( | ||
value = customField.key, | ||
onValueChange = {}, | ||
label = { Text(text = stringResource(id = R.string.custom_fields_editor_key_label)) }, | ||
readOnly = true, | ||
modifier = Modifier | ||
) |
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.
I used read-only text fields for displaying the custom field's content because it has built-in support for selection and allowing copy/paste.
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.
Good call! Just a minor nitpick. From a UX point of view, having the edit text fields focusable (highlighted with the purple border) when they are not editable seems confusing.
I was wondering if we should use enabled = false
instead of readOnly = true
. This still allows for copy pasting (although usability is worse for selecting the text), but makes it way more apparent that the content is not editable.
Wdyt?
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.
Good point here @JorgeMucientes, I made some updates to disable the focus of the fields, I didn't use enabled = false
reduced the experience a lot, please check the commit dbcf0be and let me know what you think.
With this commit, and the other UI updates suggested below, the result looks like this now:
Screen_recording_20241001_130945.mp4
1c7051e
to
b585623
Compare
Project dependencies changesThe following changes in project dependencies were detected (configuration list
tree-+--- org.wordpress:fluxc:trunk-06e2a179771b9d8c726a15843d56fc897b6d5ca0
-| +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.25
-| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
-| | \--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.25
-| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
-| +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.6
-| | \--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
-| +--- androidx.security:security-crypto:1.0.0 -> 1.1.0-alpha03
-| | +--- androidx.annotation:annotation:1.1.0 -> 1.8.0 (*)
-| | +--- com.google.crypto.tink:tink-android:1.5.0
-| | \--- androidx.collection:collection:1.1.0 -> 1.4.0 (*)
-| +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0
-| | +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
-| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.9.10 (*)
-| +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
-| +--- org.apache.commons:commons-text:1.10.0 (*)
-| +--- androidx.room:room-runtime:2.6.1 (*)
-| +--- androidx.room:room-ktx:2.6.1
-| | +--- androidx.room:room-common:2.6.1 (*)
-| | +--- androidx.room:room-runtime:2.6.1 (*)
-| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 1.9.25 (*)
-| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1 -> 1.8.1 (*)
-| | +--- androidx.room:room-common:2.6.1 (c)
-| | \--- androidx.room:room-runtime:2.6.1 (c)
-| +--- com.google.dagger:dagger:2.51.1
-| | \--- javax.inject:javax.inject:1
-| +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
-| +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
-| +--- org.wordpress:wellsql:2.0.0
-| | +--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
-| | \--- org.wordpress.wellsql:wellsql-annotations:2.0.0
-| +--- org.wordpress.fluxc:fluxc-annotations:trunk-06e2a179771b9d8c726a15843d56fc897b6d5ca0
-| +--- org.greenrobot:eventbus:3.3.1 (*)
-| +--- org.greenrobot:eventbus-java:3.3.1
-| +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
-| +--- com.android.volley:volley:1.1.1 -> 1.2.0
-| +--- androidx.paging:paging-runtime:2.1.2
-| | +--- androidx.paging:paging-common:2.1.2
-| | | +--- androidx.annotation:annotation:1.0.0 -> 1.8.0 (*)
-| | | \--- androidx.arch.core:core-common:2.0.0 -> 2.2.0 (*)
-| | +--- androidx.arch.core:core-runtime:2.0.0 -> 2.2.0 (*)
-| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.7.0 (*)
-| | +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.7.0 (*)
-| | \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.3.2 (*)
-| +--- com.goterl:lazysodium-android:5.0.2
-| +--- net.java.dev.jna:jna:5.5.0
-| \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
++--- org.wordpress:fluxc:trunk-373bc6d30f8d9da6b7750f3ddc38929611b50056
+| +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.25
+| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
+| | \--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.25
+| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
+| +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.6
+| | \--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
+| +--- androidx.security:security-crypto:1.0.0 -> 1.1.0-alpha03
+| | +--- androidx.annotation:annotation:1.1.0 -> 1.8.0 (*)
+| | +--- com.google.crypto.tink:tink-android:1.5.0
+| | \--- androidx.collection:collection:1.1.0 -> 1.4.0 (*)
+| +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0
+| | +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
+| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.9.10 (*)
+| +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
+| +--- org.apache.commons:commons-text:1.10.0 (*)
+| +--- androidx.room:room-runtime:2.6.1 (*)
+| +--- androidx.room:room-ktx:2.6.1
+| | +--- androidx.room:room-common:2.6.1 (*)
+| | +--- androidx.room:room-runtime:2.6.1 (*)
+| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 1.9.25 (*)
+| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1 -> 1.8.1 (*)
+| | +--- androidx.room:room-common:2.6.1 (c)
+| | \--- androidx.room:room-runtime:2.6.1 (c)
+| +--- com.google.dagger:dagger:2.51.1
+| | \--- javax.inject:javax.inject:1
+| +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
+| +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
+| +--- org.wordpress:wellsql:2.0.0
+| | +--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
+| | \--- org.wordpress.wellsql:wellsql-annotations:2.0.0
+| +--- org.wordpress.fluxc:fluxc-annotations:trunk-373bc6d30f8d9da6b7750f3ddc38929611b50056
+| +--- org.greenrobot:eventbus:3.3.1 (*)
+| +--- org.greenrobot:eventbus-java:3.3.1
+| +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
+| +--- com.android.volley:volley:1.1.1 -> 1.2.0
+| +--- androidx.paging:paging-runtime:2.1.2
+| | +--- androidx.paging:paging-common:2.1.2
+| | | +--- androidx.annotation:annotation:1.0.0 -> 1.8.0 (*)
+| | | \--- androidx.arch.core:core-common:2.0.0 -> 2.2.0 (*)
+| | +--- androidx.arch.core:core-runtime:2.0.0 -> 2.2.0 (*)
+| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.7.0 (*)
+| | +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.7.0 (*)
+| | \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.3.2 (*)
+| +--- com.goterl:lazysodium-android:5.0.2
+| +--- net.java.dev.jna:jna:5.5.0
+| \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
-\--- org.wordpress.fluxc.plugins:woocommerce:trunk-06e2a179771b9d8c726a15843d56fc897b6d5ca0
- +--- org.wordpress:fluxc:trunk-06e2a179771b9d8c726a15843d56fc897b6d5ca0 (*)
- +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
- +--- com.google.dagger:dagger:2.51.1 (*)
- +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
- +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
- +--- androidx.room:room-runtime:2.6.1 (*)
- +--- org.wordpress:wellsql:2.0.0 (*)
- +--- org.wordpress.fluxc:fluxc-annotations:trunk-06e2a179771b9d8c726a15843d56fc897b6d5ca0
- +--- androidx.room:room-ktx:2.6.1 (*)
- \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
+\--- org.wordpress.fluxc.plugins:woocommerce:trunk-373bc6d30f8d9da6b7750f3ddc38929611b50056
+ +--- org.wordpress:fluxc:trunk-373bc6d30f8d9da6b7750f3ddc38929611b50056 (*)
+ +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
+ +--- com.google.dagger:dagger:2.51.1 (*)
+ +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
+ +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
+ +--- androidx.room:room-runtime:2.6.1 (*)
+ +--- org.wordpress:wellsql:2.0.0 (*)
+ +--- org.wordpress.fluxc:fluxc-annotations:trunk-373bc6d30f8d9da6b7750f3ddc38929611b50056
+ +--- androidx.room:room-ktx:2.6.1 (*)
+ \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*) |
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.
Nice work @hichamboushaba looks good and works well!
I just left a minor suggestion. Let me know what you think about it.
OutlinedTextField( | ||
value = customField.key, | ||
onValueChange = {}, | ||
label = { Text(text = stringResource(id = R.string.custom_fields_editor_key_label)) }, | ||
readOnly = true, | ||
modifier = Modifier | ||
) |
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.
Good call! Just a minor nitpick. From a UX point of view, having the edit text fields focusable (highlighted with the purple border) when they are not editable seems confusing.
I was wondering if we should use enabled = false
instead of readOnly = true
. This still allows for copy pasting (although usability is worse for selecting the text), but makes it way more apparent that the content is not editable.
Wdyt?
That's great, thanks so much @hichamboushaba! In terms of UX it'd be nice if the data could be 'transformed' into regular text, e.g. Json_object
|
Thanks @keunes for the suggestion, but sadly it won't be as simple as this, as the JSON could have multiple nested levels for the fields, for example:
I'm sorry, but displaying the information as a list won't work in this case because we need to maintain the nesting level for the JSON values. We'll have to continue showing the JSON as raw text for now.
I don't think these points are related, Jorge's concern above is just about the "focus" indicator, when the fields are selected, they will be focused and be shown with a purple Color, and this could be confusing given the fields are not editable, I'll adjust this to remove this part later.
Thanks for bringing this up, I'll see what I can do for this. |
// We use this to disable focus on the text fields used to show the key and value as it's not needed for our case | ||
val inactiveInteractionSource = remember { | ||
object : MutableInteractionSource { | ||
override val interactions: Flow<Interaction> = emptyFlow() | ||
override suspend fun emit(interaction: Interaction) {} | ||
override fun tryEmit(interaction: Interaction): Boolean = false | ||
} | ||
} |
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.
Nice! :TIL
# Conflicts: # build.gradle
89541d1
to
5b2cae4
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #12708 +/- ##
============================================
+ Coverage 40.66% 40.69% +0.02%
- Complexity 5727 5730 +3
============================================
Files 1232 1232
Lines 69408 69445 +37
Branches 9621 9630 +9
============================================
+ Hits 28228 28260 +32
+ Misses 38578 38577 -1
- Partials 2602 2608 +6 ☔ View full report in Codecov by Sentry. |
Closes: #12699
Description
This PR adds support for displaying JSON values in read-only mode, it depends on the FluxC work done in wordpress-mobile/WordPress-FluxC-Android#3102
Steps to reproduce
Testing information
The tests that have been performed
Images/gif
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: