mirror of
https://github.com/apache/superset.git
synced 2024-09-18 03:29:38 -04:00
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:
parent
53017e5a35
commit
38d21acff6
@ -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()}
|
||||||
|
Loading…
Reference in New Issue
Block a user