import React from 'react'; import PropTypes from 'prop-types'; import { react2angular } from 'react2angular'; import Select from 'antd/lib/select'; import Input from 'antd/lib/input'; import InputNumber from 'antd/lib/input-number'; import { DateInput } from './DateInput'; import { DateRangeInput } from './DateRangeInput'; import { DateTimeInput } from './DateTimeInput'; import { DateTimeRangeInput } from './DateTimeRangeInput'; import { QueryBasedParameterInput } from './QueryBasedParameterInput'; const { Option } = Select; export class ParameterValueInput extends React.Component { static propTypes = { type: PropTypes.string, value: PropTypes.any, // eslint-disable-line react/forbid-prop-types enumOptions: PropTypes.string, queryId: PropTypes.number, onSelect: PropTypes.func, className: PropTypes.string, }; static defaultProps = { type: 'text', value: null, enumOptions: '', queryId: null, onSelect: () => {}, className: '', }; renderDateTimeWithSecondsInput() { const { value, onSelect } = this.props; return ( ); } renderDateTimeInput() { const { value, onSelect } = this.props; return ( ); } renderDateInput() { const { value, onSelect } = this.props; return ( ); } renderDateTimeRangeWithSecondsInput() { const { value, onSelect } = this.props; return ( ); } renderDateTimeRangeInput() { const { value, onSelect } = this.props; return ( ); } renderDateRangeInput() { const { value, onSelect } = this.props; return ( ); } renderEnumInput() { const { value, onSelect, enumOptions } = this.props; const enumOptionsArray = enumOptions.split('\n').filter(v => v !== ''); return ( ); } renderQueryBasedInput() { const { value, onSelect, queryId } = this.props; return ( ); } renderNumberInput() { const { value, onSelect, className } = this.props; return ( ); } renderTextInput() { const { value, onSelect, className } = this.props; return ( onSelect(event.target.value)} /> ); } render() { const { type } = this.props; switch (type) { case 'datetime-with-seconds': return this.renderDateTimeWithSecondsInput(); case 'datetime-local': return this.renderDateTimeInput(); case 'date': return this.renderDateInput(); case 'datetime-range-with-seconds': return this.renderDateTimeRangeWithSecondsInput(); case 'datetime-range': return this.renderDateTimeRangeInput(); case 'date-range': return this.renderDateRangeInput(); case 'enum': return this.renderEnumInput(); case 'query': return this.renderQueryBasedInput(); case 'number': return this.renderNumberInput(); default: return this.renderTextInput(); } } } export default function init(ngModule) { ngModule.component('parameterValueInput', { template: ` `, bindings: { param: '<', }, controller($scope) { this.setValue = (value) => { this.param.setValue(value); $scope.$applyAsync(); }; }, }); ngModule.component('parameterValueInputImpl', react2angular(ParameterValueInput)); } init.init = true;