From 0586cfd42b09e63c1928f4e15e92eeb6d84d0a62 Mon Sep 17 00:00:00 2001 From: Peter Kerpedjiev Date: Sun, 22 Jan 2017 15:50:16 -0500 Subject: [PATCH] Working JSON view export --- app/scripts/HiGlassComponent.jsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/scripts/HiGlassComponent.jsx b/app/scripts/HiGlassComponent.jsx index f88765aee..5cda97a09 100644 --- a/app/scripts/HiGlassComponent.jsx +++ b/app/scripts/HiGlassComponent.jsx @@ -1048,9 +1048,21 @@ export class HiGlassComponent extends React.Component { return; } + getViewsAsString() { + console.log('views:', this.state.views); + let newJson = JSON.parse(JSON.stringify(this.props.viewConfig)); + newJson.views = dictItems(this.state.views).map(k => { + k[1].uid = k[0]; + return k[1]; + }); + + + let data = JSON.stringify(newJson); + return data; + } + handleExportViewAsJSON() { - let wholeJSON = dictValues(this.state.views); - let data = JSON.stringify(wholeJSON,null,2); + let data = this.getViewsAsString(); var a = document.createElement("a"); var file = new Blob([data], {type: 'text/json'}); @@ -1060,11 +1072,7 @@ export class HiGlassComponent extends React.Component { } handleExportViewsAsLink() { - let wholeJSON = dictValues(this.state.views); - let newJson = JSON.parse(JSON.stringify(this.props.viewConfig)); - newJson.views = this.state.views; - - let data = JSON.stringify(newJson); + let data = this.getViewsAsString(); this.setState({ exportLinkModalOpen: true, @@ -1215,6 +1223,7 @@ export class HiGlassComponent extends React.Component { processViewConfig(viewConfig) { let views = viewConfig.views; let viewsByUid = {}; + views.forEach(v => { this.fillInMinWidths(v.tracks); viewsByUid[v.uid] = v;