@@ -11,8 +11,7 @@ import { CoreStart } from '@kbn/core/public';
1111import { i18n } from '@kbn/i18n' ;
1212import { Subject } from 'rxjs' ;
1313import { KibanaContextProvider , KibanaThemeProvider } from '@kbn/kibana-react-plugin/public' ;
14- import { Embeddable , IContainer } from '@kbn/embeddable-plugin/public' ;
15- import type { DataView } from '@kbn/data-views-plugin/common' ;
14+ import { IContainer } from '@kbn/embeddable-plugin/public' ;
1615import { EmbeddableAnomalyChartsContainer } from './embeddable_anomaly_charts_container_lazy' ;
1716import type { JobId } from '../../../common/types/anomaly_detection_jobs' ;
1817import type { MlDependencies } from '../../application/app' ;
@@ -23,6 +22,8 @@ import {
2322 AnomalyChartsServices ,
2423} from '..' ;
2524import { EmbeddableLoading } from '../common/components/embeddable_loading_fallback' ;
25+ import { AnomalyDetectionEmbeddable } from '../common/anomaly_detection_embeddable' ;
26+
2627export const getDefaultExplorerChartsPanelTitle = ( jobIds : JobId [ ] ) =>
2728 i18n . translate ( 'xpack.ml.anomalyChartsEmbeddable.title' , {
2829 defaultMessage : 'ML anomaly charts for {jobIds}' ,
@@ -31,7 +32,7 @@ export const getDefaultExplorerChartsPanelTitle = (jobIds: JobId[]) =>
3132
3233export type IAnomalyChartsEmbeddable = typeof AnomalyChartsEmbeddable ;
3334
34- export class AnomalyChartsEmbeddable extends Embeddable <
35+ export class AnomalyChartsEmbeddable extends AnomalyDetectionEmbeddable <
3536 AnomalyChartsEmbeddableInput ,
3637 AnomalyChartsEmbeddableOutput
3738> {
@@ -44,52 +45,7 @@ export class AnomalyChartsEmbeddable extends Embeddable<
4445 public services : [ CoreStart , MlDependencies , AnomalyChartsServices ] ,
4546 parent ?: IContainer
4647 ) {
47- super (
48- initialInput ,
49- {
50- defaultTitle : initialInput . title ,
51- defaultDescription : initialInput . description ,
52- } ,
53- parent
54- ) ;
55- this . initializeOutput ( initialInput ) ;
56- }
57-
58- private async initializeOutput ( initialInput : AnomalyChartsEmbeddableInput ) {
59- const { anomalyExplorerService } = this . services [ 2 ] ;
60- const { jobIds } = initialInput ;
61-
62- try {
63- const jobs = await anomalyExplorerService . getCombinedJobs ( jobIds ) ;
64- const dataViewsService = this . services [ 1 ] . data . dataViews ;
65-
66- // First get list of unique indices from the selected jobs
67- const indices = new Set ( jobs . map ( ( j ) => j . datafeed_config . indices ) . flat ( ) ) ;
68- // Then find the data view assuming the data view title matches the index name
69- const indexPatterns : Record < string , DataView > = { } ;
70- for ( const indexName of indices ) {
71- const response = await dataViewsService . find ( `"${ indexName } "` ) ;
72-
73- const indexPattern = response . find (
74- ( obj ) => obj . title . toLowerCase ( ) === indexName . toLowerCase ( )
75- ) ;
76- if ( indexPattern !== undefined ) {
77- indexPatterns [ indexPattern . id ! ] = indexPattern ;
78- }
79- }
80-
81- this . updateOutput ( {
82- ...this . getOutput ( ) ,
83- indexPatterns : Object . values ( indexPatterns ) ,
84- } ) ;
85- } catch ( e ) {
86- // Unable to find and load data view but we can ignore the error
87- // as we only load it to support the filter & query bar
88- // the visualizations should still work correctly
89-
90- // eslint-disable-next-line no-console
91- console . error ( `Unable to load data views for ${ jobIds } ` , e ) ;
92- }
48+ super ( initialInput , services [ 2 ] . anomalyDetectorService , services [ 1 ] . data . dataViews , parent ) ;
9349 }
9450
9551 public onLoading ( ) {
0 commit comments