Extract AttributeValue component from EntityAttribute
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 21 Apr 2017 17:16:28 +0200
changeset 133 72e439b9b15f
parent 132 2b6ce8199a46
child 134 7c7bbeecbff4
Extract AttributeValue component from EntityAttribute
src/components/Attribute.js
src/components/Entity.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/components/Attribute.js	Fri Apr 21 17:16:28 2017 +0200
@@ -0,0 +1,22 @@
+import React from 'react';
+import {PropTypeJsonaryWrapper} from '../jsonaryutils'
+
+const ATTRIBUTE_VALUE_PROPTYPES = {
+    attribute: PropTypeJsonaryWrapper.isRequired,
+}
+
+export function AttributeValue({attribute}) {
+    const value = attribute.value();
+    let attrView;
+    if (attribute.defined()) {
+        if (attribute.basicType() === 'array') {
+            attrView = value.join(', ');
+        } else {
+            attrView = value;
+        }
+    } else {
+        attrView = '<unspecified>';
+    }
+    return (<span>{attrView}</span>)
+}
+AttributeValue.propTypes = ATTRIBUTE_VALUE_PROPTYPES;
--- a/src/components/Entity.js	Wed Apr 19 11:50:55 2017 +0200
+++ b/src/components/Entity.js	Fri Apr 21 17:16:28 2017 +0200
@@ -12,23 +12,13 @@
 import {buildFormData, appendPath} from '../utils';
 import {ActionsDropDown, CollectionItemLink} from './BaseViews';
 import {WorkflowActions} from './Workflow';
+import {AttributeValue} from './Attribute';
 
 function EntityAttribute({attribute}) {
-    const value = attribute.value();
-    let attrView;
-    if (attribute.defined()) {
-        if (attribute.basicType() === 'array') {
-            attrView = value.join(', ');
-        } else {
-            attrView = value;
-        }
-    } else {
-        attrView = '<unspecified>';
-    }
     return (
         <tr>
             <th>{attribute.schemas().title() || attribute.parentKey()}</th>
-            <td>{attrView}</td>
+            <td><AttributeValue attribute={attribute} /></td>
         </tr>
     );
 }