Add PropTypesEntitiesModel to manipulate collection of entities
authorFrank Bessou <frank.bessou@logilab.fr>
Tue, 04 Apr 2017 15:34:25 +0200
changeset 74 0cd81011cef3
parent 73 a366599c0e9a
child 75 8ef8d6f31fca
Add PropTypesEntitiesModel to manipulate collection of entities
src/components/BaseViews.js
src/components/Entities.js
src/model.js
--- a/src/components/BaseViews.js	Wed Apr 05 15:10:15 2017 +0200
+++ b/src/components/BaseViews.js	Tue Apr 04 15:34:25 2017 +0200
@@ -1,6 +1,6 @@
 import React from 'react';
 import {Link} from 'react-router';
-import {PropTypeAction, PropTypesEntityModel} from '../model';
+import {PropTypeAction, PropTypesEntityModel, PropTypesEntitiesModel} from '../model';
 
 export function OneLineView({entity}) {
     return (
@@ -22,7 +22,7 @@
     return (
         <ul className="list-group">
             {
-                props.entities.map(
+                props.entities.data.value().map(
                     entity => (
                         <li className="list-group-item" key={entity.id}>
                             <OneLineView entity={entity} />
@@ -35,11 +35,7 @@
 }
 
 ListView.propTypes = {
-    entities: React.PropTypes.arrayOf(
-        React.PropTypes.shape({
-            id: React.PropTypes.string.isRequired,
-        })
-    ).isRequired,
+    entities: PropTypesEntitiesModel.isRequired,
 };
 
 export function ActionLink({target, action}) {
--- a/src/components/Entities.js	Wed Apr 05 15:10:15 2017 +0200
+++ b/src/components/Entities.js	Tue Apr 04 15:34:25 2017 +0200
@@ -2,6 +2,7 @@
 import {isEmpty} from 'lodash/lang';
 import {ListView} from './BaseViews';
 import Api from '../Api';
+import {PropTypesEntitiesModel} from '../model';
 
 export default class Entities extends React.Component {
 
@@ -13,7 +14,7 @@
     componentDidMount() {
         const {etype} = this.props.params;
         Api.getEntities(etype)
-            .then(entities => this.setState({entities: entities.data.value()}));
+            .then(entities => this.setState({entities: entities}));
     }
 
     render() {
@@ -43,11 +44,5 @@
 
 EntitiesView.propTypes = {
     etype: React.PropTypes.string.isRequired,
-    entities: React.PropTypes.arrayOf(
-        React.PropTypes.shape({
-            // XXX JSON Schema of collection item
-            id: React.PropTypes.string.isRequired,
-            title: React.PropTypes.string.isRequired,
-        })
-    ).isRequired,
+    entities: PropTypesEntitiesModel.isRequired,
 };
--- a/src/model.js	Wed Apr 05 15:10:15 2017 +0200
+++ b/src/model.js	Tue Apr 04 15:34:25 2017 +0200
@@ -17,3 +17,11 @@
     data: PropTypeJsonaryWrapper.isRequired,
     allowedActions: React.PropTypes.arrayOf(PropTypeAction).isRequired,
 });
+
+export const PropTypesEntitiesModel = React.PropTypes.shape({
+    url: React.PropTypes.string.isRequired,
+    route: React.PropTypes.string.isRequired,
+    etype: React.PropTypes.string.isRequired,
+    data: PropTypeJsonaryWrapper.isRequired,
+    allowedActions: React.PropTypes.arrayOf(PropTypeAction).isRequired,
+});