Skip to content

Commit

Permalink
fix(dashboard): add toast if JSON metadata is invalid (#20823)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ committed Jul 23, 2022
1 parent 3fb5c79 commit 557cf4b
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type PropertiesModalProps = {
setColorSchemeAndUnsavedChanges?: () => void;
onSubmit?: (params: Record<string, any>) => void;
addSuccessToast: (message: string) => void;
addDangerToast: (message: string) => void;
onlyApply?: boolean;
};

Expand All @@ -80,6 +81,7 @@ type DashboardInfo = {

const PropertiesModal = ({
addSuccessToast,
addDangerToast,
colorScheme: currentColorScheme,
dashboardId,
dashboardInfo: currentDashboardInfo,
Expand Down Expand Up @@ -294,7 +296,12 @@ const PropertiesModal = ({

// color scheme in json metadata has precedence over selection
if (currentJsonMetadata?.length) {
const metadata = JSON.parse(currentJsonMetadata);
let metadata;
try {
metadata = JSON.parse(currentJsonMetadata);
} catch (error) {
addDangerToast(t('JSON metadata is invalid!'));
}
currentColorScheme = metadata?.color_scheme || colorScheme;
colorNamespace = metadata?.color_namespace || '';

Expand Down

0 comments on commit 557cf4b

Please sign in to comment.