Add ArrayItemValue component
authorFrank Bessou <frank.bessou@logilab.fr>
Wed, 26 Apr 2017 11:00:22 +0200
changeset 135 3f7a3d0d3730
parent 134 7c7bbeecbff4
child 136 7961cd55e99b
Add ArrayItemValue component This component displays the title of the item's schema when it exists, otherwise it displays the item's value using the AttributeValue component.
src/components/Attribute.js
--- a/src/components/Attribute.js	Fri Apr 21 17:30:59 2017 +0200
+++ b/src/components/Attribute.js	Wed Apr 26 11:00:22 2017 +0200
@@ -24,9 +24,18 @@
 
 function ArrayValue({attribute}) {
     let attributeValue =  attribute.mapItems( (item) => {
-        return (<AttributeValue attribute={item} key={item.uniqueId} />);
+        return (<ArrayItemValue attribute={item} key={item.uniqueId} />);
     });
     attributeValue = intersperse(attributeValue, ', ')
     return <span>{attributeValue}</span>
 }
 ArrayValue.propTypes = ATTRIBUTE_VALUE_PROPTYPES;
+
+function ArrayItemValue({attribute}) {
+    if (attribute.schemas().title !== undefined) {
+        return <span>{attribute.schemas().title()}</span>;
+    } else {
+        return <AttributeValue attribute={attribute}/>
+    }
+}
+ArrayItemValue.propTypes = ATTRIBUTE_VALUE_PROPTYPES;