From a8b908a418b8c4bb18b91c11c23120a8e4bb5108 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 29 Jan 2025 15:23:03 +0100 Subject: [PATCH 01/18] changes --- .../plugins/plugin-chart-echarts/package.json | 7 +- .../src/components/Echart.tsx | 86 ++++++++++++------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index f84ecd0ed4ac..0aa75f3afbfc 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -24,16 +24,17 @@ "lib" ], "dependencies": { + "@types/react-redux": "^7.1.34", "d3-array": "^1.2.0", - "lodash": "^4.17.21", - "dayjs": "^1.11.13" + "dayjs": "^1.11.13", + "lodash": "^4.17.21" }, "peerDependencies": { "@superset-ui/chart-controls": "*", "@superset-ui/core": "*", "echarts": "*", "memoize-one": "*", - "react": "^17.0.2" + "react": "^16.13.1" }, "publishConfig": { "access": "public" diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 995e3a535134..8350d1128439 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -27,8 +27,10 @@ import { Ref, } from 'react'; +import { useSelector } from 'react-redux'; + import { styled } from '@superset-ui/core'; -import { use, init, EChartsType } from 'echarts/core'; +import { use, init, EChartsType, registerLocale } from 'echarts/core'; import { SankeyChart, PieChart, @@ -61,6 +63,15 @@ import { import { LabelLayout } from 'echarts/features'; import { EchartsHandler, EchartsProps, EchartsStylesProps } from '../types'; +// 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; + }; +}; + const Styles = styled.div` height: ${({ height }) => height}; width: ${({ width }) => width}; @@ -123,24 +134,52 @@ function Echart( getEchartInstance: () => chartRef.current, })); + const locale = useSelector( + (state: ExplorePageState) => state?.common?.locale ?? 'en', + ).toUpperCase(); + + const handleSizeChange = useCallback( + ({ width, height }: { width: number; height: number }) => { + if (chartRef.current) { + chartRef.current.resize({ width, height }); + } + }, + [], + ); + useEffect(() => { - if (!divRef.current) return; - if (!chartRef.current) { - chartRef.current = init(divRef.current); - } + const loadLocaleAndInitChart = async () => { + if (!divRef.current) return; - Object.entries(eventHandlers || {}).forEach(([name, handler]) => { - chartRef.current?.off(name); - chartRef.current?.on(name, handler); - }); + const lang = await import(`echarts/lib/i18n/lang${locale}`).catch(e => { + console.error(`Locale ${locale} not supported in ECharts`, e); + }); + if (lang?.default) { + registerLocale(locale, lang.default); + } - Object.entries(zrEventHandlers || {}).forEach(([name, handler]) => { - chartRef.current?.getZr().off(name); - chartRef.current?.getZr().on(name, handler); - }); + if (!chartRef.current) { + chartRef.current = init(divRef.current, null, { locale }); + } - chartRef.current.setOption(echartOptions, true); - }, [echartOptions, eventHandlers, zrEventHandlers]); + Object.entries(eventHandlers || {}).forEach(([name, handler]) => { + chartRef.current?.off(name); + chartRef.current?.on(name, handler); + }); + + Object.entries(zrEventHandlers || {}).forEach(([name, handler]) => { + chartRef.current?.getZr().off(name); + chartRef.current?.getZr().on(name, handler); + }); + + chartRef.current.setOption(echartOptions, true); + + // did mount + handleSizeChange({ width, height }); + }; + + loadLocaleAndInitChart(); + }, [echartOptions, eventHandlers, zrEventHandlers, locale]); // highlighting useEffect(() => { @@ -158,22 +197,7 @@ function Echart( }); } previousSelection.current = currentSelection; - }, [currentSelection]); - - const handleSizeChange = useCallback( - ({ width, height }: { width: number; height: number }) => { - if (chartRef.current) { - chartRef.current.resize({ width, height }); - } - }, - [], - ); - - // did mount - useEffect(() => { - handleSizeChange({ width, height }); - return () => chartRef.current?.dispose(); - }, []); + }, [currentSelection, chartRef.current]); useLayoutEffect(() => { handleSizeChange({ width, height }); From d42fe2166cc401b5dd108030f65b4866b6f0e91c Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 29 Jan 2025 15:55:44 +0100 Subject: [PATCH 02/18] prettier --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 8350d1128439..8d54ccd5f135 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -63,14 +63,14 @@ import { import { LabelLayout } from 'echarts/features'; import { EchartsHandler, EchartsProps, EchartsStylesProps } from '../types'; -// Define this interface here to avoid creating a dependency back to superset-frontend, +// 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; }; -}; +} const Styles = styled.div` height: ${({ height }) => height}; From a54c883edc62db3b9baee5c843247b29b80a53c2 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 29 Jan 2025 15:44:54 +0100 Subject: [PATCH 03/18] fixed react version in plugin-char-echarts/package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index 0aa75f3afbfc..388fc8f72227 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -34,7 +34,7 @@ "@superset-ui/core": "*", "echarts": "*", "memoize-one": "*", - "react": "^16.13.1" + "react": "^17.0.2" }, "publishConfig": { "access": "public" From 4fad789d7868e5034d7c569e4a5915a8116f7384 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 30 Jan 2025 09:34:51 +0100 Subject: [PATCH 04/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index 388fc8f72227..01763f3078af 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -24,7 +24,7 @@ "lib" ], "dependencies": { - "@types/react-redux": "^7.1.34", + "@types/react-redux": "^7.1.10", "d3-array": "^1.2.0", "dayjs": "^1.11.13", "lodash": "^4.17.21" From 7090e9fdeb9539f2c0c13106056a07822e0adc5c Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 20 Feb 2025 17:38:16 +0100 Subject: [PATCH 05/18] Update Echart.tsx --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 8d54ccd5f135..254d1b02983e 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -64,8 +64,7 @@ import { LabelLayout } from 'echarts/features'; import { EchartsHandler, EchartsProps, EchartsStylesProps } from '../types'; // Define this interface here to avoid creating a dependency back to superset-frontend, -// and to appease the compiler. -// ref: superset-frontend/src/explore/types +// TODO: to move the type to @superset-ui/core interface ExplorePageState { common: { locale: string; From 591fae178f16bde9ff7a4133401371538fba1417 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 20 Feb 2025 17:39:17 +0100 Subject: [PATCH 06/18] Update constants.ts --- superset-frontend/plugins/plugin-chart-echarts/src/constants.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts index 65ea1679e2c1..ce4f71d889c4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts @@ -121,3 +121,5 @@ export const TOOLTIP_POINTER_MARGIN = 10; // If no satisfactory position can be found, how far away // from the edge of the window should the tooltip be kept export const TOOLTIP_OVERFLOW_MARGIN = 5; + +export const DEFAULT_LOCALE = 'en' From 9c6207d0511e9df102aaa0fe1f7c97fda6205c36 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 20 Feb 2025 17:39:31 +0100 Subject: [PATCH 07/18] Update constants.ts --- superset-frontend/plugins/plugin-chart-echarts/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts index ce4f71d889c4..fb6221342a40 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts @@ -122,4 +122,4 @@ export const TOOLTIP_POINTER_MARGIN = 10; // from the edge of the window should the tooltip be kept export const TOOLTIP_OVERFLOW_MARGIN = 5; -export const DEFAULT_LOCALE = 'en' +export const DEFAULT_LOCALE = 'en'; From 6302c74358f95d183b602d72a5624af939e1f981 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 20 Feb 2025 17:42:12 +0100 Subject: [PATCH 08/18] Update Echart.tsx --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 254d1b02983e..5f5f71c14bd6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -62,6 +62,7 @@ import { } from 'echarts/components'; import { LabelLayout } from 'echarts/features'; import { EchartsHandler, EchartsProps, EchartsStylesProps } from '../types'; +import { DEFAULT_LOCALE } from '../constants'; // Define this interface here to avoid creating a dependency back to superset-frontend, // TODO: to move the type to @superset-ui/core @@ -134,7 +135,7 @@ function Echart( })); const locale = useSelector( - (state: ExplorePageState) => state?.common?.locale ?? 'en', + (state: ExplorePageState) => state?.common?.locale ?? DEFAULT_LOCALE, ).toUpperCase(); const handleSizeChange = useCallback( From 1fa75ef8a74151300d16d9c2123f0645d4ae3225 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 20 Feb 2025 17:44:33 +0100 Subject: [PATCH 09/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index 01763f3078af..e5334817c6c6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -26,8 +26,8 @@ "dependencies": { "@types/react-redux": "^7.1.10", "d3-array": "^1.2.0", - "dayjs": "^1.11.13", - "lodash": "^4.17.21" + "lodash": "^4.17.21", + "dayjs": "^1.11.13" }, "peerDependencies": { "@superset-ui/chart-controls": "*", From 9f5d050a15a75d8c4a6ffe00375fd772e81935ea Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Fri, 21 Feb 2025 09:43:13 +0100 Subject: [PATCH 10/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index e5334817c6c6..c3cb372b6e3a 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -24,7 +24,6 @@ "lib" ], "dependencies": { - "@types/react-redux": "^7.1.10", "d3-array": "^1.2.0", "lodash": "^4.17.21", "dayjs": "^1.11.13" @@ -34,7 +33,8 @@ "@superset-ui/core": "*", "echarts": "*", "memoize-one": "*", - "react": "^17.0.2" + "react": "^17.0.2", + "@types/react-redux": "^7.1.10" }, "publishConfig": { "access": "public" From 0a31c94d32872a5b175ac7b070f33a8d89197b23 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Fri, 21 Feb 2025 18:19:56 +0100 Subject: [PATCH 11/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index c3cb372b6e3a..c6083a2bb1f4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -33,7 +33,9 @@ "@superset-ui/core": "*", "echarts": "*", "memoize-one": "*", - "react": "^17.0.2", + "react": "^17.0.2" + }, + "devDependencies": { "@types/react-redux": "^7.1.10" }, "publishConfig": { From 48d007f361082d8297697f0b992b2db4adf56053 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Tue, 4 Mar 2025 00:26:01 +0100 Subject: [PATCH 12/18] modified linter to let devDependencies contain types --- superset-frontend/.eslintrc.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 3d5e04cde0dd..751aaea523a3 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -238,7 +238,9 @@ module.exports = { rules: { 'import/no-extraneous-dependencies': [ 'error', - { devDependencies: true }, + { + "devDependencies": ["**/*.test.js", "**/*.spec.js"] + }, ], 'no-only-tests/no-only-tests': 'error', 'max-classes-per-file': 0, From 87121424a2f5b6432aba38fcc62db58fd406644b Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Tue, 4 Mar 2025 00:36:33 +0100 Subject: [PATCH 13/18] Update .eslintrc.js --- superset-frontend/.eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 751aaea523a3..81194d36c139 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -239,7 +239,7 @@ module.exports = { 'import/no-extraneous-dependencies': [ 'error', { - "devDependencies": ["**/*.test.js", "**/*.spec.js"] + "devDependencies": ["**/*.test.tsx", "**/*.test.jsx", "**/*.test.ts"] }, ], 'no-only-tests/no-only-tests': 'error', From c95cd3322c6b99f5643d1bd92c94188ca9b1e920 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Tue, 4 Mar 2025 00:47:02 +0100 Subject: [PATCH 14/18] Update .eslintrc.js --- superset-frontend/.eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 81194d36c139..5315c249abf0 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -239,7 +239,7 @@ module.exports = { 'import/no-extraneous-dependencies': [ 'error', { - "devDependencies": ["**/*.test.tsx", "**/*.test.jsx", "**/*.test.ts"] + "devDependencies": ["**/*.test.tsx", "**/*.test.js", "**/*.test.jsx", "**/*.test.ts", "**/*.stories.tsx", "**/*.fixtures.ts"] }, ], 'no-only-tests/no-only-tests': 'error', From 2f96ce03483f5238bf8d0e01ae866cc85333b7f9 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Tue, 4 Mar 2025 10:11:50 +0100 Subject: [PATCH 15/18] Update .eslintrc.js --- superset-frontend/.eslintrc.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 5315c249abf0..3d5e04cde0dd 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -238,9 +238,7 @@ module.exports = { rules: { 'import/no-extraneous-dependencies': [ 'error', - { - "devDependencies": ["**/*.test.tsx", "**/*.test.js", "**/*.test.jsx", "**/*.test.ts", "**/*.stories.tsx", "**/*.fixtures.ts"] - }, + { devDependencies: true }, ], 'no-only-tests/no-only-tests': 'error', 'max-classes-per-file': 0, From 417274abbbf369158f5377d56d460547104358df Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Tue, 4 Mar 2025 10:22:23 +0100 Subject: [PATCH 16/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index c6083a2bb1f4..64da86afdcc8 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -26,7 +26,8 @@ "dependencies": { "d3-array": "^1.2.0", "lodash": "^4.17.21", - "dayjs": "^1.11.13" + "dayjs": "^1.11.13", + "@types/react-redux": "^7.1.10" }, "peerDependencies": { "@superset-ui/chart-controls": "*", @@ -35,9 +36,6 @@ "memoize-one": "*", "react": "^17.0.2" }, - "devDependencies": { - "@types/react-redux": "^7.1.10" - }, "publishConfig": { "access": "public" } From 00493dce5f8bfec7fbec63185cc9fcce5f4b2199 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 19 Mar 2025 08:58:36 +0100 Subject: [PATCH 17/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index 64da86afdcc8..b56d82f45662 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -23,11 +23,13 @@ "esm", "lib" ], + "devDependencies": { + "@types/react-redux": "^7.1.10" + }, "dependencies": { "d3-array": "^1.2.0", "lodash": "^4.17.21", - "dayjs": "^1.11.13", - "@types/react-redux": "^7.1.10" + "dayjs": "^1.11.13" }, "peerDependencies": { "@superset-ui/chart-controls": "*", From 3f34a419145094e8045463456e4567b2bd3466c6 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 19 Mar 2025 18:32:37 +0100 Subject: [PATCH 18/18] Update package.json --- superset-frontend/plugins/plugin-chart-echarts/package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/package.json b/superset-frontend/plugins/plugin-chart-echarts/package.json index b56d82f45662..64da86afdcc8 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/package.json +++ b/superset-frontend/plugins/plugin-chart-echarts/package.json @@ -23,13 +23,11 @@ "esm", "lib" ], - "devDependencies": { - "@types/react-redux": "^7.1.10" - }, "dependencies": { "d3-array": "^1.2.0", "lodash": "^4.17.21", - "dayjs": "^1.11.13" + "dayjs": "^1.11.13", + "@types/react-redux": "^7.1.10" }, "peerDependencies": { "@superset-ui/chart-controls": "*",