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

fix(Changing languages doesn't affect echarts charts): issue 30131 #31751

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

jpchev
Copy link
Contributor

@jpchev jpchev commented Jan 8, 2025

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)

Copy link

@korbit-ai korbit-ai bot left a 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
Functionality Unsafe Dynamic Module Import ▹ view
Functionality Missing Locale Fallback ▹ view
Error Handling 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.

@jpchev jpchev changed the title fixes for https://github.com/apache/superset/issues/30131 fix(issue): 30131 Jan 8, 2025
Copy link
Contributor

@pomegranited pomegranited left a 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.

Copy link
Contributor

@pomegranited pomegranited left a 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 :)

translate.echarts.mp4

@rusackas
Copy link
Member

rusackas commented Jan 22, 2025

@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

@jpchev jpchev changed the title fix(issue): 30131 fix(Changing languages doesn't affect echarts charts): 30131 Jan 22, 2025
@jpchev jpchev changed the title fix(Changing languages doesn't affect echarts charts): 30131 fix(Changing languages doesn't affect echarts charts): issue 30131 Jan 22, 2025
@jpchev
Copy link
Contributor Author

jpchev commented Jan 22, 2025

@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.
Also, I see one of the checks fails because I used the 'require' import

https://github.com/apache/superset/actions/runs/12825802735/job/35764682648?pr=31751#step:4:4582

I know it's not recommended, but I don't know how to dynamically import a js file without using 'require'.
There is an async alternative, but that would make the code much less clear, in my opinion.

Comment on lines 130 to 149
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`);
}

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpchev I found the culprit! handleSizeChange wasn't running because of race conditions on render.

See jpchev#2

@jpchev
Copy link
Contributor Author

jpchev commented Jan 24, 2025

@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,
for instance

@superset-ui/plugin-chart-echarts: ../../scripts/tsc.sh: line 25: exit: ../../src/components/Icons/Icon.tsx(23,29): error TS2307: Cannot find module 'src/assets/images/icons/transparent.svg' or its corresponding type declarations.

@@ -50218,6 +50218,14 @@
"version": "4.2.0",
"license": "MIT"
},
"node_modules/superset": {
Copy link
Contributor

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.

@jpchev
Copy link
Contributor Author

jpchev commented Jan 29, 2025

@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

@jpchev jpchev reopened this Jan 29, 2025
@jpchev
Copy link
Contributor Author

jpchev commented Jan 29, 2025

@pomegranited all checks pass now

@jpchev
Copy link
Contributor Author

jpchev commented Jan 31, 2025

all tests pass now,
but due to a merge conflict I had to remove all my commits and push again,
and that closed the PR, so I had to reopen again and that requires again your approval.

@villebro @michael-s-molina could you please have a look if it is ok?

Thank you

@jpchev
Copy link
Contributor Author

jpchev commented Feb 7, 2025

@pomegranited do you have news? It seems this PR can be merged, all tests pass and we fixed all the detected issues

@pomegranited
Copy link
Contributor

@jpchev I have no news -- we're just waiting for upstream to review and merge here.

@rusackas rusackas requested a review from kgabryje February 19, 2025 23:34
Copy link
Member

@villebro villebro left a 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"
Copy link
Member

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?

Comment on lines 66 to 73
// 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;
};
}
Copy link
Member

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

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.

@rusackas
Copy link
Member

This is looking great! Re-running a failing (and probably just flaky) CI check.

Copy link
Contributor

@rusackas Processing your ephemeral environment request here. Action: up.

Copy link
Member

@villebro villebro left a 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",
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 this be devDependencies?

Copy link
Contributor

@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"
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing languages doesn't affect echarts charts.
5 participants