update graphOptionsTimeFormat to have state and validate format; fix linter errors
parent
571382f046
commit
79fe4d0102
|
@ -1,20 +1,42 @@
|
||||||
import React, {PropTypes} from 'react'
|
import React, {Component} from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import moment from 'moment'
|
||||||
|
|
||||||
const GraphOptionsTimeFormat = ({TimeFormat, onTimeFormatChange}) =>
|
import InputClickToEdit from 'shared/components/InputClickToEdit'
|
||||||
<div>
|
|
||||||
<label>Time Format</label>
|
class GraphOptionsTimeFormat extends Component {
|
||||||
<input
|
state = {format: 'MM/DD/YYYY HH:mm:ss.ss'}
|
||||||
className="form-control input-sm"
|
|
||||||
placeholder="mm/dd/yyyy HH:mm:ss.ss"
|
handleInputChange = value => {
|
||||||
value={TimeFormat}
|
const {onTimeFormatChange} = this.props
|
||||||
onChange={onTimeFormatChange}
|
const date = new Date()
|
||||||
/>
|
const formattedDate = moment(date.toISOString()).format(value)
|
||||||
</div>
|
const validDateFormat = moment(formattedDate, value)._isValid
|
||||||
|
if (validDateFormat) {
|
||||||
|
onTimeFormatChange(validDateFormat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {timeFormat} = this.props
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<label>Time Format</label>
|
||||||
|
<InputClickToEdit
|
||||||
|
wrapperClass="fancytable--td orgs-table--name"
|
||||||
|
value={timeFormat}
|
||||||
|
onUpdate={this.handleInputChange}
|
||||||
|
placeholder="MM/DD/YYYY HH:mm:ss.ss"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {func, string} = PropTypes
|
const {func, string} = PropTypes
|
||||||
|
|
||||||
GraphOptionsTimeFormat.propTypes = {
|
GraphOptionsTimeFormat.propTypes = {
|
||||||
TimeFormat: string,
|
timeFormat: string,
|
||||||
onTimeFormatChange: func,
|
onTimeFormatChange: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ const formatColor = color => {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TableOptions extends Component {
|
class TableOptions extends Component {
|
||||||
state = {TimeAxis: 'VERTICAL', TimeFormat: 'MM/DD/YYYY HH:mm:ss.ss'}
|
state = {TimeAxis: 'VERTICAL', timeFormat: 'MM/DD/YYYY HH:mm:ss.ss'}
|
||||||
|
|
||||||
handleToggleSingleStatType = () => {}
|
handleToggleSingleStatType = () => {}
|
||||||
|
|
||||||
|
@ -39,7 +39,9 @@ class TableOptions extends Component {
|
||||||
|
|
||||||
handleChooseSortBy = () => {}
|
handleChooseSortBy = () => {}
|
||||||
|
|
||||||
handleTimeFormatChange = () => {}
|
handleTimeFormatChange = timeFormat => {
|
||||||
|
this.setState({...this.state, timeFormat: timeFormat.target.value})
|
||||||
|
}
|
||||||
|
|
||||||
handleToggleTimeAxis = () => {}
|
handleToggleTimeAxis = () => {}
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ class TableOptions extends Component {
|
||||||
// axes: {y: {prefix, suffix}},
|
// axes: {y: {prefix, suffix}},
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const {TimeFormat, TimeAxis} = this.state
|
const {timeFormat, TimeAxis} = this.state
|
||||||
|
|
||||||
const disableAddThreshold = singleStatColors.length > MAX_THRESHOLDS
|
const disableAddThreshold = singleStatColors.length > MAX_THRESHOLDS
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ class TableOptions extends Component {
|
||||||
<h5 className="display-options--header">Table Controls</h5>
|
<h5 className="display-options--header">Table Controls</h5>
|
||||||
<div className="gauge-controls">
|
<div className="gauge-controls">
|
||||||
<GraphOptionsTimeFormat
|
<GraphOptionsTimeFormat
|
||||||
TimeFormat={TimeFormat}
|
timeFormat={timeFormat}
|
||||||
onTimeFormatChange={this.handleTimeFormatChange}
|
onTimeFormatChange={this.handleTimeFormatChange}
|
||||||
/>
|
/>
|
||||||
<GraphOptionsTimeAxis
|
<GraphOptionsTimeAxis
|
||||||
|
|
|
@ -13,6 +13,8 @@ export const SINGLE_STAT_TEXT = 'text'
|
||||||
export const SINGLE_STAT_BG = 'background'
|
export const SINGLE_STAT_BG = 'background'
|
||||||
export const SINGLE_STAT_BASE = 'base'
|
export const SINGLE_STAT_BASE = 'base'
|
||||||
|
|
||||||
|
export const TIME_FORMAT_DEFAULT = 'MM/DD/YYYY HH:mm:ss.ss'
|
||||||
|
|
||||||
export const GAUGE_COLORS = [
|
export const GAUGE_COLORS = [
|
||||||
{
|
{
|
||||||
hex: '#BF3D5E',
|
hex: '#BF3D5E',
|
||||||
|
|
|
@ -167,12 +167,14 @@ export const timeSeriesToTable = data => {
|
||||||
const {labels, timeSeries} = timeSeriesToDygraph(data, false)
|
const {labels, timeSeries} = timeSeriesToDygraph(data, false)
|
||||||
const tableData = timeSeries.length
|
const tableData = timeSeries.length
|
||||||
? timeSeries.map(row =>
|
? timeSeries.map(row =>
|
||||||
row.map(
|
row.map(cell => {
|
||||||
cell =>
|
if (cell) {
|
||||||
cell
|
return typeof cell === 'object'
|
||||||
? typeof cell === 'object' ? cell.toISOString() : cell.toString()
|
? cell.toISOString()
|
||||||
: 'null'
|
: cell.toString()
|
||||||
)
|
}
|
||||||
|
return 'null'
|
||||||
|
})
|
||||||
)
|
)
|
||||||
: [[]]
|
: [[]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue