-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(DateTimeControl): Add DateTimeControl to default renderers #102
Conversation
package.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antd uses dayjs under the hood, but in order to coerce initial values from string
to dayjs
format we need to import dayjs into this component to parse the string.
src/antd/InputNumber.tsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type was declared but unused inside this component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding format optionally here allows us to distinguish between normal strings and date-time strings.
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #102 +/- ##
==========================================
+ Coverage 74.80% 77.11% +2.30%
==========================================
Files 38 40 +2
Lines 504 533 +29
Branches 96 102 +6
==========================================
+ Hits 377 411 +34
+ Misses 90 83 -7
- Partials 37 39 +2 ☔ View full report in Codecov by Sentry. |
6f62186
to
5db15e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried out the storybook (sweet!!!). Couldn't find a single nit in the code. 🚀 🚀 🚀
5db15e4
to
33ff832
Compare
? U extends "object" // ObjectControlOptions goes here | ||
? unknown | ||
: U extends "string" | ||
? TextControlOptions | ||
? F extends "date-time" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
* can be found in [this section](https://ant.design/components/date-picker#datepicker) | ||
* of the antd docs. | ||
*/ | ||
export const allowedDateTimePropKeys: (keyof DatePickerProps)[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If antd adds a property to DatePickerProps, this will compile just fine, but uischemas using the new properties will get rejected at runtime by isDateTimeControlOptions.
To facilitate keeping it up to date more easily, you can write a conditional type that evaluates to true
if all of the values in DatePickerProps are contained in this array, and to never
if some values in DatePickerProps are not contained in this array, and then write a variable assignment with that type, assigning it to true
. That way if new values are added, our code won't compile =)
if (!visible) return null | ||
|
||
const initialValue = | ||
typeof schema.default === "string" ? dayjs(schema.default) : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using our own instance of dayjs isn't ideal (or even using a hardcoded timezone library since AntD lets you generate time-based ui controls with your own library) and may cause problems in any app that has a configurable timezone, but I think it's ok for us to use it here since AntD does a pretty poor job making the timezone configurable (it doesn't, and it overrides any default you set on dayjs 😕). If we wanted to support configurable timezones, we'd have to use the generatePicker function and probably accept a datetimelibraryconfig object (inside of jsonforms's config) that contains library-specific details that we could use to generate the AntD DateTime component.
ant-design/ant-design#47490 (comment)
🎉 This PR is included in version 1.22.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
date-time
with a priorty of3
.uiSchema.options
interface typed via updating the existing option type helper.