Remove Enumeration type

Summary:
Enumeration used to be a type containing a single property value of type string.

The InspectableEnum is a type that had an Enumeration value and possible values.

As we removed possible values from the enum value, this structure no longer serves its purpose.

Reviewed By: antonk52

Differential Revision: D41400874

fbshipit-source-id: e5c2d1e15ee9b3074ddd69f75ee9b8150d44379f
This commit is contained in:
Lorenzo Blasa
2022-11-21 05:30:18 -08:00
committed by Facebook GitHub Bot
parent 5e200dd7ec
commit 5b3e110821
9 changed files with 16 additions and 25 deletions

View File

@@ -137,8 +137,7 @@ object ComponentPropExtractor {
return InspectableArray(0, values ?: listOf())
}
override fun isPick(pick: EditorPick?): Inspectable =
InspectableValue.Enum(Enumeration(pick?.selected))
override fun isPick(pick: EditorPick): Inspectable = InspectableValue.Enum(pick.selected)
override fun isNumber(number: EditorNumber): Inspectable =
InspectableValue.Number(number.value)
@@ -146,8 +145,8 @@ object ComponentPropExtractor {
override fun isColor(number: EditorColor): Inspectable =
InspectableValue.Color(number.value.toInt().let { Color.fromColor(it) })
override fun isString(string: EditorString?): Inspectable =
InspectableValue.Text(string?.value ?: "")
override fun isString(string: EditorString): Inspectable =
InspectableValue.Text(string.value ?: "")
override fun isBool(bool: EditorBool): Inspectable = InspectableValue.Boolean(bool.value)
})

View File

@@ -324,26 +324,26 @@ object LayoutPropExtractor {
val layout = component.layoutNode ?: return props
props[AlignItemsId] = InspectableValue.Enum(Enumeration(layout.alignItems.name))
props[AlignSelfId] = InspectableValue.Enum(Enumeration(layout.alignSelf.name))
props[AlignContentId] = InspectableValue.Enum(Enumeration(layout.alignContent.name))
props[AlignItemsId] = InspectableValue.Enum(layout.alignItems.name)
props[AlignSelfId] = InspectableValue.Enum(layout.alignSelf.name)
props[AlignContentId] = InspectableValue.Enum(layout.alignContent.name)
props[AspectRatioId] = InspectableValue.Text(layout.aspectRatio.toString())
layout.background?.let { drawable -> props[BackgroundId] = fromDrawable(drawable) }
props[DirectionId] = InspectableValue.Enum(Enumeration(layout.layoutDirection.name))
props[DirectionId] = InspectableValue.Enum(layout.layoutDirection.name)
props[FlexBasisId] = InspectableValue.Text(layout.flexBasis.toString())
props[FlexDirectionId] = InspectableValue.Enum(Enumeration(layout.flexDirection.name))
props[FlexDirectionId] = InspectableValue.Enum(layout.flexDirection.name)
props[FlexGrowId] = InspectableValue.Text(layout.flexGrow.toString())
props[FlexShrinkId] = InspectableValue.Text(layout.flexShrink.toString())
layout.foreground?.let { drawable -> props[ForegroundId] = fromDrawable(drawable) }
props[JustifyContentId] = InspectableValue.Enum(Enumeration(layout.justifyContent.name))
props[JustifyContentId] = InspectableValue.Enum(layout.justifyContent.name)
props[PositionTypeId] = InspectableValue.Enum(Enumeration(layout.positionType.name))
props[PositionTypeId] = InspectableValue.Enum(layout.positionType.name)
val size: MutableMap<MetadataId, Inspectable> = mutableMapOf()
size[WidthId] = InspectableValue.Text(layout.width.toString())

View File

@@ -9,7 +9,6 @@ package com.facebook.flipper.plugins.uidebugger.common
import android.util.Log
import com.facebook.flipper.plugins.uidebugger.LogTag
import com.facebook.flipper.plugins.uidebugger.model.Enumeration
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
// Maintains 2 way mapping between some enum value and a readable string representation
@@ -40,7 +39,7 @@ open class EnumMapping<T>(private val mapping: Map<String, T>) {
}
fun toInspectable(value: T): InspectableValue.Enum {
return InspectableValue.Enum(Enumeration(getStringRepresentation(value)))
return InspectableValue.Enum(getStringRepresentation(value))
}
companion object {
const val NoMapping = "__UNKNOWN_ENUM_VALUE__"

View File

@@ -85,9 +85,7 @@ sealed class InspectableValue : Inspectable() {
@SerialName("enum")
@kotlinx.serialization.Serializable
data class Enum(
val value: com.facebook.flipper.plugins.uidebugger.model.Enumeration,
) : InspectableValue()
data class Enum(val value: String) : InspectableValue()
@SerialName("unknown")
@kotlinx.serialization.Serializable

View File

@@ -62,5 +62,3 @@ data class Size(
@Serializable(with = NumberSerializer::class) val width: Number,
@Serializable(with = NumberSerializer::class) val height: Number
) {}
@kotlinx.serialization.Serializable data class Enumeration(val value: String?)

View File

@@ -9,7 +9,6 @@ package com.facebook.flipper.plugins.uidebugger
import android.view.View
import com.facebook.flipper.plugins.uidebugger.common.EnumMapping
import com.facebook.flipper.plugins.uidebugger.model.Enumeration
import com.facebook.flipper.plugins.uidebugger.model.InspectableValue
import org.hamcrest.CoreMatchers.*
import org.hamcrest.MatcherAssert.assertThat
@@ -38,7 +37,6 @@ class EnumMappingTest {
@Test
fun testTurnsIntoEnumInspectable() {
assertThat(
visibility.toInspectable(View.GONE), equalTo(InspectableValue.Enum(Enumeration("GONE"))))
assertThat(visibility.toInspectable(View.GONE), equalTo(InspectableValue.Enum("GONE")))
}
}

View File

@@ -102,7 +102,7 @@ function create(
case 'enum':
return (
<NamedAttributeInspector name={displayableName(name)}>
<EnumValue>{inspectable.value.value}</EnumValue>
<EnumValue>{inspectable.value}</EnumValue>
</NamedAttributeInspector>
);
case 'text':

View File

@@ -22,10 +22,9 @@ function transformAny(
case 'bounds':
case 'coordinate':
case 'coordinate3d':
case 'enum':
case 'space':
return inspectable.value;
case 'enum':
return inspectable.value.value;
case 'object':
return transformObject(metadata, inspectable);
default:

View File

@@ -155,7 +155,7 @@ export type InspectableBoolean = {
export type InspectableEnum = {
type: 'enum';
value: {value: string; values: string[]};
value: string;
};
export type InspectableColor = {