Promote k state to top level
Summary: In the new sidebar design complex types are behind a preview. before states was an array under the key states. Now we create a top level attribute according to its index Reviewed By: lblasa Differential Revision: D50654698 fbshipit-source-id: 410c50c5f1ab14efc77184a5b147d9bdf70761d4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f3449a5641
commit
92e831cc40
@@ -99,7 +99,19 @@ object ComponentDataExtractor {
|
|||||||
val id = getMetadataId(componentName, field.name)
|
val id = getMetadataId(componentName, field.name)
|
||||||
val editorValue: EditorValue? = EditorRegistry.read(field.type, field, stateContainer)
|
val editorValue: EditorValue? = EditorRegistry.read(field.type, field, stateContainer)
|
||||||
if (editorValue != null) {
|
if (editorValue != null) {
|
||||||
stateFields[id] = toInspectable(field.name, editorValue)
|
|
||||||
|
val inspectable = toInspectable(field.name, editorValue)
|
||||||
|
|
||||||
|
if (inspectable is InspectableArray) {
|
||||||
|
inspectable.items.forEachIndexed { idx, item ->
|
||||||
|
val metadataId =
|
||||||
|
MetadataRegister.register(
|
||||||
|
MetadataRegister.TYPE_ATTRIBUTE, "kstate", idx.toString())
|
||||||
|
stateFields[metadataId] = item
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stateFields[id] = toInspectable(field.name, editorValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.facebook.flipper.plugins.uidebugger.descriptors.MetadataRegister
|
||||||
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentDataExtractor
|
import com.facebook.flipper.plugins.uidebugger.litho.descriptors.props.ComponentDataExtractor
|
||||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableArray
|
import com.facebook.flipper.plugins.uidebugger.model.InspectableArray
|
||||||
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
|
import com.facebook.flipper.plugins.uidebugger.model.InspectableObject
|
||||||
@@ -16,16 +17,22 @@ import org.junit.Test
|
|||||||
class KStateContainerExtractionTest {
|
class KStateContainerExtractionTest {
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testCanExtractKState() {
|
fun testCanExtractKStateIntoSeparateAttributesByIndex() {
|
||||||
|
|
||||||
// this test ensures that our reflection based extraction doesn't break if the KState class
|
// this test ensures that our reflection based extraction doesn't break if the KState class
|
||||||
// structure changes
|
// structure changes
|
||||||
val stateContainer = KStateContainer.withNewState(null, "foo")
|
MetadataRegister.reset()
|
||||||
|
val stateContainer =
|
||||||
|
KStateContainer.withNewState(KStateContainer.withNewState(null, "foo"), true)
|
||||||
|
|
||||||
val result = ComponentDataExtractor.getState(stateContainer, "Comp1")
|
val result = ComponentDataExtractor.getState(stateContainer, "Comp1")
|
||||||
|
|
||||||
|
val first = MetadataRegister.get("kstate", "0")?.id ?: -1
|
||||||
|
val second = MetadataRegister.get("kstate", "1")?.id ?: -2
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
InspectableObject(
|
||||||
|
mapOf(first to InspectableValue.Text("foo"), second to InspectableValue.Boolean(true))),
|
||||||
result,
|
result,
|
||||||
InspectableObject(mapOf(1 to InspectableArray(listOf(InspectableValue.Text("foo"))))))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user