-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(module:DatePicker&RangePicker): OneOf to TValue, default value for picker, optimizations #933
fix(module:DatePicker&RangePicker): OneOf to TValue, default value for picker, optimizations #933
Conversation
DefaultValue type change to align with Value type
Picker value is served based on input index (start/end)
ViewStartDate, MaxRow & MaxCol do not cause refresh if not changed
ArgumentOutOfRangeException fix for dates before DateTime.MinValue
Values get ordered on set
PickerValue fix gets first panel value and evaluates second panel value
Thanks for contribution @anddrzejb . We may need some time to review it. |
I would be surprised if you just accepted it 😄. I'll be waiting for comments/input/changes/etc. |
/preview |
@anddrzejb Thanks for your pr! It's great, but i found an issue here. |
@mutouzdl thanks for pointing that out. I fixed it. When checking I also noticed some other issues. My second commit addresses the scenario when It seems the check has failed in the areas that I have not touched. The app is building and running successfully on my machine. I run all the tests present in the app and they were successful. |
@anddrzejb Hi, here has 1 failing check |
@mutouzdl yeah, I mentioned that. Last 4 PR have exactly the same check fail - there seems to be a problem with |
I will fix it later today. |
Codecov Report
@@ Coverage Diff @@
## master #933 +/- ##
=========================================
+ Coverage 5.49% 5.75% +0.26%
=========================================
Files 405 406 +1
Lines 21532 21702 +170
=========================================
+ Hits 1184 1250 +66
- Misses 20348 20452 +104
Continue to review full report at Codecov.
|
…ptimizations (#933) * fix(module:DatePicker): input OnClick has new event handler * fix(module:DateTime): remove misleading reliance on picker index * fix(module: DatePicker & RangePicker): DefaultValue type change DefaultValue type change to align with Value type * fix(module:rangepicker): add default values helper with tests * fix(module:datepicker): ChangePickerValue action declaration fix Picker value is served based on input index (start/end) * fix(module:DatePicker): optimization ViewStartDate, MaxRow & MaxCol do not cause refresh if not changed * fix(module:DatePicker): min date fix ArgumentOutOfRangeException fix for dates before DateTime.MinValue * fix(module:RangePicker): sorted values Values get ordered on set * fix(module:DatePicker): OneOf switch to TValue * fix(module:DatePicker): code optimization and PickerValue fix PickerValue fix gets first panel value and evaluates second panel value * fix(module:DatePicker): default values evaluation * fix(module:RangePicker): default picker value fix * docs(module:DatePicker): switch to TValue for DefaultValue * fix(module:RangePicker): other value picker fix * fix(module:RangePicker): on value init include DefaultValue Co-authored-by: James Yeung <shunjiey@hotmail.com>
…ptimizations (#933) * fix(module:DatePicker): input OnClick has new event handler * fix(module:DateTime): remove misleading reliance on picker index * fix(module: DatePicker & RangePicker): DefaultValue type change DefaultValue type change to align with Value type * fix(module:rangepicker): add default values helper with tests * fix(module:datepicker): ChangePickerValue action declaration fix Picker value is served based on input index (start/end) * fix(module:DatePicker): optimization ViewStartDate, MaxRow & MaxCol do not cause refresh if not changed * fix(module:DatePicker): min date fix ArgumentOutOfRangeException fix for dates before DateTime.MinValue * fix(module:RangePicker): sorted values Values get ordered on set * fix(module:DatePicker): OneOf switch to TValue * fix(module:DatePicker): code optimization and PickerValue fix PickerValue fix gets first panel value and evaluates second panel value * fix(module:DatePicker): default values evaluation * fix(module:RangePicker): default picker value fix * docs(module:DatePicker): switch to TValue for DefaultValue * fix(module:RangePicker): other value picker fix * fix(module:RangePicker): on value init include DefaultValue Co-authored-by: James Yeung <shunjiey@hotmail.com>
🤔 This is a ...
🔗 Related issue link
Value
was generic butDefaultValue
andDefaultPickerValue
wereOneOf<DateTime, DateTime[]>
. That approach was allowing calls like this:and there was no warning from the compiler. However during runtime
NullReferenceException
was being thrown due to inconsistent data types.3.
DatePicker
andRangePicker
were handling the same type of events in a different way: inRangePicker
there is a separateOnInputClick
method to handleOnClick
event. InDatePicker
there is no such method, instead this codeawait _dropDown.Show(); ChangeFocusTarget(true, false);
is executed.4. (Appeared after fixing #906) For
RangePicker
a 2-panel picker is shown for eachinput
. Every 2-panel picker should set its 1st panel to a default value and 2nd panel should be pointing to next period (for month view - next month, for year view - next decade, etc). The method to pick up values for panels were taking both values for both panels. So ifValue = { "2020-10-10", "2021-10-10" }
, then for:inputStart
) 1st panel was showing "2020-10-10",inputStart
) 2nd was showing "2021-10-10" (instead of 1st panel + 1 month)inputEnd
) 1st panel was showing "2020-10-10" (instead of "2021-10-10"),inputEnd
) 2nd was showing "2021-10-10" (instead of 1st panel + 1 month)The analysis was made by comparing how ant-design react is behaving.
Value
,DefaultValue
,DefaultPickerValue
were not returning expected results (in comparison to what ant-design react is returning).RangePicker
Values are not sorted, so a picker could be shown with start set after the end. The values are sorted by ant-design react.💡 Background and solution
When picker is shown, data is fetched from
![datePickerChart](https://user-images.githubusercontent.com/6518006/103240482-26fd8d00-4959-11eb-88c4-23b43dea45a6.png)
PickerValue
. That value was not properly initiated. That value should be initiated during initialization of the the component, and then changed whenever a new value is selected. However the value(s) inPickerValue
can be different depending on combination ofValue
,DefaultValue
,DefaultPickerValue
. A new static classRangePickerDefaults
has been introduced to handleRangePicker.PickerValue
scenarios (includes also tests covering most of the combinations). ForDatePicker
evaluation of thePickerValue
is simple and was included in theProcessDefaults()
method that is called in theOnInitialized()
method.The default evaluation follows the table (based on analysis of the ant-design react)(forgive my excel skills...):
Ad. 2.
OneOf<DateTime, DateTime[]>
was replaced with genericTValue
.### This is a breaking change
For example, due to the change to
TValue
, the docs files Disabled.razor and Format.razor (check commit 3c2024c) had to be altered because the compiler was raising an error. I do think this is desirable, but if this is going to be accepted, should probably be noted in the changelog.Ad. 3. Handling of the events had been unified (commit d03518e)
Ad. 4. This change required fixes in multiple files. A change was required to actually rely on current active input index instead of on passed index value. It is still allowed to pass the index value (and is useful in certain scenarios) but most scenarios actually no longer send this value.
As a side note: commit 076c77f changed
index
value for picker to hardcoded value0
- this is forDatePicker
where onlyindex==0
is used, so to avoid any mistake I made it clear this refers only to a single (first) value.Ad. 6.
SortValue
method was added toDatePickerBase
class. It is called wheneverValue
,DefaultValue
orDefaultPickerValue
is set/changed. It also required to alterIsNullable
evaluation.Commit 72b3067 addresses certain optimization issue I discovered: pickers seems to be initialized multiple times. I could not track all the reasons of multiple initializations, but I found that not changing
MaxCol
,MaxRow
andViewStartDate
limitted a bit that number. Still, there is still a lot of things happening, even when picker is hidden (after first time it is shown - the dates for pickers seem to be constantly recalculated on each mouse move even if picker is not visible - this does require more research).In this PR I multiple times referred to original ant-design for react as my reference whenever I was not sure how should the picker in question behave. Most of the times, I was trying to follow the original. That is why I created the chart. The choices made by the original ant-design for the behaviours are justifiable - even if someone argues that a certain result is not what he/she expected, it is still logically explainable. However certain values are not identical - for example the minimum value. This is because Javascript is a weakly typed language, so there is no differentiation between nullable and non-nullable (at least not to my knowledge). So I was trying to follow the logic that if it is not nullable, then it is minimum. Therefore the presence of minimum that does not really exists in ant-design react (unless manually set as a value).
Second issue I had with original ant-design react - range picker does not follow the logic of date picker. To be honest, I do not know what logic it follows... I couldn't figure it out (granted, I did not spent a long time on it). So I decided to actually follow the same logic as for
DatePicker
(I used the chart) - this seemed most intuitive. I do not think using a different logic forDatePicker
andRangePicker
would add to user experience...📝 Changelog
DefaultValue
andDefaultPickerValue
have to be of the same type asValue
, but still can be null or can be omitted.☑️ Self Check before Merge