55 * 2.0.
66 */
77import { i18n } from '@kbn/i18n' ;
8- import React , { useEffect , useRef , useState , useCallback } from 'react' ;
8+ import React , { useEffect , useRef , useState } from 'react' ;
99import { EuiPanel , EuiTitle } from '@elastic/eui' ;
1010import styled from 'styled-components' ;
1111import { isEmpty } from 'lodash' ;
@@ -14,11 +14,12 @@ import { ObservabilityPublicPluginsStart } from '../../../plugin';
1414import { ExploratoryViewHeader } from './header/header' ;
1515import { useSeriesStorage } from './hooks/use_series_storage' ;
1616import { useLensAttributes } from './hooks/use_lens_attributes' ;
17- import { EmptyView } from './components/empty_view' ;
1817import { TypedLensByValueInput } from '../../../../../lens/public' ;
1918import { useAppIndexPatternContext } from './hooks/use_app_index_pattern' ;
2019import { SeriesBuilder } from './series_builder/series_builder' ;
2120import { SeriesUrl } from './types' ;
21+ import { LensEmbeddable } from './lens_embeddable' ;
22+ import { EmptyView } from './components/empty_view' ;
2223
2324export const combineTimeRanges = (
2425 allSeries : Record < string , SeriesUrl > ,
@@ -52,14 +53,13 @@ export function ExploratoryView({
5253 saveAttributes ?: ( attr : TypedLensByValueInput [ 'attributes' ] | null ) => void ;
5354} ) {
5455 const {
55- services : { lens, notifications } ,
56+ services : { lens } ,
5657 } = useKibana < ObservabilityPublicPluginsStart > ( ) ;
5758
5859 const seriesBuilderRef = useRef < HTMLDivElement > ( null ) ;
5960 const wrapperRef = useRef < HTMLDivElement > ( null ) ;
6061
6162 const [ height , setHeight ] = useState < string > ( '100vh' ) ;
62- const [ seriesId , setSeriesId ] = useState < string > ( '' ) ;
6363
6464 const [ lastUpdated , setLastUpdated ] = useState < number | undefined > ( ) ;
6565
@@ -69,13 +69,7 @@ export function ExploratoryView({
6969
7070 const { loadIndexPattern, loading } = useAppIndexPatternContext ( ) ;
7171
72- const LensComponent = lens ?. EmbeddableComponent ;
73-
74- const { firstSeriesId, firstSeries : series , setSeries, allSeries } = useSeriesStorage ( ) ;
75-
76- useEffect ( ( ) => {
77- setSeriesId ( firstSeriesId ) ;
78- } , [ allSeries , firstSeriesId ] ) ;
72+ const { firstSeries, firstSeriesId, allSeries } = useSeriesStorage ( ) ;
7973
8074 const lensAttributesT = useLensAttributes ( ) ;
8175
@@ -108,49 +102,16 @@ export function ExploratoryView({
108102 setHeightOffset ( ) ;
109103 } ) ;
110104
111- const timeRange = combineTimeRanges ( allSeries , series ) ;
112-
113- const onLensLoad = useCallback ( ( ) => {
114- setLastUpdated ( Date . now ( ) ) ;
115- } , [ ] ) ;
116-
117- const onBrushEnd = useCallback (
118- ( { range } : { range : number [ ] } ) => {
119- if ( series ?. reportType !== 'data-distribution' ) {
120- setSeries ( seriesId , {
121- ...series ,
122- time : {
123- from : new Date ( range [ 0 ] ) . toISOString ( ) ,
124- to : new Date ( range [ 1 ] ) . toISOString ( ) ,
125- } ,
126- } ) ;
127- } else {
128- notifications ?. toasts . add (
129- i18n . translate ( 'xpack.observability.exploratoryView.noBrusing' , {
130- defaultMessage : 'Zoom by brush selection is only available on time series charts.' ,
131- } )
132- ) ;
133- }
134- } ,
135- [ notifications ?. toasts , series , seriesId , setSeries ]
136- ) ;
137-
138105 return (
139106 < Wrapper >
140107 { lens ? (
141108 < >
142- < ExploratoryViewHeader lensAttributes = { lensAttributes } seriesId = { seriesId } />
109+ < ExploratoryViewHeader lensAttributes = { lensAttributes } seriesId = { firstSeriesId } />
143110 < LensWrapper ref = { wrapperRef } height = { height } >
144- { lensAttributes && timeRange . to && timeRange . from ? (
145- < LensComponent
146- id = "exploratoryView"
147- timeRange = { timeRange }
148- attributes = { lensAttributes }
149- onLoad = { onLensLoad }
150- onBrushEnd = { onBrushEnd }
151- />
111+ { lensAttributes ? (
112+ < LensEmbeddable setLastUpdated = { setLastUpdated } lensAttributes = { lensAttributes } />
152113 ) : (
153- < EmptyView series = { series } loading = { loading } height = { height } />
114+ < EmptyView series = { firstSeries } loading = { loading } height = { height } />
154115 ) }
155116 </ LensWrapper >
156117 < SeriesBuilder
0 commit comments