From fd11a20fdd138efffc65c3e7b845f2cb49ddadce Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Wed, 24 Aug 2016 12:03:38 -0400 Subject: [PATCH] saving and displaying relations --- src/edit.js | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/edit.js b/src/edit.js index ec73e5e..b885739 100644 --- a/src/edit.js +++ b/src/edit.js @@ -45,43 +45,53 @@ export default function (compDef) { } if (fields[fieldName].relation) { const relation = fields[fieldName].relation - console.log(`selected ${relation}`, props[relation].uuid) + //console.log(`selected ${relation}`, props[relation].uuid) const relationList = props[`${relation}List`] const relationComponentDef = props[`${relation}ComponentDef`] const relationProperName = relation.toUpperCase() + relation.substring(1) const routes = `${relation}Routes` const listRoute = props[routes][`${relation}List`] - console.log(`relation ${relation} is `, next[relation]) - console.log('is selecting?', next[`${relation}Selecting`]) - console.log('relationList', relationList) - console.log('next relationList', next[relation], component[relation]) + //console.log(`relation ${relation} is `, next[relation]) + //console.log('is selecting?', next[`${relation}Selecting`]) + //console.log('relationList', relationList) if (next[relation]===undefined) {next[relation]=[]} if (next[`${relation}Selecting`]) { if (next[relation].indexOf(props[relation].uuid)===-1) { - console.log('new', props[relation].uuid) next[relation].push(props[relation].uuid) } delete next[`${relation}Selecting`] } - //ahora a crear los items para el render - const relListFields = [] -// next[relation].map(relUUID =>{ -// relationList.map(item =>{ -// if (item.uuid===relUUID) { -// let keys = Object.keys(item) -// for (let key of keys) { -// relListFields.push(
{key}: {item[key]}
) -// } -// } -// }) -// }) + const relListFields= relationList.filter(comp =>{ + if (next[relation].indexOf(comp.uuid)) { + return true + } + return false + }).map(comp=>{ + let thisComp = [] + for (let key in comp) { + //console.log(`rendering ${key}`, comp[key]) + thisComp.push(
{key}: {comp[key]}
) + } + return
{thisComp} +
+ }) return
{relListFields} -