From 38d21acff63dde1a1604565e37f73c8b1ac130a0 Mon Sep 17 00:00:00 2001 From: Agata Stawarz <47450693+agatapst@users.noreply.github.com> Date: Thu, 3 Dec 2020 19:23:23 +0100 Subject: [PATCH] fix: Check if annotation type is supported by the given chart type (#11876) * Check if annotation type is supported by this kind of chart * Check if annotation type exists --- .../components/controls/AnnotationLayer.jsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx b/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx index 3388fea03d..1c65c56e7c 100644 --- a/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx +++ b/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx @@ -118,6 +118,7 @@ export default class AnnotationLayer extends React.PureComponent { descriptionColumns, timeColumn, intervalEndColumn, + vizType, } = props; // Only allow override whole time_range @@ -127,10 +128,19 @@ export default class AnnotationLayer extends React.PureComponent { delete overrides.until; } + // Check if annotationType is supported by this chart + const metadata = getChartMetadataRegistry().get(vizType); + const supportedAnnotationTypes = metadata?.supportedAnnotationTypes || []; + const validAnnotationType = supportedAnnotationTypes.includes( + annotationType, + ) + ? annotationType + : supportedAnnotationTypes[0]; + this.state = { // base name, - annotationType, + annotationType: validAnnotationType, sourceType, value, overrides, @@ -187,7 +197,7 @@ export default class AnnotationLayer extends React.PureComponent { label: chartMetadata.name, })); // Prepend native source if applicable - if (ANNOTATION_TYPES_METADATA[annotationType].supportNativeSource) { + if (ANNOTATION_TYPES_METADATA[annotationType]?.supportNativeSource) { sources.unshift(ANNOTATION_SOURCE_TYPES_METADATA.NATIVE); } return sources; @@ -724,6 +734,7 @@ export default class AnnotationLayer extends React.PureComponent { options={supportedSourceTypes} value={sourceType} onChange={this.handleAnnotationSourceType} + validationErrors={!sourceType ? [t('Mandatory')] : []} /> )} {this.renderValueConfiguration()}