Moved RessourceCollectionView and ResourceEntityView to views folder
authorHugo Delahousse <hugo.delahousse@logilab.fr>
Fri, 16 Jun 2017 10:43:52 +0200
changeset 230 737cba398b88
parent 229 584564700959
child 231 f811f0442a5c
Moved RessourceCollectionView and ResourceEntityView to views folder This change prepares for the introduction of a View Registry
src/components/Resource.js
src/views/Generics.js
test/index.js
--- a/src/components/Resource.js	Wed Jun 14 11:06:21 2017 +0200
+++ b/src/components/Resource.js	Fri Jun 16 10:43:52 2017 +0200
@@ -5,10 +5,11 @@
 import {Link} from 'react-router-dom';
 
 import {buildFormData} from '../utils';
-import {EntityAttributes, EntityForm, EntityMeta, RelatedResources} from './Entity';
+import {EntityForm} from './Entity';
 import {PropTypesResourceModel} from '../model';
-import {PropTypeJsonaryWrapper, mapToSchema} from '../jsonaryutils';
-import {ActionsDropDown, CollectionView, withPagination} from './BaseViews';
+import {mapToSchema} from '../jsonaryutils';
+import {ActionsDropDown, withPagination} from './BaseViews';
+import {ResourceCollectionView, ResourceEntityView} from '../views/Generics.js';
 
 export class ResourceContainer extends React.Component {
     constructor(props) {
@@ -116,41 +117,6 @@
     router: PropTypes.object,
 };
 
-export function ResourceCollectionView(props) {
-    if (props.resource.data.length() > 0) {
-        return <CollectionView collection={props.resource.data} />;
-    }
-
-    return <div className="text-mutted">
-        No entities yet
-    </div>;
-}
-ResourceCollectionView.propTypes = {
-    resource: PropTypesResourceModel.isRequired,
-};
-
-export function ResourceEntityView({entity}) {
-    function renderRelated() {
-        const links = entity.links('related');
-        if (links.length > 0) {
-            return Array.prototype.map.call(links, (link) => {
-                return <ResourceContainer url={link.href} component={RelatedResources} childProps={{title: link.title}} key={link.title} />;
-            });
-        }
-        return null;
-    }
-    return (
-        <div>
-            <EntityAttributes data={entity} />
-            <EntityMeta data={entity} />
-            { renderRelated() }
-        </div>
-    );
-}
-ResourceEntityView.propTypes = {
-    entity: PropTypeJsonaryWrapper.isRequired,
-};
-
 export class ResourceView extends React.Component {
     constructor(props) {
         super(props);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/views/Generics.js	Fri Jun 16 10:43:52 2017 +0200
@@ -0,0 +1,45 @@
+import * as React from 'react';
+import {ResourceContainer} from '../components/Resource';
+import {PropTypeJsonaryWrapper} from '../jsonaryutils';
+import {EntityAttributes,
+    EntityMeta,
+    RelatedResources} from '../components/Entity';
+import {CollectionView} from '../components/BaseViews';
+
+export function ResourceCollectionView({resource}) {
+    if (resource.data.length() > 0) {
+        return <CollectionView collection={resource.data} />;
+    }
+
+    return <div className="text-mutted">
+        No entities yet
+    </div>;
+}
+ResourceCollectionView.propTypes = {
+    resource: PropTypeJsonaryWrapper.isRequired,
+};
+
+export function ResourceEntityView({entity}) {
+    function renderRelated() {
+        const links = entity.links('related');
+        if (links.length > 0) {
+            return Array.prototype.map.call(links, (link) => {
+                return (<ResourceContainer url={link.href}
+                    component={RelatedResources}
+                    childProps={{title: link.title}}
+                    key={link.title} />);
+            });
+        }
+        return null;
+    }
+    return (
+        <div>
+            <EntityAttributes data={entity} />
+            <EntityMeta data={entity} />
+            { renderRelated() }
+        </div>
+    );
+}
+ResourceEntityView.propTypes = {
+    entity: PropTypeJsonaryWrapper.isRequired,
+};
--- a/test/index.js	Wed Jun 14 11:06:21 2017 +0200
+++ b/test/index.js	Fri Jun 16 10:43:52 2017 +0200
@@ -23,10 +23,12 @@
     ResourceEditionForm,
     ResourceView,
     PaginatedResourceView,
+    ResourceDeletionView,
+} from '../src/components/Resource';
+import {
     ResourceCollectionView,
     ResourceEntityView,
-    ResourceDeletionView,
-} from '../src/components/Resource';
+} from '../src/views/Generics';
 import {expect} from 'chai';
 
 chai.use(chaiAsPromised);