Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
testing relationship between components
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanflorentin committed Aug 13, 2016
1 parent e92e153 commit 3f51d99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -28,18 +34,17 @@ export default function (compDef) {
error = <span>{next[fieldError]}</span>
}
const field = <div key={fieldName}>
<Input value={next[fieldName] ||''}
<Input value={next[fieldName] ||''}
type={componentField.uiType} label={label} name='name' icon={componentField.icon}
hint={componentField.hint}
onChange={(e) => {
next[fieldName] = e
save()
}}/>
{error}
</div>
</div>
listFields.push(field)
}

return (
<div>
<ListSubHeader caption={listCaption}/>
Expand Down
24 changes: 24 additions & 0 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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 = {}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f51d99

Please sign in to comment.