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
This commit is contained in:
Agata Stawarz 2020-12-03 19:23:23 +01:00 committed by GitHub
parent 53017e5a35
commit 38d21acff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,6 +118,7 @@ export default class AnnotationLayer extends React.PureComponent {
descriptionColumns, descriptionColumns,
timeColumn, timeColumn,
intervalEndColumn, intervalEndColumn,
vizType,
} = props; } = props;
// Only allow override whole time_range // Only allow override whole time_range
@ -127,10 +128,19 @@ export default class AnnotationLayer extends React.PureComponent {
delete overrides.until; 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 = { this.state = {
// base // base
name, name,
annotationType, annotationType: validAnnotationType,
sourceType, sourceType,
value, value,
overrides, overrides,
@ -187,7 +197,7 @@ export default class AnnotationLayer extends React.PureComponent {
label: chartMetadata.name, label: chartMetadata.name,
})); }));
// Prepend native source if applicable // Prepend native source if applicable
if (ANNOTATION_TYPES_METADATA[annotationType].supportNativeSource) { if (ANNOTATION_TYPES_METADATA[annotationType]?.supportNativeSource) {
sources.unshift(ANNOTATION_SOURCE_TYPES_METADATA.NATIVE); sources.unshift(ANNOTATION_SOURCE_TYPES_METADATA.NATIVE);
} }
return sources; return sources;
@ -724,6 +734,7 @@ export default class AnnotationLayer extends React.PureComponent {
options={supportedSourceTypes} options={supportedSourceTypes}
value={sourceType} value={sourceType}
onChange={this.handleAnnotationSourceType} onChange={this.handleAnnotationSourceType}
validationErrors={!sourceType ? [t('Mandatory')] : []}
/> />
)} )}
{this.renderValueConfiguration()} {this.renderValueConfiguration()}