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

DateTimePicker - invoke value change only on real change #3227

Merged

Conversation

nitzanyiz
Copy link
Contributor

Description

Added handling to invoke onChange only when the value really change.

Changelog

DateTimePicker - onChange fixes. Only calls onChange when value really changes.

Additional info

MADS-4209
MADS-4210
MADS-4211

@nitzanyiz nitzanyiz requested a review from M-i-k-e-l August 25, 2024 08:55
@nitzanyiz nitzanyiz marked this pull request as ready for review August 25, 2024 08:56
@nitzanyiz nitzanyiz changed the title Fix/date time picker invoke value change on real change DateTimePicker - invoke value change only on real change Aug 25, 2024
src/components/dateTimePicker/index.tsx Outdated Show resolved Hide resolved
Comment on lines 16 to 18
const someDate = new Date('2021-04-04T00:00:00Z');
const someDateNextDay = new Date(someDate.getTime() + 24 * 60 * 60 * 1000);
const someDateNextHour = new Date(someDate.getTime() + 60 * 60 * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe:
sameTime \ sameDate
nextDay
nextHour

Copy link
Contributor Author

@nitzanyiz nitzanyiz Sep 1, 2024

Choose a reason for hiding this comment

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

Wdym here?
Do you think date, nextHour, nextDay is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, sorry I was not clear - this is about naming.
Personally I think sameTime, nextDay and nextHour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would you call it sameDate? What is it similar to?
I feel like its pretty clear, it also states that the date its self is not important.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it's the same date as the date of the value, it's not a random "some date" it's the same date and the next day after the value and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the date objects to the top of the file and used them in the default props.

const someDate = new Date('2021-04-04T00:00:00Z');
const someDateNextDay = new Date(someDate.getTime() + 24 * 60 * 60 * 1000);
const someDateNextHour = new Date(someDate.getTime() + 60 * 60 * 1000);
jest.mock('../../../optionalDependencies', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be in jest-setup.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. jest-setup will mock this for every test file we have. I only see external modules in the jest-mock file i think its more organized this way.
Adding it to the jest-setup file also works. I guess we could do that. Do you think it will be clearer to put it there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think that's the proper place for it because if we'll have an issue in private we'll look there first for a mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What kind of issue will possibly have? When I you the jest mock here I don't think it has any effect on other test files. If I put it in the jest-setup one it does.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we'll need to mock the DateTimePickerPackage we'll probably look there and not here

src/components/dateTimePicker/__tests__/index.spec.tsx Outdated Show resolved Hide resolved
src/components/dateTimePicker/__tests__/index.spec.tsx Outdated Show resolved Hide resolved
src/components/dateTimePicker/__tests__/index.spec.tsx Outdated Show resolved Hide resolved
src/components/dateTimePicker/index.tsx Outdated Show resolved Hide resolved
@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Aug 27, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Sep 1, 2024
@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Sep 2, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Sep 2, 2024
@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Sep 4, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Sep 5, 2024
@M-i-k-e-l M-i-k-e-l merged commit cc8ad20 into master Sep 11, 2024
1 check passed
@M-i-k-e-l M-i-k-e-l deleted the fix/DateTimePicker-invoke-value-change-on-real-change branch September 11, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants