You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by yo...@apache.org on 2022/09/20 09:32:45 UTC
[superset] branch master updated: chore: should return if get a exception in Dashboard edit modal (#21524)
This is an automated email from the ASF dual-hosted git repository.
yongjiezhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 42000823be chore: should return if get a exception in Dashboard edit modal (#21524)
42000823be is described below
commit 42000823be5bc6982cb2cae7939ac6fccb74cc8c
Author: Yongjie Zhao <yo...@apache.org>
AuthorDate: Tue Sep 20 17:32:28 2022 +0800
chore: should return if get a exception in Dashboard edit modal (#21524)
---
.../dashboard/components/PropertiesModal/index.tsx | 75 ++++++++++++----------
1 file changed, 40 insertions(+), 35 deletions(-)
diff --git a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
index a5ee37e1cd..f015612d2a 100644
--- a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
+++ b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
@@ -21,15 +21,15 @@ import { Input } from 'src/components/Input';
import { FormItem } from 'src/components/Form';
import jsonStringify from 'json-stringify-pretty-compact';
import Button from 'src/components/Button';
-import { AsyncSelect, Row, Col, AntdForm } from 'src/components';
+import { AntdForm, AsyncSelect, Col, Row } from 'src/components';
import rison from 'rison';
import {
- styled,
- t,
- SupersetClient,
- getCategoricalSchemeRegistry,
ensureIsArray,
+ getCategoricalSchemeRegistry,
getSharedLabelColor,
+ styled,
+ SupersetClient,
+ t,
} from '@superset-ui/core';
import Modal from 'src/components/Modal';
@@ -299,43 +299,48 @@ const PropertiesModal = ({
let colorNamespace = '';
let currentJsonMetadata = jsonMetadata;
- // color scheme in json metadata has precedence over selection
- if (currentJsonMetadata?.length) {
- let metadata;
- try {
- metadata = JSON.parse(currentJsonMetadata);
- } catch (error) {
- addDangerToast(t('JSON metadata is invalid!'));
- }
- currentColorScheme = metadata?.color_scheme || colorScheme;
- colorNamespace = metadata?.color_namespace || '';
-
- // filter shared_label_color from user input
- if (metadata?.shared_label_colors) {
- delete metadata.shared_label_colors;
- }
- if (metadata?.color_scheme_domain) {
- delete metadata.color_scheme_domain;
+ // validate currentJsonMetadata
+ let metadata;
+ try {
+ if (
+ !currentJsonMetadata.startsWith('{') ||
+ !currentJsonMetadata.endsWith('}')
+ ) {
+ throw new Error();
}
+ metadata = JSON.parse(currentJsonMetadata);
+ } catch (error) {
+ addDangerToast(t('JSON metadata is invalid!'));
+ return;
+ }
- const colorMap = getSharedLabelColor().getColorMap(
- colorNamespace,
- currentColorScheme,
- true,
- );
+ // color scheme in json metadata has precedence over selection
+ currentColorScheme = metadata?.color_scheme || colorScheme;
+ colorNamespace = metadata?.color_namespace || '';
- metadata.shared_label_colors = colorMap;
+ // filter shared_label_color from user input
+ if (metadata?.shared_label_colors) {
+ delete metadata.shared_label_colors;
+ }
+ if (metadata?.color_scheme_domain) {
+ delete metadata.color_scheme_domain;
+ }
- if (metadata?.color_scheme) {
- metadata.color_scheme_domain =
- categoricalSchemeRegistry.get(colorScheme)?.colors || [];
- } else {
- metadata.color_scheme_domain = [];
- }
+ metadata.shared_label_colors = getSharedLabelColor().getColorMap(
+ colorNamespace,
+ currentColorScheme,
+ true,
+ );
- currentJsonMetadata = jsonStringify(metadata);
+ if (metadata?.color_scheme) {
+ metadata.color_scheme_domain =
+ categoricalSchemeRegistry.get(colorScheme)?.colors || [];
+ } else {
+ metadata.color_scheme_domain = [];
}
+ currentJsonMetadata = jsonStringify(metadata);
+
onColorSchemeChange(currentColorScheme, {
updateMetadata: false,
});