From 6385fcf7a26e74eb81e8151a08bad3e94c59ee5e Mon Sep 17 00:00:00 2001 From: Ryan Ashley Date: Thu, 14 Feb 2019 16:07:56 -0500 Subject: [PATCH] fix: Namespaces properties added by CRViz and removes them before export. fixes #238 --- src/domain/dataset.js | 25 +++++++++++-------- src/epics/diff-dataset-epic.js | 10 ++++---- src/epics/search-dataset-epic.js | 4 +-- src/features/dataset-controls/export.js | 16 +++++++++++- .../visualization/d3-viz/append-circles.js | 14 +++++------ .../visualization/d3-viz/setup-tooltip.js | 4 +-- .../visualization/d3-viz/to-hierarchy.js | 9 ++++--- 7 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/domain/dataset.js b/src/domain/dataset.js index 23fa6e8ae..d39eb2a4d 100644 --- a/src/domain/dataset.js +++ b/src/domain/dataset.js @@ -47,16 +47,19 @@ const getHashFields = (allFields, ignoredFields) => { const addHashKey = (keys, obj) => { //console.log("addHashKey keys: %o", keys); const hashKey = keys.reduce( (h, k) => h + path(k.path, obj) + ":", ""); - obj["HASH_KEY"] = hashKey; + obj.CRVIZ["_HASH_KEY"] = hashKey; } const addHashWithoutIgnored = (fields, obj) => { const hash = fields.reduce( (h, f) => h + path(f.path, obj) + "|", ""); - obj["HASH_WITHOUT_IGNORED"] = hash; + obj.CRVIZ["_HASH_WITHOUT_IGNORED"] = hash; } const applyHashes = (dataset, configuration) => { dataset.forEach((i) => { + if(!('CRVIZ' in i)){ + i['CRVIZ'] = {}; + } addHashKey(configuration.keyFields.length > 0 ? configuration.keyFields : configuration.hashFields, i); addHashWithoutIgnored(configuration.hashFields, i); }); @@ -377,23 +380,23 @@ const selectDatasetIntersection = (state, startOwner, endOwner) => { ds = end; } else if(start.length > 0 && end.length > 0) { start.forEach((s) => { - const idx = end.findIndex(e => e.HASH_KEY === s.HASH_KEY); + const idx = end.findIndex(e => e.CRVIZ._HASH_KEY === s.CRVIZ._HASH_KEY); if(idx === -1){ - s.isRemoved = true; + s.CRVIZ._isRemoved = true; } else { - s.isRemoved = false; + s.CRVIZ._isRemoved = false; } - s.isChanged = false; - s.isAdded = false; + s.CRVIZ._isChanged = false; + s.CRVIZ._isAdded = false; ds.push(s); }); end.forEach((e) => { - const idx = ds.findIndex(i => i.HASH_KEY === e.HASH_KEY); + const idx = ds.findIndex(i => i.CRVIZ._HASH_KEY === e.CRVIZ._HASH_KEY); if(idx === -1){ - e.isAdded = true; + e.CRVIZ._isAdded = true; ds.push(e); - } else if(ds[idx].HASH_WITHOUT_IGNORED !== e.HASH_WITHOUT_IGNORED){ - ds[idx].isChanged = true; + } else if(ds[idx].CRVIZ._HASH_WITHOUT_IGNORED !== e.CRVIZ._HASH_WITHOUT_IGNORED){ + ds[idx].CRVIZ._isChanged = true; } }) } diff --git a/src/epics/diff-dataset-epic.js b/src/epics/diff-dataset-epic.js index 06bc4e002..b5cc7f367 100644 --- a/src/epics/diff-dataset-epic.js +++ b/src/epics/diff-dataset-epic.js @@ -34,16 +34,16 @@ const generateDiff = (payload) => { changed:[], removed:[] }; - diffs.added = diffs.added.concat(endDs.filter(ei => startDs.findIndex(si => si["HASH_KEY"] === ei["HASH_KEY"]) === -1).map(i => i["HASH_KEY"])); - diffs.removed = diffs.removed.concat(startDs.filter(si => endDs.findIndex(ei => ei["HASH_KEY"] === si["HASH_KEY"]) === -1).map(i => i["HASH_KEY"])); + diffs.added = diffs.added.concat(endDs.filter(ei => startDs.findIndex(si => si.CRVIZ["_HASH_KEY"] === ei.CRVIZ["_HASH_KEY"]) === -1).map(i => i.CRVIZ["_HASH_KEY"])); + diffs.removed = diffs.removed.concat(startDs.filter(si => endDs.findIndex(ei => ei.CRVIZ["_HASH_KEY"] === si.CRVIZ["_HASH_KEY"]) === -1).map(i => i.CRVIZ["_HASH_KEY"])); diffs.changed = diffs.changed.concat( endDs.filter( ei => startDs.findIndex( - si => si["HASH_KEY"] === ei["HASH_KEY"] && - si["HASH_WITHOUT_IGNORED"] !== ei["HASH_WITHOUT_IGNORED"] + si => si.CRVIZ["_HASH_KEY"] === ei.CRVIZ["_HASH_KEY"] && + si.CRVIZ["_HASH_WITHOUT_IGNORED"] !== ei.CRVIZ["_HASH_WITHOUT_IGNORED"] ) !== -1 - ).map(i => i["HASH_KEY"]) + ).map(i => i.CRVIZ["_HASH_KEY"]) ); //console.log("diffs to return: %o", diffs); diff --git a/src/epics/search-dataset-epic.js b/src/epics/search-dataset-epic.js index 211df5778..49ae457d4 100644 --- a/src/epics/search-dataset-epic.js +++ b/src/epics/search-dataset-epic.js @@ -49,10 +49,10 @@ const performSearch = (data) => { } } - data.dataset.forEach((el) => { el.isSearchResult = false; }); + data.dataset.forEach((el) => { el.CRVIZ._isSearchResult = false; }); results.forEach((r) => { if(data.dataset[r.ref]){ - data.dataset[r.ref].isSearchResult = true; + data.dataset[r.ref].CRVIZ._isSearchResult = true; data.results.push(data.dataset[r.ref]); } }); diff --git a/src/features/dataset-controls/export.js b/src/features/dataset-controls/export.js index 06695fc97..8bd432ba1 100644 --- a/src/features/dataset-controls/export.js +++ b/src/features/dataset-controls/export.js @@ -1,8 +1,10 @@ +import clonedeep from "lodash.clonedeep"; + const getDataToExport = (datasets, keyFields, ignoredFields, controls) => { let exportData = {}; if(datasets) - exportData["datasets"] = datasets; + exportData["datasets"] = sanitizeForExport(datasets); if(keyFields) exportData["keyFields"] = keyFields; @@ -16,5 +18,17 @@ const getDataToExport = (datasets, keyFields, ignoredFields, controls) => { return exportData; } +const sanitizeForExport = (datasets) =>{ + let result = clonedeep(datasets); + Object.keys(result).forEach((key) => { + result[key].dataset.forEach((item) => { + delete item.CRVIZ; + }); + }); + console.log("dataset without CRVIZ: %o", result); + console.log("dataset with CRVIZ: %o", datasets); + return result; +} + export default getDataToExport; export { getDataToExport }; \ No newline at end of file diff --git a/src/features/visualization/d3-viz/append-circles.js b/src/features/visualization/d3-viz/append-circles.js index 3aa2d6b65..a6d1a5cbe 100644 --- a/src/features/visualization/d3-viz/append-circles.js +++ b/src/features/visualization/d3-viz/append-circles.js @@ -19,13 +19,13 @@ const appendCircles = ({ nodeRoot, labelRoot, packedData, showNodes, hasSearch } .attr('data-key', datumKey) .classed(className("rootNode"), (d) => d.depth === 0) .classed(className("groupingNode"), (d) => d.depth > 0 && d.height > 0) - .classed(className("containsSearchResult"), (d) => hasSearch && d.data.searchResultCount > 0 && d.depth > 0 && d.height > 0) - .classed(className("containsNoSearchResult"), (d) => hasSearch && d.data.searchResultCount === 0 && d.depth > 0 && d.height > 0) - .classed(className("searchResult"), (d) => hasSearch && d.data.isSearchResult && d.depth > 0 && d.height === 0) - .classed(className("isChanged"), (d) => d.data.isChanged && d.depth > 0 && d.height === 0) - .classed(className("isAdded"), (d) => d.data.isAdded && d.depth > 0 && d.height === 0) - .classed(className("isRemoved"), (d) => d.data.isRemoved && d.depth > 0 && d.height === 0) - .classed(className("searchExcluded"), (d) => hasSearch && !d.data.isSearchResult && d.depth > 0 && d.height === 0) + .classed(className("containsSearchResult"), (d) => hasSearch && d.data.CRVIZ._searchResultCount > 0 && d.depth > 0 && d.height > 0) + .classed(className("containsNoSearchResult"), (d) => hasSearch && d.data.CRVIZ._searchResultCount === 0 && d.depth > 0 && d.height > 0) + .classed(className("searchResult"), (d) => hasSearch && d.data.CRVIZ._isSearchResult && d.depth > 0 && d.height === 0) + .classed(className("isChanged"), (d) => d.data.CRVIZ._isChanged && d.depth > 0 && d.height === 0) + .classed(className("isAdded"), (d) => d.data.CRVIZ._isAdded && d.depth > 0 && d.height === 0) + .classed(className("isRemoved"), (d) => d.data.CRVIZ._isRemoved && d.depth > 0 && d.height === 0) + .classed(className("searchExcluded"), (d) => hasSearch && !d.data.CRVIZ._isSearchResult && d.depth > 0 && d.height === 0) .classed(className("leafNode"), (d) => d.height === 0) .attr("transform", (d) => `translate(${[d.x, d.y].join(",")})`) .attr("display", (d) => !showNodes && d.height === 0 ? 'none' : null) diff --git a/src/features/visualization/d3-viz/setup-tooltip.js b/src/features/visualization/d3-viz/setup-tooltip.js index fe85ae245..adca07119 100644 --- a/src/features/visualization/d3-viz/setup-tooltip.js +++ b/src/features/visualization/d3-viz/setup-tooltip.js @@ -43,8 +43,8 @@ const showTooltip = (event, fields, offsetTop, offsetLeft, tooltip) => { const content = (datum, fields) => { if (datum.depth > 0 && datum.height > 0) { let cont = `${ datum.data.fieldValue } (${datum.value})`; - if(datum.data.searchResultCount > 0){ - cont += `
${datum.data.searchResultCount} search results` + if(datum.data.CRVIZ._searchResultCount > 0){ + cont += `
${datum.data.CRVIZ._searchResultCount} search results` } return cont; } else if (datum.height === 0) { diff --git a/src/features/visualization/d3-viz/to-hierarchy.js b/src/features/visualization/d3-viz/to-hierarchy.js index e568a150f..1cc150b06 100644 --- a/src/features/visualization/d3-viz/to-hierarchy.js +++ b/src/features/visualization/d3-viz/to-hierarchy.js @@ -40,7 +40,10 @@ const countSearchResults = (children) => { var result = 0; for(var c in children){ - result += (children[c].searchResultCount || 0) + (children[c].isSearchResult || 0) + + if(!('CRVIZ' in children[c])){ + children[c]['CRVIZ'] = {}; + } + result += (children[c].CRVIZ._searchResultCount || 0) + (children[c].CRVIZ._isSearchResult || 0) + ( !isNil(children[c].values) ? countSearchResults(children[c].values) : 0 @@ -59,7 +62,7 @@ const entriesToHierarchy = (fieldValue, field, hierarchyConfig, entries) => { fieldValue, field, children: chain(getLeaves, entries), - searchResultCount: countSearchResults(entries) + CRVIZ:{ _SEARCH_RESULT_COUNT: countSearchResults(entries) } } } @@ -78,7 +81,7 @@ const entriesToHierarchy = (fieldValue, field, hierarchyConfig, entries) => { return entry; } }, entries), - searchResultCount: countSearchResults(entries) + CRVIZ:{ _SEARCH_RESULT_COUNT: countSearchResults(entries) } }; };