Add and use ResourceIdentifier when schema contains oneOf/anyOf
authorFrank Bessou <frank.bessou@logilab.fr>
Mon, 15 May 2017 15:36:06 +0200
changeset 206 2cf5245ab86d
parent 205 9edd745e2e16
child 207 f2b81d05b3cb
Add and use ResourceIdentifier when schema contains oneOf/anyOf It is displayed when the attribute's schema contains a oneOf/anyOf schema.
src/components/Attribute.js
--- a/src/components/Attribute.js	Mon May 15 15:08:37 2017 +0200
+++ b/src/components/Attribute.js	Mon May 15 15:36:06 2017 +0200
@@ -10,7 +10,9 @@
     const value = attribute.value();
     let attrView;
     if (attribute.defined()) {
-        if (attribute.basicType() === 'array') {
+        if (isResourceIdentifier(attribute)) {
+            return <ResourceIdentifier attribute={attribute} />;
+        } else if (attribute.basicType() === 'array') {
             attrView = (<ArrayValue attribute={attribute} />);
         } else {
             attrView = value;
@@ -28,22 +30,13 @@
         return <ObjectTable objectArray={attribute} />;
     }
     let attributeValue = attribute.mapItems( (item) => {
-        return (<ArrayItemValue attribute={item} key={item.uniqueId} />);
+        return (<AttributeValue 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;
-
 function ObjectTable({objectArray}) {
     return (
         <table className="table table-bordered">
@@ -100,6 +93,18 @@
     object: PropTypeJsonaryWrapper.isRequired,
 };
 
+function ResourceIdentifier({attribute}) {
+    return <span>{attribute.schemas().title()}</span>;
+}
+ResourceIdentifier.propTypes = ATTRIBUTE_VALUE_PROPTYPES;
+
 function objectPropertyTitle(propertySchema) {
     return propertySchema.title() || propertySchema.parentKey;
 }
+
+function isResourceIdentifier(attribute) {
+    const schemas = attribute.schemas();
+    const xorSchemas = schemas.xorSchemas();
+    const orSchemas = schemas.orSchemas();
+    return xorSchemas.length > 0 || orSchemas.length > 0;
+}