Skip to content

Commit

Permalink
Merge pull request #986 from oskarhane/fix-json-export
Browse files Browse the repository at this point in the history
Bring back JSON data export
  • Loading branch information
oskarhane authored Nov 13, 2019
2 parents bf34d62 + 79b3fa7 commit 9249231
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 318 deletions.
35 changes: 32 additions & 3 deletions src/browser/modules/Frame/FrameTitlebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { connect } from 'react-redux'
import React, { Component } from 'react'
import { withBus } from 'react-suber'
import { saveAs } from 'file-saver'
import { map } from 'lodash-es'

import * as editor from 'shared/modules/editor/editorDuck'
import * as commands from 'shared/modules/commands/commandsDuck'
import {
Expand Down Expand Up @@ -55,22 +57,26 @@ import {
StyledFrameTitleBar,
StyledFrameTitlebarButtonSection,
StyledFrameCommand
} from 'browser/modules/Frame/styled'
} from './styled'
import {
downloadPNGFromSVG,
downloadSVG
} from 'shared/services/exporting/imageUtils'
import {
stringifyResultArray,
transformResultRecordsToResultArray
transformResultRecordsToResultArray,
recordToJSONMapper
} from 'browser/modules/Stream/CypherFrame/helpers'
import { csvFormat } from 'services/bolt/cypherTypesFormatting'
import arrayHasItems from 'shared/utils/array-has-items'

const JSON_EXPORT_INDENT = 2

class FrameTitlebar extends Component {
hasData () {
return this.props.numRecords > 0
}

exportCSV (records) {
const exportData = stringifyResultArray(
csvFormat,
Expand Down Expand Up @@ -108,25 +114,43 @@ class FrameTitlebar extends Component {
}
}

exportJSON (records) {
const data = JSON.stringify(
map(records, recordToJSONMapper),
null,
JSON_EXPORT_INDENT
)
const blob = new Blob([data], {
type: 'text/plain;charset=utf-8'
})

saveAs(blob, 'records.json')
}

exportPNG () {
const { svgElement, graphElement, type } = this.props.visElement
downloadPNGFromSVG(svgElement, graphElement, type)
}

exportSVG () {
const { svgElement, graphElement, type } = this.props.visElement
downloadSVG(svgElement, graphElement, type)
}

exportGrass (data) {
var blob = new Blob([data], {
type: 'text/plain;charset=utf-8'
})
saveAs(blob, 'style.grass')
}

canExport = () => {
let props = this.props
const { frame = {} } = props

return (
(frame.type === 'cypher' && (this.hasData() || props.visElement)) ||
this.canExportTXT() ||
(frame.type === 'cypher' && (this.hasData() || this.props.visElement)) ||
(frame.type === 'style' && this.hasData())
)
}
Expand Down Expand Up @@ -175,6 +199,11 @@ class FrameTitlebar extends Component {
>
Export CSV
</DropdownItem>
<DropdownItem
onClick={() => this.exportJSON(props.getRecords())}
>
Export JSON
</DropdownItem>
</Render>
<Render if={this.canExportTXT()}>
<DropdownItem onClick={this.exportTXT}>
Expand Down
Loading

0 comments on commit 9249231

Please sign in to comment.