import { defaultsDeep } from 'lodash' ; import { ISchemas } from 'src/plugins/vis_default_editor/public' ; import { VisParams } from '../types' ; import { VisType , VisTypeOptions } from './types' ; interface CommonBaseVisTypeOptions < TVisParams > extends Pick < VisType < TVisParams > , 'description' | 'editor' | 'getInfoMessage' | 'getSupportedTriggers' | 'hierarchicalData' | 'icon' | 'image' | 'inspectorAdapters' | 'getUsedIndexPattern' | 'name' | 'requestHandler' | 'responseHandler' | 'setup' | 'title' > , Pick < Partial < VisType < TVisParams > > , 'editorConfig' | 'hidden' | 'stage' | 'useCustomNoDataScreen' | 'visConfig' > { options ? : Partial < VisType < TVisParams > [ 'options' ] > ; } interface ExpressionBaseVisTypeOptions < TVisParams > extends CommonBaseVisTypeOptions < TVisParams > { toExpressionAst : VisType < TVisParams > [ 'toExpressionAst' ] ; visualization ? : undefined ; } interface VisualizationBaseVisTypeOptions < TVisParams > extends CommonBaseVisTypeOptions < TVisParams > { toExpressionAst ? : undefined ; visualization : VisType < TVisParams > [ 'visualization' ] ; } export type BaseVisTypeOptions < TVisParams = VisParams > = ExpressionBaseVisTypeOptions < TVisParams > | VisualizationBaseVisTypeOptions < TVisParams > ; const defaultOptions = { showTimePicker : true , showQueryBar : true , showFilterBar : true , showIndexSelection : true , hierarchicalData : false , } ; export class BaseVisType < TVisParams = VisParams > implements VisType < TVisParams > { public readonly name ; public readonly title ; public readonly description ; public readonly getSupportedTriggers ; public readonly icon ; public readonly image ; public readonly stage ; public readonly options ; public readonly visualization ; public readonly visConfig ; public readonly editor ; public readonly editorConfig ; public hidden ; public readonly requestHandler ; public readonly responseHandler ; public readonly hierarchicalData ; public readonly setup ; public readonly getUsedIndexPattern ; public readonly useCustomNoDataScreen ; public readonly inspectorAdapters ; public readonly toExpressionAst ; public readonly getInfoMessage ; constructor ( opts ) { if ( ! opts . icon && ! opts . image ) { throw new Error ( 'vis_type must define its icon or image' ) ; } this . name = opts . name ; this . description = opts . description ?? '' ; this . getSupportedTriggers = opts . getSupportedTriggers ; this . title = opts . title ; this . icon = opts . icon ; this . image = opts . image ; this . visualization = opts . visualization ; this . visConfig = defaultsDeep ( { } , opts . visConfig , { defaults : { } } ) ; this . editor = opts . editor ; this . editorConfig = defaultsDeep ( { } , opts . editorConfig , { collections : { } } ) ; this . options = defaultsDeep ( { } , opts . options , defaultOptions ) ; this . stage = opts . stage ?? 'production' ; this . hidden = opts . hidden ?? false ; this . requestHandler = opts . requestHandler ?? 'courier' ; this . responseHandler = opts . responseHandler ?? 'none' ; this . setup = opts . setup ; this . hierarchicalData = opts . hierarchicalData ?? false ; this . getUsedIndexPattern = opts . getUsedIndexPattern ; this . useCustomNoDataScreen = opts . useCustomNoDataScreen ?? false ; this . inspectorAdapters = opts . inspectorAdapters ; this . toExpressionAst = opts . toExpressionAst ; this . getInfoMessage = opts . getInfoMessage ; } public get schemas ( ) : ISchemas { return this . editorConfig ?. schemas ?? [ ] ; } public get requiresSearch ( ) : boolean { return this . requestHandler !== 'none' ; } }