mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 22:00:10 -04:00
* 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
48 lines
1.1 KiB
JavaScript
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;
|