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

Commit

Permalink
store templates in provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanflorentin committed Aug 18, 2016
1 parent 791217e commit 1973c5e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default function (compDef) {

const componentProperName = componentName[0].toUpperCase() + componentName.substring(1)
const fieldNames = Object.keys(fields)
const ComponentEdit = (props) =>{
const ComponentDisplay = (props) =>{
console.log('in display', props)
let next = Object.assign({}, props[componentName])
const url = props.routing.locationBeforeTransitions.pathname
const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit`
Expand Down Expand Up @@ -39,15 +40,15 @@ export default function (compDef) {
)
}

ComponentEdit.propTypes = {
ComponentDisplay.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
ComponentDisplay.propTypes[`${componentName}`] = PropTypes.object
ComponentDisplay.propTypes[`save${componentProperName}`] = PropTypes.func
ComponentDisplay.propTypes[`store${componentProperName}`] = PropTypes.func
return ComponentDisplay
}


14 changes: 9 additions & 5 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default function (compDef) {
if (fields[fieldName].relation) {
const relation = fields[fieldName].relation
propTypes[`${relation}Routes`] = PropTypes.object
//console.log(fieldName, relation)
propTypes[`${relation}Templates`] = PropTypes.object
propTypes[relation] = PropTypes.object
}
})
const ComponentEdit = (props) =>{
Expand All @@ -22,7 +23,6 @@ export default function (compDef) {
const store = () =>{props[`store${componentProperName}`](next)}
const {goBack} = props
const listCaption = `Ingrese datos de ${componentProperName}`
// const listFields = []
const listFields = fieldNames.map((fieldName)=>{
let label = fields[fieldName].label
if (!label || label === '') {
Expand All @@ -36,11 +36,15 @@ export default function (compDef) {
}
if (fields[fieldName].relation) {
const relation = fields[fieldName].relation
console.log('relation:', relation)
const routes = `${relation}Routes`
const listRoute = props[routes][`${relation}List`]
return <div key={fieldName}><Button icon='add' onClick={(e) => {
console.log('go to ', props[routes], props.pushRoute)
const relationDisplay = props[`${relation}Templates`][`${relation}Display`]
console.log('this component was selected', relationDisplay, props[relation])
return <div key={fieldName}>
<relationDisplay props={props[relation]}/>
<label>{relation}</label>

<Button icon='add' onClick={(e) => {
props.pushRoute(listRoute)
}}
/></div>
Expand Down
28 changes: 28 additions & 0 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function (compDef) {
const componentProperName = componentName[0].toUpperCase() + componentName.substring(1)
const componentCapitalName = componentName.toUpperCase()
const routesName = componentName + 'Routes'
const templatesName = componentName + 'Templates'

const crudInit = {}
const crudErrorInit = {}
Expand All @@ -30,6 +31,8 @@ export default function (compDef) {
const DELETE = `DELETE_${componentCapitalName}`
const SET_ROUTE = `SET_ROUTE_${componentCapitalName}`
const DELETE_ROUTE = `DELETE_ROUTE_${componentCapitalName}`
const SET_TEMPLATE = `SET_TEMPLATE_${componentCapitalName}`
const DELETE_TEMPLATE = `DELETE_TEMPLATE_${componentCapitalName}`

const actions = {}
const reducers = {}
Expand Down Expand Up @@ -58,6 +61,13 @@ export default function (compDef) {
actions[`deleteRoute${componentProperName}`] = (routeDef) =>{
return {type: DELETE_ROUTE, ...routeDef}
}
actions[`setTemplate${componentProperName}`] = (templateDef) =>{
return {type: SET_TEMPLATE, ...templateDef}
}
actions[`deleteTemplate${componentProperName}`] = (templateDef) =>{
return {type: DELETE_TEMPLATE, ...templateDef}
}

reducers[routesName] = (state = {}, action) =>{
switch (action.type) {
case SET_ROUTE: {
Expand All @@ -76,6 +86,24 @@ export default function (compDef) {
}
}

reducers[templatesName] = (state = {}, action) =>{
switch (action.type) {
case SET_TEMPLATE: {
const {name, template} = action
let temp = {}
temp[name] = template
return Object.assign({}, state, temp)
}
case DELETE_TEMPLATE: {
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) {
case SELECT: {
Expand Down

0 comments on commit 1973c5e

Please sign in to comment.