This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch default_chart_settings in repository https://gitbox.apache.org/repos/asf/superset.git
commit 400ef542d779743af28b1f14eaf4e1cedb884cd0 Author: Maxime Beauchemin <maximebeauche...@gmail.com> AuthorDate: Sun Aug 3 17:42:49 2025 -0700 fix: DatasetEditor Chart Defaults not displaying saved values Fixed an issue where the Chart Defaults section in the DatasetEditor would not display previously saved values when reopening the editor. The problem was that the component assumed `datasource.extra` would always be a string that needed JSON parsing, but it could also be an already-parsed object depending on the component's state. Changes: - Added proper type checking for `datasource.extra` (string vs object) - Used IIFE with try-catch for safe value extraction in Select components - Fixed onChange handlers to handle both string and object types - Ensured saved chart defaults now properly display on editor reload 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <nore...@anthropic.com> --- superset-frontend/package-lock.json | 2 +- .../src/components/Datasource/DatasourceEditor.jsx | 105 +++++++++++++++------ 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index ad6ac17411..5442463535 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -61644,7 +61644,7 @@ "@storybook/types": "8.4.7", "@types/react-loadable": "^5.5.11", "core-js": "3.40.0", - "gh-pages": "^6.2.0", + "gh-pages": "^6.3.0", "jquery": "^3.7.1", "memoize-one": "^5.2.1", "react": "^17.0.2", diff --git a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx index 8eb080f505..d1ea76ba24 100644 --- a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx +++ b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx @@ -1061,13 +1061,22 @@ class DatasourceEditor extends PureComponent { label: metric.verbose_name || metric.metric_name, })) || [] } - value={ - datasource.extra && - JSON.parse(datasource.extra || '{}')?.default_chart_metadata - ?.default_metric - } + value={(() => { + try { + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : datasource.extra || {}; + return extra.default_chart_metadata?.default_metric; + } catch { + return undefined; + } + })()} onChange={value => { - const extra = JSON.parse(datasource.extra || '{}'); + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : { ...(datasource.extra || {}) }; if (!extra.default_chart_metadata) { extra.default_chart_metadata = {}; } @@ -1096,13 +1105,22 @@ class DatasourceEditor extends PureComponent { label: column.verbose_name || column.column_name, })) || [] } - value={ - datasource.extra && - JSON.parse(datasource.extra || '{}')?.default_chart_metadata - ?.default_dimension - } + value={(() => { + try { + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : datasource.extra || {}; + return extra.default_chart_metadata?.default_dimension; + } catch { + return undefined; + } + })()} onChange={value => { - const extra = JSON.parse(datasource.extra || '{}'); + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : { ...(datasource.extra || {}) }; if (!extra.default_chart_metadata) { extra.default_chart_metadata = {}; } @@ -1136,13 +1154,22 @@ class DatasourceEditor extends PureComponent { { value: 'P1M', label: t('Month') }, { value: 'P1Y', label: t('Year') }, ]} - value={ - datasource.extra && - JSON.parse(datasource.extra || '{}')?.default_chart_metadata - ?.default_time_grain - } + value={(() => { + try { + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : datasource.extra || {}; + return extra.default_chart_metadata?.default_time_grain; + } catch { + return undefined; + } + })()} onChange={value => { - const extra = JSON.parse(datasource.extra || '{}'); + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : { ...(datasource.extra || {}) }; if (!extra.default_chart_metadata) { extra.default_chart_metadata = {}; } @@ -1171,13 +1198,22 @@ class DatasourceEditor extends PureComponent { { value: 'Last year', label: t('Last year') }, { value: 'No filter', label: t('No filter') }, ]} - value={ - datasource.extra && - JSON.parse(datasource.extra || '{}')?.default_chart_metadata - ?.default_time_range - } + value={(() => { + try { + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : datasource.extra || {}; + return extra.default_chart_metadata?.default_time_range; + } catch { + return undefined; + } + })()} onChange={value => { - const extra = JSON.parse(datasource.extra || '{}'); + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : { ...(datasource.extra || {}) }; if (!extra.default_chart_metadata) { extra.default_chart_metadata = {}; } @@ -1198,13 +1234,22 @@ class DatasourceEditor extends PureComponent { control={ <TextControl name="default_row_limit" - value={ - datasource.extra && - JSON.parse(datasource.extra || '{}')?.default_chart_metadata - ?.default_row_limit - } + value={(() => { + try { + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : datasource.extra || {}; + return extra.default_chart_metadata?.default_row_limit; + } catch { + return undefined; + } + })()} onChange={value => { - const extra = JSON.parse(datasource.extra || '{}'); + const extra = + typeof datasource.extra === 'string' + ? JSON.parse(datasource.extra || '{}') + : { ...(datasource.extra || {}) }; if (!extra.default_chart_metadata) { extra.default_chart_metadata = {}; }