|
@@ -41,8 +41,15 @@ const keyValPairToMetaRecursive = ( [key, val] ) => {
|
|
|
const metaVal = keyValPairToMeta(innerVal, key);
|
|
|
return [key, metaVal];
|
|
|
};
|
|
|
-const arrayMemberAutoName = val => isScalar(val) ? val : val.__typename || val.constructor.name;
|
|
|
-const arrayToMeta = array => array.map(val => ({ name: arrayMemberAutoName(val), 'value' : val }));
|
|
|
+
|
|
|
+// Here, if array member is an object, generate autoMeta for the object members
|
|
|
+
|
|
|
+const arrayMemberAutoName = (val, i) => {
|
|
|
+ isScalar(val) ? val : val.__typename || val.constructor.name;
|
|
|
+}
|
|
|
+const arrayToMeta = array => array.map((val, i) => {
|
|
|
+ return { name: arrayMemberAutoName(val, i), 'value' : val };
|
|
|
+});
|
|
|
|
|
|
const autoMeta = model => Object.entries(model)
|
|
|
.filter(kvPair => kvPair[0] !== '__')
|
|
@@ -70,50 +77,45 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
|
const metaFoG = metaG[key] || {};
|
|
|
const seed = isCon ? {} : containerSeed; // Container's don't seed themselves, only their children
|
|
|
|
|
|
- // ---------------------------------------
|
|
|
|
|
|
// OK, so we need to... expand repeating containers here
|
|
|
if (isRepeating) {
|
|
|
- const repeatInAutoMeta = Array.isArray(metaG[key].meta) ? metaG[key].meta.length : 0;
|
|
|
+
|
|
|
+ const repeatInAutoMeta = Array.isArray(metaFoG.meta) ? metaFoG.meta.length : 0;
|
|
|
const repeatInExtraMeta = val['initialRepeat'] || val['minRepeat'];
|
|
|
const repeat = Math.max(repeatInAutoMeta, repeatInExtraMeta);
|
|
|
+ console.log('repeat is', repeat);
|
|
|
|
|
|
- // Extend array from model (if any) to length repeat, apdding with empty values
|
|
|
+ // Extend array from model (if any) to length repeat, adding with empty values
|
|
|
const repeatingGroup = repeatInAutoMeta ?
|
|
|
- [ ...metaG[key].meta, ...Array(repeat - repeatInAutoMeta).fill(metaG[key].meta[0]) ] // RETHING DEFAULT HERE - its first val from data repeated
|
|
|
+ [ ...metaFoG.meta, ...Array(repeat - repeatInAutoMeta).fill(metaFoG.meta[0]) ] // RETHING DEFAULT HERE - its first val from data repeated
|
|
|
:
|
|
|
- arrayMemberAutoName(repeat).fill(val['meta'][0]);
|
|
|
-
|
|
|
- if (Array.isArray(metaG[key])) {
|
|
|
- combinedMeta[key] = combineExtraMeta(metaG[key], val['meta'][0], createFromExtra, val['seed']);
|
|
|
- }
|
|
|
-
|
|
|
+ Array(repeat).fill({});
|
|
|
+ console.log('repeatingGroup is', repeatingGroup);
|
|
|
|
|
|
+ combinedMeta[key] = repeatingGroup.map(metaG => combineExtraMeta(metaG, val['meta'][0], createFromExtra, val['seed']));
|
|
|
+ console.log('combinedMeta is', combinedMeta[key]);
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+
|
|
|
+ {
|
|
|
+ const extra = isCon ?
|
|
|
+ {
|
|
|
+ ...val,
|
|
|
+ meta: combineExtraMeta( // RECURSION
|
|
|
+ metaFoG.meta || {},
|
|
|
+ val['meta'],
|
|
|
+ createFromExtra,
|
|
|
+ val['seed'] || containerSeed // Inherit seeded data if this group's seed isn't set
|
|
|
+ )
|
|
|
+ }
|
|
|
+ :
|
|
|
+ val;
|
|
|
+ combinedMeta[key] = combineMetaForField(metaFoG, seed, extra);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // ---------------------------------------
|
|
|
- // Maybe else?
|
|
|
|
|
|
- const extra = isCon ?
|
|
|
- {
|
|
|
- ...val,
|
|
|
- meta: combineExtraMeta( // RECURSION
|
|
|
- metaFoG.meta || {},
|
|
|
- val['meta'],
|
|
|
- createFromExtra,
|
|
|
- val['seed'] || containerSeed // Inherit seeded data if this group's seed isn't set
|
|
|
- )
|
|
|
- }
|
|
|
- :
|
|
|
- val;
|
|
|
- combinedMeta[key] = combineMetaForField(metaFoG, seed, extra);
|
|
|
}
|
|
|
});
|
|
|
return { ...metaG, ...combinedMeta };
|