From 3f51d99dc12c1a8780656a906d355a3f25d9a18d Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Sat, 13 Aug 2016 09:51:16 -0400 Subject: [PATCH] testing relationship between components --- src/edit.js | 13 +++++++++---- src/providers.js | 24 ++++++++++++++++++++++++ src/routes.js | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/edit.js b/src/edit.js index 7455f45..9f53e0d 100644 --- a/src/edit.js +++ b/src/edit.js @@ -17,8 +17,14 @@ export default function (compDef) { const listFields = [] for (let fieldName of fieldNames) { + if (fields[fieldName].type && fields[fieldName].type === 'oneToMany') { + console.log('oneToMany', fields[fieldName].component, fields[fieldName].remoteField) + } + if (fields[fieldName].type && fields[fieldName].type === 'manyToOne') { + console.log('manyToOne', fields[fieldName].component, fields[fieldName].remoteField) + } let label = fields[fieldName].label - if (!label || label === '') { + if (!label || label === '') { label = fieldName } const componentField = compDef.fields[fieldName] @@ -28,7 +34,7 @@ export default function (compDef) { error = {next[fieldError]} } const field =
- { @@ -36,10 +42,9 @@ export default function (compDef) { save() }}/> {error} -
+ listFields.push(field) } - return (
diff --git a/src/providers.js b/src/providers.js index 8176554..8cacff9 100644 --- a/src/providers.js +++ b/src/providers.js @@ -8,6 +8,7 @@ export default function (compDef) { const listCapitalName = listName.toUpperCase() const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) const componentCapitalName = componentName.toUpperCase() + const routesName = componentName + 'Routes' const crudInit = {} const crudErrorInit = {} @@ -24,6 +25,8 @@ export default function (compDef) { const LOAD = `LOAD_${listCapitalName}` const STORE = `STORE_${componentCapitalName}` const DELETE = `DELETE_${componentCapitalName}` + const SET_ROUTE = `SET_ROUTE_${componentCapitalName}` + const DELETE_ROUTE = `DELETE_ROUTE_${componentCapitalName}` const actions = {} const reducers = {} @@ -46,6 +49,27 @@ export default function (compDef) { actions[`delete${componentProperName}`] = (component) =>{ return {type: DELETE, component} } + actions[`setRoute${componentProperName}`] = (routeDef) =>{ + return {type: SET_ROUTE, ...routeDef} + } + actions[`deleteRoute${componentProperName}`] = (routeDef) =>{ + return {type: DELETE_ROUTE, ...routeDef} + } + reducers[routesName] = (state = {}, action) =>{ + switch (action.type) { + case SET_ROUTE: { + const {name, path} = action + return Object.assign({}, state, {name, path}) + } + case DELETE_ROUTE: { + const {name} = action + const next = Object.assign({}, state) + delete next[name] + return next + } + default : return state + } + } reducers[componentName] = (state = {isValid: false}, action) =>{ switch (action.type) { diff --git a/src/routes.js b/src/routes.js index 9086a1c..a136c39 100644 --- a/src/routes.js +++ b/src/routes.js @@ -3,7 +3,7 @@ import React from 'react' export default function (compDef, components) { const mainPath = compDef.componentName - const componentProperName = compDef.componentName[0].toUpperCase()+ + const componentProperName = compDef.componentName[0].toUpperCase() + compDef.componentName.substring(1) const edit = 'edit' + componentProperName const list = 'list' + componentProperName