-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
refactor(date picker): Migrate Date Picker to Ant Design 5 #31019
refactor(date picker): Migrate Date Picker to Ant Design 5 #31019
Conversation
…com/msyavuz/superset into msyavuz/refactor/migrate-datepicker
Can't believe we're finally getting rid of moment.js! Amazing job @msyavuz. The code looks good to me besides a small nitpick, manual testing in progress |
superset-frontend/packages/superset-ui-chart-controls/src/constants.ts
Outdated
Show resolved
Hide resolved
Docker build keeps failing, but I can compile the code locally without any problem. @mistercrunch can it be related to your recent docker changes? |
/testenv up |
@kgabryje Ephemeral environment spinning up at http://34.209.140.91:8080. Credentials are |
@msyavuz I'm getting an error when I do the following:
Interestingly, I can just close this error (with x in top right corner) and then everything seems to be working fine - I'm able to select a date with the date picker |
@kgabryje This revealed a deeper issue which is not using locales in all datepickers. I extracted a useLocale hook from CustomFrame to enable setting locale individually on other places. So now filter control datepickers should respect the locale as well. Also fixed the error :) |
superset-frontend/webpack.config.js
Outdated
@@ -160,11 +160,6 @@ const plugins = [ | |||
chunks: [], | |||
filename: '500.html', | |||
}), | |||
// Dayjs locales to keep | |||
new webpack.ContextReplacementPlugin( |
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.
Shouldn’t we keep this plugin to trim unsupported locales from the bundle?
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.
Looks great! Thanks again for the contribution!
}} | ||
/> | ||
</RangeFilterContainer> | ||
<AntdThemeProvider locale={locale}> |
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.
Noticed this while rebasing my large theming PR, but we won't want to re-inject the AntdThemeProvider in multiple places. My PR will clean this up and load it once and only once
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 did that because I don't know if modifying global theme provider is something we want. Some components might not want to be localized.
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.
Yes, looking at what is needed here it seems it will fetch some local configuration async and isn't ready to render until those locale files are loaded, so we really don't want that at the base of the tree (aka in the main ThemeProvider) and delay the first render. It's important to not hold up the main tree which is what is happening here.
Now, knowing that it must be inject more dynamically or on-demand, it'd be great for it to be DRY (single injection point if/where needed) and for the fetch-locale logic to be cached to it only happens once in the SPA. I didn't review the logic here to see whether there's any caching, but squeezing it in the client-side cache somewhere seems important.
Now how should the components that need it get it? Maybe some sort of reusable AntdLocaleProvider decorator or something simple like that, where components that need would just wrap themselves with it (?) That wrapper itself could take care of the caching with some way to share that locale
object with other instances of that same component.
? (triggerNode.parentNode as HTMLElement) | ||
: document.body | ||
} | ||
<AntdThemeProvider locale={datePickerLocale}> |
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.
same here, we don't want to sprinkly theme providers in the react tree...
import { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { ExplorePageState } from 'src/explore/types'; | ||
import 'dayjs/locale/en'; |
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.
how bad is all this on bundle size?
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.
Bundle size is not affected since we used to import these before as well
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.
@mistercrunch I verified this before approving, the PR decreases the bundle size thanks to removing moment, the size of those locales is negligible
SUMMARY
Migrate Datepicker to Ant Design 5 while also finishing the migration to Dayjs in Datepicker related components.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
After:
TESTING INSTRUCTIONS
Run the testing suite / Check for visual changes
ADDITIONAL INFORMATION