Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
chore: should return if get a exception in Dashboard edit modal (apac…
Browse files Browse the repository at this point in the history
…he#21524)

(cherry picked from commit 4200082)
  • Loading branch information
zhaoyongjie authored and john-bodley committed Sep 21, 2022
1 parent d583e03 commit 6accf2f
Showing 1 changed file with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
});
Expand Down

0 comments on commit 6accf2f

Please sign in to comment.