xrutayisire / react-js-cron

A React cron editor built with antd
https://xrutayisire.github.io/react-js-cron/?path=/docs/reactjs-cron--demo
MIT License
249 stars 106 forks source link

Do not allow cron to be set for every hour #15

Closed vdineva closed 2 years ago

vdineva commented 2 years ago

I have a use case where we don't want the users to set the cron job to run at every hour. I've added custom logic in the customSetValue function - see reproducible code here: https://codesandbox.io/s/funny-einstein-vjlfv?file=/src/App.js

and check if the value of cron is set to every hour (e.g. no value is selected for hour)- default it to 12am. I can see it flashes with 12am selected but then reverts back to 'every hour'

please see video here:

https://user-images.githubusercontent.com/791418/149348982-43650b50-8916-4cfa-93bb-c15dcb7f33d1.mov

Any advise on how I can achieve this is much appreciated.

xrutayisire commented 2 years ago

Hi!

Thanks for the issue. I will take a look at your problem because it's very strange, and it's maybe a bug :/

Xavier

xrutayisire commented 2 years ago

I found the bug 🎉

There is a double call to "setValue" function when unselecting last value. It causes your changes to be overridden by an empty array.

In "CustomSelect" component, there is an "onChange" function (https://github.com/xrutayisire/react-js-cron/blob/4fdcae1b08a26868fb5ab2fd48f6c491b639ade7/src/components/CustomSelect.tsx#L208) that I used to be able to clear the value. The problem is that the onChange function also trigger it when you manually clear the value by unselecting last value :/

I can fix this bug easily because when I started this library, antd (v4.2.5) didn't have an onClear function, so I had to use the "onChange" function. But since version 4.6.0 antd added an "onClear" function!

I will release a hotfix soon!

Xavier

xrutayisire commented 2 years ago

v1.3.1 is released with the fix! 🎉

Your use case should word now 💯 You can reopen this issue if you still have a problem.

Have a good day!