From e92e1530e0bf9fd268b55e266a31c8ad63248da3 Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Thu, 11 Aug 2016 21:59:41 -0400 Subject: [PATCH] display working as list --- src/display.js | 77 ++++++++++++++++++++++++++++---------------------- src/edit.js | 6 +++- src/list.js | 14 ++++++--- 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/display.js b/src/display.js index 477ca40..934d4f2 100644 --- a/src/display.js +++ b/src/display.js @@ -1,44 +1,53 @@ import React, {PropTypes} from 'react' -import {Button} from 'react-toolbox' -import {Card, CardTitle, CardText, CardActions} from 'react-toolbox/lib/card' +import {List, ListItem, ListSubHeader, Button} from 'react-toolbox' export default function (compDef) { - const {componentName} = compDef + const {componentName, + fields + } = compDef - const ComponentDisplay = (props) => { - const {goBack, pushRoute, routing} = props - const url = routing.locationBeforeTransitions.pathname + const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) + const fieldNames = Object.keys(fields) + const ComponentEdit = (props) =>{ + let next = Object.assign({}, props[componentName]) + const url = props.routing.locationBeforeTransitions.pathname const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit` - const component = props[`${componentName}`] - let content = [] - let cardActions =
-
- if (component.index !== undefined) { - for (let field of component) { - if (component[field] && compDef[field]) { - content.push(

{compDef[field].label} : {component[field]}

) - } - } + const {goBack} = props + const listCaption = `Datos de ${componentProperName}` + const listFields = [] + + for (let fieldName of fieldNames) { + const componentField = compDef.fields[fieldName] + const field =
+ +
+ listFields.push(field) } - return - - {content} - {cardActions} - + return ( +
+ + + {listFields} + +
+ ) } - ComponentDisplay.propTypes = {} - ComponentDisplay.propTypes[`${componentName}`] = PropTypes.object - ComponentDisplay.propTypes.goBack = PropTypes.func - ComponentDisplay.propTypes.pushRoute = PropTypes.func - ComponentDisplay.propTypes.routing = PropTypes.object - - return ComponentDisplay + ComponentEdit.propTypes = { + pushRoute: PropTypes.func, + goBack: PropTypes.func, + routing: PropTypes.object + } + ComponentEdit.propTypes[`${componentName}`] = PropTypes.object + ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func + ComponentEdit.propTypes[`store${componentProperName}`] = PropTypes.func + return ComponentEdit } + + diff --git a/src/edit.js b/src/edit.js index d8814d1..7455f45 100644 --- a/src/edit.js +++ b/src/edit.js @@ -17,6 +17,10 @@ export default function (compDef) { const listFields = [] for (let fieldName of fieldNames) { + let label = fields[fieldName].label + if (!label || label === '') { + label = fieldName + } const componentField = compDef.fields[fieldName] const fieldError = `${fieldName}Error` let error = '' @@ -25,7 +29,7 @@ export default function (compDef) { } const field =
{ next[fieldName] = e diff --git a/src/list.js b/src/list.js index 0c70f72..5937e5b 100644 --- a/src/list.js +++ b/src/list.js @@ -15,16 +15,22 @@ export default function (compDef) { const Items = list.map((item, index) =>{ let itemLegend = '' for (let field in fields) { + let label = fields[field].label + if (!label || label === '') { + label = field + } if (item[field] && item[field] !== '') { - itemLegend = itemLegend + ` ${fields[field].label}: ${item[field]}` + itemLegend = itemLegend + ` ${label}: ${item[field]}` } } - return { props[`select${componentProperName}`](props[listName][index]) - props.pushRoute(editURL) + props.pushRoute(displayURL) } - }/> + }> + this is a child + }) return