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

refactor(date picker): Migrate Date Picker to Ant Design 5 #31019

Merged
merged 47 commits into from
Jan 13, 2025

Conversation

msyavuz
Copy link
Contributor

@msyavuz msyavuz commented Nov 21, 2024

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:
image
After:
image

TESTING INSTRUCTIONS

Run the testing suite / Check for visual changes

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Ant Design 5: Upgrade DatePicker component #30910
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@geido geido added the preset:bounty Issues that have been selected by Preset and have a bounty attached. label Dec 2, 2024
@kgabryje
Copy link
Member

kgabryje commented Jan 7, 2025

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

@kgabryje
Copy link
Member

kgabryje commented Jan 7, 2025

Docker build keeps failing, but I can compile the code locally without any problem. @mistercrunch can it be related to your recent docker changes?

@kgabryje
Copy link
Member

kgabryje commented Jan 9, 2025

/testenv up

Copy link
Contributor

github-actions bot commented Jan 9, 2025

@kgabryje Processing your ephemeral environment request here.

Copy link
Contributor

github-actions bot commented Jan 9, 2025

@kgabryje Ephemeral environment spinning up at http://34.209.140.91:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@kgabryje
Copy link
Member

kgabryje commented Jan 9, 2025

@msyavuz I'm getting an error when I do the following:

  • add a time range filter on a dashboard
  • open that filter
  • go to "custom"
image

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

@msyavuz
Copy link
Contributor Author

msyavuz commented Jan 9, 2025

@msyavuz I'm getting an error when I do the following:

* add a time range filter on a dashboard

* open that filter

* go to "custom"
image

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 :)

@@ -160,11 +160,6 @@ const plugins = [
chunks: [],
filename: '500.html',
}),
// Dayjs locales to keep
new webpack.ContextReplacementPlugin(
Copy link
Member

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?

Copy link
Member

@kgabryje kgabryje left a 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!

@geido geido merged commit b5e6275 into apache:master Jan 13, 2025
50 checks passed
}}
/>
</RangeFilterContainer>
<AntdThemeProvider locale={locale}>
Copy link
Member

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

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 did that because I don't know if modifying global theme provider is something we want. Some components might not want to be localized.

Copy link
Member

@mistercrunch mistercrunch Jan 15, 2025

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}>
Copy link
Member

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';
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

@kgabryje kgabryje Jan 15, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:frontend Requires changing the frontend dependencies:npm frontend:refactor:antd5 packages preset:bounty Issues that have been selected by Preset and have a bounty attached. review:draft size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ant Design 5: Upgrade DatePicker component
5 participants