Use resource instead of collection props for ResourceCollectionView
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Wed, 07 Jun 2017 14:00:07 +0200
changeset 227 d191f86135c0
parent 226 1e18e08035d3
child 228 9c2cc723db97
Use resource instead of collection props for ResourceCollectionView So ResourceCollectionView can be used with higher-order that require a resource props (eg. withPagination).
src/components/Resource.js
test/index.js
--- a/src/components/Resource.js	Wed Jun 07 14:15:10 2017 +0200
+++ b/src/components/Resource.js	Wed Jun 07 14:00:07 2017 +0200
@@ -117,8 +117,8 @@
 };
 
 export function ResourceCollectionView(props) {
-    if (props.collection.length() > 0) {
-        return <CollectionView collection={props.collection} />;
+    if (props.resource.data.length() > 0) {
+        return <CollectionView collection={props.resource.data} />;
     }
 
     return <div className="text-mutted">
@@ -126,7 +126,7 @@
     </div>;
 }
 ResourceCollectionView.propTypes = {
-    collection: PropTypeJsonaryWrapper.isRequired,
+    resource: PropTypesResourceModel.isRequired,
 };
 
 export function ResourceEntityView({entity}) {
@@ -190,7 +190,7 @@
     function renderData() {
         const isCollection = data.schemas().basicTypes()[0] === 'array';
         if (isCollection) {
-            return <ResourceCollectionView collection={data} />;
+            return <ResourceCollectionView resource={props.resource} />;
         } else {
             return <ResourceEntityView entity={data} />;
         }
--- a/test/index.js	Wed Jun 07 14:15:10 2017 +0200
+++ b/test/index.js	Wed Jun 07 14:00:07 2017 +0200
@@ -815,7 +815,7 @@
             const resource = {data: mapToSchema([], {type: 'array'})};
             const wrapper = shallow(<ResourceView resource={resource}/>);
 
-            const view = <ResourceCollectionView collection={resource.data} />;
+            const view = <ResourceCollectionView resource={resource} />;
             expect(wrapper.contains(view)).to.be.true;
         });
     });