Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

PersistenceTransforms for date in datePickerRange and datePickerSingle #854

Merged
merged 23 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
command: |
. venv/bin/activate && mkdir packages
# build main dash
git clone --depth 1 https://github.com/plotly/dash.git dash-main
git clone -b persistence-hg --depth 1 https://github.com/plotly/dash.git dash-main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With plotly/dash#1376 now merged, this can be 🔪

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd dash-main && pip install -e .[dev] --progress-bar off && python setup.py sdist && mv dist/* ../packages/
cd dash-renderer && npm ci && npm run build
python setup.py sdist && mv dist/* ../../packages/ && cd ../..
Expand Down
26 changes: 26 additions & 0 deletions src/components/DatePickerRange.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React, {Component, lazy, Suspense} from 'react';
import datePickerRange from '../utils/LazyLoader/datePickerRange';
import moment from 'moment';

const RealDatePickerRange = lazy(datePickerRange);

Expand Down Expand Up @@ -263,6 +264,31 @@ DatePickerRange.propTypes = {
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
};

DatePickerRange.persistenceTransforms = {
end_date: {
extract: propValue => {
if (!(propValue === null || propValue === undefined)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is fine but can be simplified by using https://ramdajs.com/docs/#isNil instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return moment(propValue)
.startOf('day')
.format('YYYY-MM-DD');
}
return propValue;
},
apply: storedValue => storedValue,
},
start_date: {
extract: propValue => {
if (!(propValue === null || propValue === undefined)) {
return moment(propValue)
.startOf('day')
.format('YYYY-MM-DD');
}
return propValue;
},
apply: storedValue => storedValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for end_date and start_date extract and apply are identical (same for DatePickerSingle date) -- DRY by defining a functions that you can share between the 3 cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
};

DatePickerRange.defaultProps = {
calendar_orientation: 'horizontal',
is_RTL: false,
Expand Down
15 changes: 15 additions & 0 deletions src/components/DatePickerSingle.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React, {Component, lazy, Suspense} from 'react';
import datePickerSingle from '../utils/LazyLoader/datePickerSingle';
import moment from 'moment';

const RealDateSingleRange = lazy(datePickerSingle);

Expand Down Expand Up @@ -220,6 +221,20 @@ DatePickerSingle.propTypes = {
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
};

DatePickerSingle.persistenceTransforms = {
date: {
extract: propValue => {
if (!(propValue === null || propValue === undefined)) {
return moment(propValue)
.startOf('day')
.format('YYYY-MM-DD');
}
return propValue;
},
apply: storedValue => storedValue,
},
};

DatePickerSingle.defaultProps = {
calendar_orientation: 'horizontal',
is_RTL: false,
Expand Down