@@ -35,11 +35,21 @@ import {
35
35
ALL_INDICES_MESSAGE ,
36
36
} from '../utils/constants' ;
37
37
import { AppState } from '../../../redux/reducers' ;
38
- import { CatIndex , IndexAlias , MDSQueryParams } from '../../../../server/models/types' ;
39
- import { getAllDetectorsQueryParamsWithDataSourceId , getVisibleOptions } from '../../utils/helpers' ;
38
+ import {
39
+ CatIndex ,
40
+ IndexAlias ,
41
+ MDSQueryParams ,
42
+ } from '../../../../server/models/types' ;
43
+ import {
44
+ getAllDetectorsQueryParamsWithDataSourceId ,
45
+ getVisibleOptions ,
46
+ } from '../../utils/helpers' ;
40
47
import { BREADCRUMBS } from '../../../utils/constants' ;
41
48
import { DETECTOR_STATE } from '../../../../server/utils/constants' ;
42
- import { getDetectorStateOptions , getURLQueryParams } from '../../DetectorsList/utils/helpers' ;
49
+ import {
50
+ getDetectorStateOptions ,
51
+ getURLQueryParams ,
52
+ } from '../../DetectorsList/utils/helpers' ;
43
53
import { DashboardHeader } from '../Components/utils/DashboardHeader' ;
44
54
import { EmptyDashboard } from '../Components/EmptyDashboard/EmptyDashboard' ;
45
55
import {
@@ -49,7 +59,12 @@ import {
49
59
import { CoreServicesContext } from '../../../components/CoreServices/CoreServices' ;
50
60
import { CoreStart , MountPoint } from '../../../../../../src/core/public' ;
51
61
import { DataSourceSelectableConfig } from '../../../../../../src/plugins/data_source_management/public' ;
52
- import { getDataSourceManagementPlugin , getDataSourcePlugin , getNotifications , getSavedObjectsClient } from '../../../services' ;
62
+ import {
63
+ getDataSourceManagementPlugin ,
64
+ getDataSourcePlugin ,
65
+ getNotifications ,
66
+ getSavedObjectsClient ,
67
+ } from '../../../services' ;
53
68
import { RouteComponentProps } from 'react-router-dom' ;
54
69
55
70
interface OverviewProps extends RouteComponentProps {
@@ -70,7 +85,7 @@ export function DashboardOverview(props: OverviewProps) {
70
85
const errorGettingDetectors = adState . errorMessage ;
71
86
const isLoadingDetectors = adState . requesting ;
72
87
73
- const dataSourceEnabled = getDataSourcePlugin ( ) . dataSourceEnabled ;
88
+ const dataSourceEnabled = getDataSourcePlugin ( ) ? .dataSourceEnabled || false ;
74
89
75
90
const [ currentDetectors , setCurrentDetectors ] = useState (
76
91
Object . values ( allDetectorList )
@@ -82,7 +97,9 @@ export function DashboardOverview(props: OverviewProps) {
82
97
const queryParams = getURLQueryParams ( props . location ) ;
83
98
const [ MDSOverviewState , setMDSOverviewState ] = useState < MDSOverviewState > ( {
84
99
queryParams,
85
- selectedDataSourceId : queryParams . dataSourceId ? queryParams . dataSourceId : '' ,
100
+ selectedDataSourceId : queryParams . dataSourceId
101
+ ? queryParams . dataSourceId
102
+ : '' ,
86
103
} ) ;
87
104
88
105
const getDetectorOptions = ( detectorsIdMap : {
@@ -140,7 +157,7 @@ export function DashboardOverview(props: OverviewProps) {
140
157
selectedDataSourceId : dataSourceId ,
141
158
} ) ;
142
159
}
143
- }
160
+ } ;
144
161
145
162
const opensearchState = useSelector ( ( state : AppState ) => state . opensearch ) ;
146
163
@@ -191,7 +208,13 @@ export function DashboardOverview(props: OverviewProps) {
191
208
} ;
192
209
193
210
const intializeDetectors = async ( ) => {
194
- dispatch ( getDetectorList ( getAllDetectorsQueryParamsWithDataSourceId ( MDSOverviewState . selectedDataSourceId ) ) ) ;
211
+ dispatch (
212
+ getDetectorList (
213
+ getAllDetectorsQueryParamsWithDataSourceId (
214
+ MDSOverviewState . selectedDataSourceId
215
+ )
216
+ )
217
+ ) ;
195
218
dispatch ( getIndices ( '' , MDSOverviewState . selectedDataSourceId ) ) ;
196
219
dispatch ( getAliases ( '' , MDSOverviewState . selectedDataSourceId ) ) ;
197
220
} ;
@@ -204,10 +227,8 @@ export function DashboardOverview(props: OverviewProps) {
204
227
history . replace ( {
205
228
...location ,
206
229
search : queryString . stringify ( updatedParams ) ,
207
- } )
208
- if ( dataSourceEnabled ? MDSOverviewState . selectedDataSourceId : true ) {
209
- intializeDetectors ( ) ;
210
- }
230
+ } ) ;
231
+ intializeDetectors ( ) ;
211
232
} , [ MDSOverviewState ] ) ;
212
233
213
234
useEffect ( ( ) => {
@@ -237,28 +258,31 @@ export function DashboardOverview(props: OverviewProps) {
237
258
filterSelectedDetectors (
238
259
selectedDetectorsName ,
239
260
selectedDetectorStates ,
240
- selectedIndices ,
261
+ selectedIndices
241
262
) ;
242
263
} , [ selectedDetectorsName , selectedIndices , selectedDetectorStates ] ) ;
243
264
244
- const DataSourceMenu =
245
- getDataSourceManagementPlugin ( ) . ui . getDataSourceMenu < DataSourceSelectableConfig > ( ) ;
246
- const renderDataSourceComponent = useMemo ( ( ) => {
247
- return (
248
- < DataSourceMenu
249
- setMenuMountPoint = { props . setActionMenu }
250
- componentType = { 'DataSourceSelectable' }
251
- componentConfig = { {
252
- fullWidth : false ,
253
- activeOption :[ { id : MDSOverviewState . selectedDataSourceId } ] ,
254
- savedObjects : getSavedObjectsClient ( ) ,
255
- notifications : getNotifications ( ) ,
256
- onSelectedDataSources : ( dataSources ) =>
257
- handleDataSourceChange ( dataSources ) ,
258
- } }
259
- />
260
- ) ;
261
- } , [ getSavedObjectsClient ( ) , getNotifications ( ) , props . setActionMenu ] ) ;
265
+ let renderDataSourceComponent = null ;
266
+ if ( dataSourceEnabled ) {
267
+ const DataSourceMenu =
268
+ getDataSourceManagementPlugin ( ) . ui . getDataSourceMenu < DataSourceSelectableConfig > ( ) ;
269
+ renderDataSourceComponent = useMemo ( ( ) => {
270
+ return (
271
+ < DataSourceMenu
272
+ setMenuMountPoint = { props . setActionMenu }
273
+ componentType = { 'DataSourceSelectable' }
274
+ componentConfig = { {
275
+ fullWidth : false ,
276
+ activeOption : [ { id : MDSOverviewState . selectedDataSourceId } ] ,
277
+ savedObjects : getSavedObjectsClient ( ) ,
278
+ notifications : getNotifications ( ) ,
279
+ onSelectedDataSources : ( dataSources ) =>
280
+ handleDataSourceChange ( dataSources ) ,
281
+ } }
282
+ />
283
+ ) ;
284
+ } , [ getSavedObjectsClient ( ) , getNotifications ( ) , props . setActionMenu ] ) ;
285
+ }
262
286
263
287
return (
264
288
< div style = { { height : '1200px' } } >
@@ -312,8 +336,7 @@ export function DashboardOverview(props: OverviewProps) {
312
336
</ EuiFlexItem >
313
337
</ EuiFlexGroup >
314
338
< EuiSpacer />
315
- < AnomaliesLiveChart
316
- selectedDetectors = { currentDetectors } />
339
+ < AnomaliesLiveChart selectedDetectors = { currentDetectors } />
317
340
< EuiSpacer />
318
341
< EuiFlexGroup justifyContent = "spaceBetween" >
319
342
< EuiFlexItem grow = { 6 } >
0 commit comments