Files
redash/client/app/components/DateTimeInput.jsx
Levko Kravets b0b4d5e26a Convert Angular services to CommonJS-style and use them in React components instead of injecting (#3331)
* Refine Auth service: remove dead code and fix race condition
* Export services in CommonJS style
* Refine Users, Events and OfflineListener services
* Refactor Notifications service - rewrite to CommonJS
* Replace Angular service injection with imports in React components
* Fix Footer tests
* Events service -> recordEvent function
* CR1
2019-01-24 16:24:58 +02:00

57 lines
1.4 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';
import { clientConfig } from '@/services/auth';
export function DateTimeInput({
value,
withSeconds,
onSelect,
className,
}) {
const format = (clientConfig.dateFormat || 'YYYY-MM-DD') +
(withSeconds ? ' HH:mm:ss' : ' HH:mm');
const additionalAttributes = {};
if (value && value.isValid()) {
additionalAttributes.defaultValue = value;
}
return (
<DatePicker
className={className}
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,
className: PropTypes.string,
};
DateTimeInput.defaultProps = {
value: null,
withSeconds: false,
onSelect: () => {},
className: '',
};
export default function init(ngModule) {
ngModule.component('dateTimeInput', react2angular(DateTimeInput));
}
init.init = true;