Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X2-4379: Add option to not select future dates in pre-calculated date ranges #211

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
11 changes: 10 additions & 1 deletion src/components/DatePicker/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const DatePicker = ({
components = {},
getTooltip,
upcomingDates,
shouldSelectFutureDatesInRelativeRange = true,
...rest
}) => {
const initialValue = variant === variants.single ? value : value.from;
Expand Down Expand Up @@ -87,7 +88,15 @@ export const DatePicker = ({

const handleRelativeRangeChanged = (rangeName, range) => {
setCurrentMonth(range.from);
onChange(range, modifiers, null);
const newRange = { ...range };
if (
!shouldSelectFutureDatesInRelativeRange && // don't select future dates, e.g. for cash flow report
range.to.isAfter(dayjs().get("date"))
) {
newRange.to = dayjs().get("date");
}

onChange(newRange, modifiers, null);
Comment on lines +91 to +99
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will not work. Did you mean to use dayjs().toDate() instead of dayjs().get("date")?

dayjs().get("date") just returns a number of the current day in month.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I feel like this logic belongs to x2-seller and not ui-kit. We can discuss when you are free

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah needs to be changed, not sure how it was working when I checked.

};

const handleMonthChange = (m) => {
Expand Down