Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/browser/modules/Stream/FrameTitlebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ import {
transformResultRecordsToResultArray
} from 'browser/modules/Stream/CypherFrame/helpers'
import { csvFormat } from 'services/bolt/cypherTypesFormatting'
import arrayHasItems from 'shared/utils/array-has-items'

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

exportCSV (records) {
const exportData = stringifyResultArray(
csvFormat,
Expand All @@ -81,28 +83,54 @@ class FrameTitlebar extends Component {
})
saveAs(blob, 'export.csv')
}

exportTXT = () => {
const { frame } = this.props

if (frame.type === 'history') {
const asTxt = frame.result.join(';\n\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check so the statement isn't already ending with a semicolon?
Also, client commands (statements starting with :) should / cannot end with a semicolon, only Cypher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

const blob = new Blob([asTxt], {
type: 'text/plain;charset=utf-8'
})

saveAs(blob, 'history.txt')
}
}

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())
)
}

canExportTXT () {
const { frame = {} } = this.props

return frame.type === 'history' && arrayHasItems(frame.result)
}

render () {
let props = this.props
const { frame = {} } = props
Expand Down Expand Up @@ -142,6 +170,11 @@ class FrameTitlebar extends Component {
Export CSV
</DropdownItem>
</Render>
<Render if={this.canExportTXT()}>
<DropdownItem onClick={this.exportTXT}>
Export TXT
</DropdownItem>
</Render>
<Render if={this.hasData() && frame.type === 'style'}>
<DropdownItem
data-testid='exportGrassButton'
Expand Down
20 changes: 20 additions & 0 deletions src/shared/utils/array-has-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
* This file is part of Neo4j.
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

export default function arrayHasItems (arr) {
return Array.isArray(arr) && arr.length > 0
}