all files / src/modules/ AnnotationTypes.js

73.33% Statements 22/30
0% Branches 0/8
0% Functions 0/6
66.67% Lines 16/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95                                                                                                                                                              
import { VIZ_TYPES } from '../visualizations';
import vizTypes from '../explore/visTypes';
 
export const ANNOTATION_TYPES = {
  FORMULA: 'FORMULA',
  EVENT: 'EVENT',
  INTERVAL: 'INTERVAL',
  TIME_SERIES: 'TIME_SERIES',
};
 
export const ANNOTATION_TYPE_LABELS = {
  FORMULA: 'Formula ',
  EVENT: 'Event',
  INTERVAL: 'Interval',
  TIME_SERIES: 'Time Series',
};
 
export function getAnnotationTypeLabel(annotationType) {
  return ANNOTATION_TYPE_LABELS[annotationType];
}
 
export const DEFAULT_ANNOTATION_TYPE = ANNOTATION_TYPES.FORMULA;
 
export const ANNOTATION_SOURCE_TYPES = {
  NATIVE: 'NATIVE',
  ...VIZ_TYPES,
};
 
export function getAnnotationSourceTypeLabels(sourceType) {
  return ANNOTATION_SOURCE_TYPES.NATIVE === sourceType ? 'Superset annotation' :
      vizTypes[sourceType].label;
}
 
export function requiresQuery(annotationSourceType) {
  return !!annotationSourceType;
}
 
// Map annotation type to annotation source type
const SUPPORTED_SOURCE_TYPE_MAP = {
  [ANNOTATION_TYPES.EVENT]: [
    ANNOTATION_SOURCE_TYPES.NATIVE,
    ANNOTATION_SOURCE_TYPES.table,
  ],
  [ANNOTATION_TYPES.INTERVAL]: [
    ANNOTATION_SOURCE_TYPES.NATIVE,
    ANNOTATION_SOURCE_TYPES.table,
  ],
  [ANNOTATION_TYPES.TIME_SERIES]: [
    ANNOTATION_SOURCE_TYPES.line,
  ],
};
 
export function getSupportedSourceTypes(annotationType) {
  return SUPPORTED_SOURCE_TYPE_MAP[annotationType] || [];
}
 
// Map from viz type to supported annotation
const SUPPORTED_ANNOTATIONS = {
  [VIZ_TYPES.line]: [
    ANNOTATION_TYPES.TIME_SERIES,
    ANNOTATION_TYPES.INTERVAL,
    ANNOTATION_TYPES.EVENT,
    ANNOTATION_TYPES.FORMULA,
  ],
  [VIZ_TYPES.bar]: [
    ANNOTATION_TYPES.INTERVAL,
    ANNOTATION_TYPES.EVENT,
  ],
  [VIZ_TYPES.area]: [
    ANNOTATION_TYPES.INTERVAL,
    ANNOTATION_TYPES.EVENT,
  ],
};
 
export function getSupportedAnnotationTypes(vizType) {
  return SUPPORTED_ANNOTATIONS[vizType] || [];
}
 
const NATIVE_COLUMN_NAMES = {
  timeColumn: 'start_dttm',
  intervalEndColumn: 'end_dttm',
  titleColumn: 'short_descr',
  descriptionColumns: ['long_descr'],
};
 
export function applyNativeColumns(annotation) {
  if (annotation.sourceType === ANNOTATION_SOURCE_TYPES.NATIVE) {
    return { ...annotation, ...NATIVE_COLUMN_NAMES };
  }
  return annotation;
}
 
export default ANNOTATION_TYPES;