@@ -22,6 +22,8 @@ import { connect } from 'react-redux'
2222import React , { Component } from 'react'
2323import { withBus } from 'react-suber'
2424import { saveAs } from 'file-saver'
25+ import { map } from 'lodash-es'
26+
2527import * as editor from 'shared/modules/editor/editorDuck'
2628import * as commands from 'shared/modules/commands/commandsDuck'
2729import {
@@ -55,22 +57,26 @@ import {
5557 StyledFrameTitleBar ,
5658 StyledFrameTitlebarButtonSection ,
5759 StyledFrameCommand
58- } from 'browser/modules/Frame /styled'
60+ } from '. /styled'
5961import {
6062 downloadPNGFromSVG ,
6163 downloadSVG
6264} from 'shared/services/exporting/imageUtils'
6365import {
6466 stringifyResultArray ,
65- transformResultRecordsToResultArray
67+ transformResultRecordsToResultArray ,
68+ recordToJSONMapper
6669} from 'browser/modules/Stream/CypherFrame/helpers'
6770import { csvFormat } from 'services/bolt/cypherTypesFormatting'
6871import arrayHasItems from 'shared/utils/array-has-items'
6972
73+ const JSON_EXPORT_INDENT = 2
74+
7075class FrameTitlebar extends Component {
7176 hasData ( ) {
7277 return this . props . numRecords > 0
7378 }
79+
7480 exportCSV ( records ) {
7581 const exportData = stringifyResultArray (
7682 csvFormat ,
@@ -108,25 +114,43 @@ class FrameTitlebar extends Component {
108114 }
109115 }
110116
117+ exportJSON ( records ) {
118+ const data = JSON . stringify (
119+ map ( records , recordToJSONMapper ) ,
120+ null ,
121+ JSON_EXPORT_INDENT
122+ )
123+ const blob = new Blob ( [ data ] , {
124+ type : 'text/plain;charset=utf-8'
125+ } )
126+
127+ saveAs ( blob , 'records.json' )
128+ }
129+
111130 exportPNG ( ) {
112131 const { svgElement, graphElement, type } = this . props . visElement
113132 downloadPNGFromSVG ( svgElement , graphElement , type )
114133 }
134+
115135 exportSVG ( ) {
116136 const { svgElement, graphElement, type } = this . props . visElement
117137 downloadSVG ( svgElement , graphElement , type )
118138 }
139+
119140 exportGrass ( data ) {
120141 var blob = new Blob ( [ data ] , {
121142 type : 'text/plain;charset=utf-8'
122143 } )
123144 saveAs ( blob , 'style.grass' )
124145 }
146+
125147 canExport = ( ) => {
126148 let props = this . props
127149 const { frame = { } } = props
150+
128151 return (
129- ( frame . type === 'cypher' && ( this . hasData ( ) || props . visElement ) ) ||
152+ this . canExportTXT ( ) ||
153+ ( frame . type === 'cypher' && ( this . hasData ( ) || this . props . visElement ) ) ||
130154 ( frame . type === 'style' && this . hasData ( ) )
131155 )
132156 }
@@ -175,6 +199,11 @@ class FrameTitlebar extends Component {
175199 >
176200 Export CSV
177201 </ DropdownItem >
202+ < DropdownItem
203+ onClick = { ( ) => this . exportJSON ( props . getRecords ( ) ) }
204+ >
205+ Export JSON
206+ </ DropdownItem >
178207 </ Render >
179208 < Render if = { this . canExportTXT ( ) } >
180209 < DropdownItem onClick = { this . exportTXT } >
0 commit comments