Perform expensive transformation for csv data at time of request
parent
80396e86e4
commit
5b69635d75
|
@ -4,7 +4,6 @@ import _ from 'lodash'
|
||||||
import {fetchTimeSeries} from 'src/shared/apis/query'
|
import {fetchTimeSeries} from 'src/shared/apis/query'
|
||||||
import {DEFAULT_TIME_SERIES} from 'src/shared/constants/series'
|
import {DEFAULT_TIME_SERIES} from 'src/shared/constants/series'
|
||||||
import {TimeSeriesServerResponse, TimeSeriesResponse} from 'src/types/series'
|
import {TimeSeriesServerResponse, TimeSeriesResponse} from 'src/types/series'
|
||||||
import {timeSeriesToTableGraph} from 'src/utils/timeSeriesTransformers'
|
|
||||||
|
|
||||||
interface Axes {
|
interface Axes {
|
||||||
bounds: {
|
bounds: {
|
||||||
|
@ -131,8 +130,7 @@ const AutoRefresh = (
|
||||||
})
|
})
|
||||||
|
|
||||||
if (grabDataForDownload) {
|
if (grabDataForDownload) {
|
||||||
const {data} = timeSeriesToTableGraph(newSeries)
|
grabDataForDownload(newSeries)
|
||||||
grabDataForDownload(data)
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
|
@ -23,11 +23,11 @@ const getSource = (cell, source, sources, defaultSource) => {
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class LayoutState extends Component {
|
class LayoutState extends Component {
|
||||||
state = {
|
state = {
|
||||||
celldata: [[]],
|
cellData: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
grabDataForDownload = celldata => {
|
grabDataForDownload = cellData => {
|
||||||
this.setState({celldata})
|
this.setState({cellData})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -59,7 +59,7 @@ const Layout = (
|
||||||
source,
|
source,
|
||||||
sources,
|
sources,
|
||||||
onZoom,
|
onZoom,
|
||||||
celldata,
|
cellData,
|
||||||
templates,
|
templates,
|
||||||
timeRange,
|
timeRange,
|
||||||
isEditable,
|
isEditable,
|
||||||
|
@ -79,7 +79,7 @@ const Layout = (
|
||||||
) => (
|
) => (
|
||||||
<LayoutCell
|
<LayoutCell
|
||||||
cell={cell}
|
cell={cell}
|
||||||
celldata={celldata}
|
cellData={cellData}
|
||||||
isEditable={isEditable}
|
isEditable={isEditable}
|
||||||
onEditCell={onEditCell}
|
onEditCell={onEditCell}
|
||||||
onCloneCell={onCloneCell}
|
onCloneCell={onCloneCell}
|
||||||
|
@ -122,7 +122,7 @@ const Layout = (
|
||||||
</LayoutCell>
|
</LayoutCell>
|
||||||
)
|
)
|
||||||
|
|
||||||
const {array, arrayOf, bool, func, number, shape, string} = PropTypes
|
const {arrayOf, bool, func, number, shape, string} = PropTypes
|
||||||
|
|
||||||
Layout.contextTypes = {
|
Layout.contextTypes = {
|
||||||
source: shape(),
|
source: shape(),
|
||||||
|
@ -200,7 +200,7 @@ LayoutState.propTypes = {...propTypes}
|
||||||
Layout.propTypes = {
|
Layout.propTypes = {
|
||||||
...propTypes,
|
...propTypes,
|
||||||
grabDataForDownload: func,
|
grabDataForDownload: func,
|
||||||
celldata: arrayOf(array),
|
cellData: arrayOf(shape({})),
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LayoutState
|
export default LayoutState
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {notifyCSVDownloadFailed} from 'src/shared/copy/notifications'
|
||||||
import download from 'src/external/download.js'
|
import download from 'src/external/download.js'
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
import {dataToCSV} from 'src/shared/parsing/dataToCSV'
|
import {dataToCSV} from 'src/shared/parsing/dataToCSV'
|
||||||
|
import {timeSeriesToTableGraph} from 'src/utils/timeSeriesTransformers'
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class LayoutCell extends Component {
|
class LayoutCell extends Component {
|
||||||
|
@ -24,9 +25,11 @@ class LayoutCell extends Component {
|
||||||
|
|
||||||
handleCSVDownload = cell => () => {
|
handleCSVDownload = cell => () => {
|
||||||
const joinedName = cell.name.split(' ').join('_')
|
const joinedName = cell.name.split(' ').join('_')
|
||||||
const {celldata} = this.props
|
const {cellData} = this.props
|
||||||
|
const {data} = timeSeriesToTableGraph(cellData)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
download(dataToCSV(celldata), `${joinedName}.csv`, 'text/plain')
|
download(dataToCSV(data), `${joinedName}.csv`, 'text/plain')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notify(notifyCSVDownloadFailed())
|
notify(notifyCSVDownloadFailed())
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
@ -34,7 +37,7 @@ class LayoutCell extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {cell, children, isEditable, celldata, onCloneCell} = this.props
|
const {cell, children, isEditable, cellData, onCloneCell} = this.props
|
||||||
|
|
||||||
const queries = _.get(cell, ['queries'], [])
|
const queries = _.get(cell, ['queries'], [])
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ class LayoutCell extends Component {
|
||||||
<LayoutCellMenu
|
<LayoutCellMenu
|
||||||
cell={cell}
|
cell={cell}
|
||||||
queries={queries}
|
queries={queries}
|
||||||
dataExists={!!celldata.length}
|
dataExists={!!cellData.length}
|
||||||
isEditable={isEditable}
|
isEditable={isEditable}
|
||||||
onDelete={this.handleDeleteCell}
|
onDelete={this.handleDeleteCell}
|
||||||
onEdit={this.handleSummonOverlay}
|
onEdit={this.handleSummonOverlay}
|
||||||
|
@ -79,7 +82,7 @@ class LayoutCell extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {array, arrayOf, bool, func, node, number, shape, string} = PropTypes
|
const {arrayOf, bool, func, node, number, shape, string} = PropTypes
|
||||||
|
|
||||||
LayoutCell.propTypes = {
|
LayoutCell.propTypes = {
|
||||||
cell: shape({
|
cell: shape({
|
||||||
|
@ -96,7 +99,7 @@ LayoutCell.propTypes = {
|
||||||
onSummonOverlayTechnologies: func,
|
onSummonOverlayTechnologies: func,
|
||||||
isEditable: bool,
|
isEditable: bool,
|
||||||
onCancelEditCell: func,
|
onCancelEditCell: func,
|
||||||
celldata: arrayOf(array),
|
cellData: arrayOf(shape({})),
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LayoutCell
|
export default LayoutCell
|
||||||
|
|
Loading…
Reference in New Issue