From d6694491936dcbdc56a9854520cd6bce24d3c6fc Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Mon, 5 Mar 2018 16:40:40 -0800 Subject: [PATCH] change time format from input to dropdown with an input available if custom format selected --- .../components/GraphOptionsTimeFormat.js | 67 +++++++++++++++---- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/ui/src/dashboards/components/GraphOptionsTimeFormat.js b/ui/src/dashboards/components/GraphOptionsTimeFormat.js index e5beec5c9..d78a43844 100644 --- a/ui/src/dashboards/components/GraphOptionsTimeFormat.js +++ b/ui/src/dashboards/components/GraphOptionsTimeFormat.js @@ -3,31 +3,70 @@ import PropTypes from 'prop-types' import moment from 'moment' import InputClickToEdit from 'shared/components/InputClickToEdit' +import {Dropdown} from 'src/shared/components/Dropdown' +import QuestionMarkTooltip from 'src/shared/components/QuestionMarkTooltip' + +const formatOptions = [ + {text: 'MM/DD/YYYY HH:mm:ss.ss'}, + {text: 'MM/DD/YYYY HH:mm'}, + {text: 'MM/DD/YYYY'}, + {text: 'h:mm:ss A'}, + {text: 'h:mm A'}, + {text: 'MMMM D, YYYY'}, + {text: 'MMMM D, YYYY h:mm A'}, + {text: 'dddd, MMMM D, YYYY h:mm A'}, + {text: 'Custom'}, +] class GraphOptionsTimeFormat extends Component { - state = {format: this.props.timeFormat || 'MM/DD/YYYY HH:mm:ss.ss'} + state = { + format: this.props.timeFormat || 'MM/DD/YYYY HH:mm:ss.ss', + customFormat: false, + } handleInputChange = value => { const {onTimeFormatChange} = this.props - const date = new Date() - const formattedDate = moment(date.toISOString()).format(value) - const validDateFormat = moment(formattedDate, value)._isValid - if (validDateFormat) { - onTimeFormatChange(value) + onTimeFormatChange(value) + } + + handleChooseFormat = formatOption => { + if (formatOption.text === 'Custom') { + this.setState({customFormat: true}) + } else { + this.setState({format: formatOption.text, customFormat: false}) } } render() { - const {format} = this.state + const {format, customFormat} = this.state + const tipContent = + 'For information on formatting, see http://momentjs.com/docs/#/parsing/string-format/' + return ( -
- - + + + {customFormat && + }
) }