Skip to content

Commit

Permalink
[Bug fix] Fix "Now" in DateTime parameter not working (#3808)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra authored and kravets-levko committed May 16, 2019
1 parent 606cf12 commit b263bb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions client/app/components/DateTimeInput.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import { react2angular } from 'react2angular';
import DatePicker from 'antd/lib/date-picker';
Expand All @@ -13,20 +13,21 @@ export function DateTimeInput({
}) {
const format = (clientConfig.dateFormat || 'YYYY-MM-DD') +
(withSeconds ? ' HH:mm:ss' : ' HH:mm');
let defaultValue;
const additionalAttributes = {};
if (value && value.isValid()) {
defaultValue = value;
additionalAttributes.defaultValue = value;
}
const [currentValue, setCurrentValue] = useState(defaultValue);
const currentValueRef = useRef(additionalAttributes.defaultValue);
return (
<DatePicker
className={className}
showTime
value={currentValue}
{...additionalAttributes}
format={format}
placeholder="Select Date and Time"
onChange={newValue => setCurrentValue(newValue)}
onChange={(newValue) => { currentValueRef.current = newValue; }}
onOpenChange={(status) => {
const currentValue = currentValueRef.current;
if (!status) { // on close picker
if (currentValue && currentValue.isValid()) {
onSelect(currentValue);
Expand Down
13 changes: 7 additions & 6 deletions client/app/components/DateTimeRangeInput.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArray } from 'lodash';
import React, { useState } from 'react';
import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import { react2angular } from 'react2angular';
import DatePicker from 'antd/lib/date-picker';
Expand All @@ -16,19 +16,20 @@ export function DateTimeRangeInput({
}) {
const format = (clientConfig.dateFormat || 'YYYY-MM-DD') +
(withSeconds ? ' HH:mm:ss' : ' HH:mm');
let defaultValue;
const additionalAttributes = {};
if (isArray(value) && value[0].isValid() && value[1].isValid()) {
defaultValue = value;
additionalAttributes.defaultValue = value;
}
const [currentValue, setCurrentValue] = useState(defaultValue);
const currentValueRef = useRef(additionalAttributes.defaultValue);
return (
<RangePicker
className={className}
showTime
value={currentValue}
{...additionalAttributes}
format={format}
onChange={newValue => setCurrentValue(newValue)}
onChange={(newValue) => { currentValueRef.current = newValue; }}
onOpenChange={(status) => {
const currentValue = currentValueRef.current;
if (!status) { // on close picker
if (isArray(currentValue) && currentValue[0].isValid() && currentValue[1].isValid()) {
onSelect(currentValue);
Expand Down

0 comments on commit b263bb7

Please sign in to comment.