-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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(Changing languages doesn't affect echarts charts): issue 30131 #31751
base: master
Are you sure you want to change the base?
Conversation
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Unsafe Dynamic Module Import ▹ view | ✅ | |
Missing Locale Fallback ▹ view | ✅ | |
Missing locale state fallback ▹ view | ✅ |
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
@@ -123,10 +127,14 @@ function Echart( | |||
getEchartInstance: () => chartRef.current, | |||
})); | |||
|
|||
const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale); | |||
const lang = require('echarts/lib/i18n/lang' + localeObj.toUpperCase()).default; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
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.
Thank you for submitting this PR @jpchev , you beat me to it :)
With just a few small changes, this is working well for me.
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
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 change is working great! Thank you @jpchev :)
- I tested this by combining it with fix(lang): patch FAB's LocaleView to redirect to previous page #31692 to test changing languages while viewing and editing the Pie Chart echart. I verified that this change ensures the "Inv" and "All" buttons on that echart are now translated as expected.
- I read through the code
translate.echarts.mp4
@villebro might be most qualified to look at this one, if he has time. That said, there are some failing tests that could use attention, and a more descritive PR title could help too :D |
sorry for the cryptic title, I've put the title of the issue it fixes. I know it's not recommended, but I don't know how to dynamically import a js file without using 'require'. |
const locale = useSelector( | ||
(state: ExplorePageState) => state?.common?.locale ?? 'en', | ||
).toUpperCase(); | ||
try { | ||
const lang = require(`echarts/lib/i18n/lang${locale}`).default; | ||
registerLocale(locale, lang); | ||
} catch (e) { | ||
console.warn(`Locale ${locale} not supported in ECharts`); | ||
} | ||
|
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.
@jpchev I think we need to use dynamic imports instead, but they're tricky to use in React. I tried a few ways and wasn't able to get it to render properly, so am asking the bot:
@dosu how do we refactor this to ensure we await the import
and registerLocale
calls before calling init
below?
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.
Reply is here: #30131 (comment)
But it doesn't work :(
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, I tried something similar, without success. That's why I went for require.
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.
@pomegranited I fixed almost all the checks, there is this one left which I don't how to treat https://github.com/apache/superset/actions/runs/12949242972/job/36119814005?pr=31751 do you have an idea? It seems there are errors also on files not impacted by changes in this PR,
|
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/package-lock.json
Outdated
@@ -50218,6 +50218,14 @@ | |||
"version": "4.2.0", | |||
"license": "MIT" | |||
}, | |||
"node_modules/superset": { |
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.
Could you revert these changes? I don't think they're needed.
@pomegranited I've pushed again my code from scratch, in order to resolve the conflict on superset-frontend/package-lock.json I think it needs again to be approved |
bba5d7a
to
0c8010c
Compare
e19e66c
to
e4bdb28
Compare
@pomegranited all checks pass now |
all tests pass now, @villebro @michael-s-molina could you please have a look if it is ok? Thank you |
@pomegranited do you have news? It seems this PR can be merged, all tests pass and we fixed all the detected issues |
@jpchev I have no news -- we're just waiting for upstream to review and merge here. |
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.
Thanks for taking this up! A few comments, LMKWYT.
"lodash": "^4.17.21", | ||
"dayjs": "^1.11.13" | ||
"dayjs": "^1.11.13", | ||
"lodash": "^4.17.21" |
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.
not your fault, but isn't lodash
a peer dependency?
// Define this interface here to avoid creating a dependency back to superset-frontend, | ||
// and to appease the compiler. | ||
// ref: superset-frontend/src/explore/types | ||
interface ExplorePageState { | ||
common: { | ||
locale: string; | ||
}; | ||
} |
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.
Oof.. I agree with the workaround here, but could we rephrase the comment to a // TODO:
to move the type to @superset-ui/core
?
@@ -123,24 +134,52 @@ function Echart( | |||
getEchartInstance: () => chartRef.current, | |||
})); | |||
|
|||
const locale = useSelector( | |||
(state: ExplorePageState) => state?.common?.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.
nit: Instead of having a magic string in the codebase, it would be nice to move this to src/constants.ts
as DEFAULT_LOCALE = 'en';
or similar.
This is looking great! Re-running a failing (and probably just flaky) CI check. |
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.
One last comment
@@ -24,6 +24,7 @@ | |||
"lib" | |||
], | |||
"dependencies": { | |||
"@types/react-redux": "^7.1.10", |
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 this be devDependencies
?
@rusackas Ephemeral environment spinning up at http://54.186.129.54:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
@@ -33,7 +33,8 @@ | |||
"@superset-ui/core": "*", | |||
"echarts": "*", | |||
"memoize-one": "*", | |||
"react": "^17.0.2" | |||
"react": "^17.0.2", | |||
"@types/react-redux": "^7.1.10" |
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'm not sure why we'd want to have this under peerDepdendencies
- let's just move it under devDependencies
.
SUMMARY
this is to propagate the current locale up to the echarts configuration.
fixes: #30131
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
switch the locale and verify that charts have the correct locale (for example in months name and in buttons)