Files
redash/client/app/components/DateRangeInput.jsx
Levko Kravets 807e6aaaa6 Migrate "time ago" components to React (#3385)
* Replace <am-time-ago> (angular-moment) and <rd-timer> with React component

* PropTypes: Moment validation

* Increase polling interval

* Refine component implementation

* Add tooltip with formatted date/time

* Refine component implementation
2019-02-02 18:46:48 +02:00

48 lines
1.1 KiB
JavaScript

import { isArray } from 'lodash';
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';
import { Moment } from '@/components/proptypes';
const { RangePicker } = DatePicker;
export function DateRangeInput({
value,
onSelect,
className,
}) {
const format = clientConfig.dateFormat || 'YYYY-MM-DD';
const additionalAttributes = {};
if (isArray(value) && value[0].isValid() && value[1].isValid()) {
additionalAttributes.defaultValue = value;
}
return (
<RangePicker
className={className}
{...additionalAttributes}
format={format}
onChange={onSelect}
/>
);
}
DateRangeInput.propTypes = {
value: PropTypes.arrayOf(Moment),
onSelect: PropTypes.func,
className: PropTypes.string,
};
DateRangeInput.defaultProps = {
value: null,
onSelect: () => {},
className: '',
};
export default function init(ngModule) {
ngModule.component('dateRangeInput', react2angular(DateRangeInput));
}
init.init = true;