From c47a27b826f7d76410308a4151611a366f9eaf46 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 25 Aug 2017 17:48:12 +0200 Subject: Fetch and display datacenter topology --- src/store/denormalizer.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/store/denormalizer.js') diff --git a/src/store/denormalizer.js b/src/store/denormalizer.js index fbf15430..e6583ae7 100644 --- a/src/store/denormalizer.js +++ b/src/store/denormalizer.js @@ -1,14 +1,28 @@ +const EXCLUDED_IDENTIFIERS = [ + "objectId", + "googleId", +]; + export function denormalize(state, objectType, id) { + return denormalizeWithRecursionCheck(state, objectType, id, undefined); +} + +function denormalizeWithRecursionCheck(state, objectType, id, previousType) { const object = Object.assign({}, state.objects[objectType][id]); for (let prop in object) { - if (!object.hasOwnProperty(prop)) { + if (prop.indexOf(previousType) !== -1) { continue; } - if (prop.endsWith("Id")) { + if (prop.endsWith("Id") && EXCLUDED_IDENTIFIERS.indexOf(prop) === -1) { const propType = prop.replace("Id", ""); - object[propType] = state.objects[propType][object[prop]]; + object[propType] = denormalizeWithRecursionCheck(state, propType, object[prop], objectType); + } + + if (prop.endsWith("Ids")) { + const propType = prop.replace("Ids", ""); + object[propType + "s"] = object[prop].map(id => denormalizeWithRecursionCheck(state, propType, id, objectType)); } } -- cgit v1.2.3