mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import moment from 'moment';
|
|
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { react2angular } from 'react2angular';
|
|
import DatePicker from 'antd/lib/date-picker';
|
|
|
|
function DateTimeInput({
|
|
value,
|
|
withSeconds,
|
|
onSelect,
|
|
// eslint-disable-next-line react/prop-types
|
|
clientConfig,
|
|
}) {
|
|
const format = (clientConfig.dateFormat || 'YYYY-MM-DD') +
|
|
(withSeconds ? ' HH:mm:ss' : ' HH:mm');
|
|
const additionalAttributes = {};
|
|
if (value && value.isValid()) {
|
|
additionalAttributes.defaultValue = value;
|
|
}
|
|
return (
|
|
<DatePicker
|
|
showTime
|
|
{...additionalAttributes}
|
|
format={format}
|
|
placeholder="Select Date and Time"
|
|
onChange={onSelect}
|
|
/>
|
|
);
|
|
}
|
|
|
|
DateTimeInput.propTypes = {
|
|
value: (props, propName, componentName) => {
|
|
const value = props[propName];
|
|
if ((value !== null) && !moment.isMoment(value)) {
|
|
return new Error('Prop `' + propName + '` supplied to `' + componentName +
|
|
'` should be a Moment.js instance.');
|
|
}
|
|
},
|
|
withSeconds: PropTypes.bool,
|
|
onSelect: PropTypes.func,
|
|
};
|
|
|
|
DateTimeInput.defaultProps = {
|
|
value: null,
|
|
withSeconds: false,
|
|
onSelect: () => {},
|
|
};
|
|
|
|
export default function init(ngModule) {
|
|
ngModule.component('dateTimeInput', react2angular(DateTimeInput, null, ['clientConfig']));
|
|
}
|
|
|