Files
redash/client/app/components/DateInput.jsx
Levko Kravets 0c45d69662 Dashboard Parameters (#2756)
* getredash/redash#2641 Step 1: split Add Widget/Add Textbox buttons

* Convert Add widget/textbox dialogs to React components

* getredash/redash#2641 Step 2: Implement new dashboard parameters logic

* Resolve conflicts and fix build errors

* getredash/redash#2641 Refactoring and improve code quality

* Add Edit parameter mappings dialog to the widget

* getredash/redash#2641 Changes after code review

* Use Ant's Select component instead on <select> tags

* Fix Antd imports

* Fix Antd imports

* Fix Cannot read property 'getParametersDefs' of undefined

* Fix widgets static params bugs (don't show input, don't init from URL)

* Minor UI/UX fixes
2019-01-15 13:14:54 +02:00

53 lines
1.2 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';
export function DateInput({
value,
onSelect,
// eslint-disable-next-line react/prop-types
clientConfig,
className,
}) {
const format = clientConfig.dateFormat || 'YYYY-MM-DD';
const additionalAttributes = {};
if (value && value.isValid()) {
additionalAttributes.defaultValue = value;
}
return (
<DatePicker
className={className}
{...additionalAttributes}
format={format}
placeholder="Select Date"
onChange={onSelect}
/>
);
}
DateInput.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.');
}
},
onSelect: PropTypes.func,
className: PropTypes.string,
};
DateInput.defaultProps = {
value: null,
onSelect: () => {},
className: '',
};
export default function init(ngModule) {
ngModule.component('dateInput', react2angular(DateInput, null, ['clientConfig']));
}
init.init = true;