File tree Expand file tree Collapse file tree 6 files changed +36
-3
lines changed Expand file tree Collapse file tree 6 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 1818 */
1919
2020export const MAX_BUCKETS_SETTING = 'metrics:max_buckets' ;
21+ export const INDEXES_SEPARATOR = ',' ;
Original file line number Diff line number Diff line change @@ -83,5 +83,21 @@ export const metricsVisDefinition = {
8383 return [ VIS_EVENT_TO_TRIGGER . applyFilter ] ;
8484 } ,
8585 inspectorAdapters : { } ,
86+ getUsedIndexPattern : async ( params : VisParams ) => {
87+ const { indexPatterns } = getDataStart ( ) ;
88+ const indexes : string = params . index_pattern ;
89+
90+ if ( indexes ) {
91+ const cachedIndexes = await indexPatterns . getIdsWithTitle ( ) ;
92+ const ids = indexes
93+ . split ( INDEXES_SEPARATOR )
94+ . map ( ( title ) => cachedIndexes . find ( ( i ) => i . title === title ) ?. id )
95+ . filter ( ( id ) => id ) ;
96+
97+ return Promise . all ( ids . map ( ( id ) => indexPatterns . get ( id ! ) ) ) ;
98+ }
99+
100+ return [ ] ;
101+ } ,
86102 responseHandler : 'none' ,
87103} ;
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
3838import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants' ;
3939import { SavedVisualizationsLoader } from '../saved_visualizations' ;
4040import { AttributeService } from '../../../dashboard/public' ;
41+ import { IndexPattern } from '../../../data/public' ;
4142
4243export const createVisEmbeddableFromObject = ( deps : VisualizeEmbeddableFactoryDeps ) => async (
4344 vis : Vis ,
@@ -66,8 +67,14 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe
6667 return new DisabledLabEmbeddable ( vis . title , input ) ;
6768 }
6869
69- const indexPattern = vis . data . indexPattern ;
70- const indexPatterns = indexPattern ? [ indexPattern ] : [ ] ;
70+ let indexPatterns : IndexPattern [ ] = [ ] ;
71+
72+ if ( vis . type . getUsedIndexPattern ) {
73+ indexPatterns = await vis . type . getUsedIndexPattern ( vis . params ) ;
74+ } else if ( vis . data . indexPattern ) {
75+ indexPatterns = [ vis . data . indexPattern ] ;
76+ }
77+
7178 const editable = getCapabilities ( ) . visualize . save as boolean ;
7279
7380 return new VisualizeEmbeddable (
Original file line number Diff line number Diff line change @@ -137,7 +137,6 @@ export class Vis<TVisParams = VisParams> {
137137 if ( state . params || typeChanged ) {
138138 this . params = this . getParams ( state . params ) ;
139139 }
140-
141140 if ( state . data && state . data . searchSource ) {
142141 this . data . searchSource = await getSearch ( ) . searchSource . create ( state . data . searchSource ! ) ;
143142 this . data . indexPattern = this . data . searchSource . getField ( 'index' ) ;
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
8686 public readonly responseHandler ;
8787 public readonly hierarchicalData ;
8888 public readonly setup ;
89+ public readonly getUsedIndexPattern ;
8990 public readonly useCustomNoDataScreen ;
9091 public readonly inspectorAdapters ;
9192 public readonly toExpressionAst ;
@@ -113,6 +114,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
113114 this . responseHandler = opts . responseHandler ?? 'none' ;
114115 this . setup = opts . setup ;
115116 this . hierarchicalData = opts . hierarchicalData ?? false ;
117+ this . getUsedIndexPattern = opts . getUsedIndexPattern ;
116118 this . useCustomNoDataScreen = opts . useCustomNoDataScreen ?? false ;
117119 this . inspectorAdapters = opts . inspectorAdapters ;
118120 this . toExpressionAst = opts . toExpressionAst ;
Original file line number Diff line number Diff line change 2020import { IconType } from '@elastic/eui' ;
2121import React from 'react' ;
2222import { Adapters } from 'src/plugins/inspector' ;
23+ import { IndexPattern } from 'src/plugins/data/public' ;
2324import { ISchemas } from 'src/plugins/vis_default_editor/public' ;
2425import { TriggerContextMapping } from '../../../ui_actions/public' ;
2526import { Vis , VisToExpressionAst , VisualizationControllerConstructor } from '../types' ;
@@ -62,6 +63,13 @@ export interface VisType<TVisParams = unknown> {
6263 readonly toExpressionAst ?: VisToExpressionAst < TVisParams > ;
6364 readonly visualization ?: VisualizationControllerConstructor ;
6465
66+ /**
67+ * Some visualizations are created without SearchSource and may change the used indexes during the visualization configuration.
68+ * Using this method we can rewrite the standard mechanism for getting used indexes
69+ */
70+ readonly getUsedIndexPattern ?: ( visParams : VisParams ) => IndexPattern [ ] | Promise < IndexPattern [ ] > ;
71+
72+
6573 readonly setup ?: ( vis : Vis < TVisParams > ) => Promise < Vis < TVisParams > > ;
6674 hidden : boolean ;
6775
You can’t perform that action at this time.
0 commit comments