@@ -11,7 +11,11 @@ import {
11
11
} from 'src/plugins/data_source_management/public' ;
12
12
import { AppMountParameters , CoreStart } from '../../../../src/core/public' ;
13
13
import { QueryInsightsDashboardsPluginStartDependencies } from '../types' ;
14
- import { getDataSourceEnabledUrl , isDataSourceCompatible } from '../utils/datasource-utils' ;
14
+ import {
15
+ getDataSourceEnabledUrl ,
16
+ isDataSourceCompatible ,
17
+ isWLMDataSourceCompatible ,
18
+ } from '../utils/datasource-utils' ;
15
19
16
20
export interface DataSourceMenuProps {
17
21
dataSourceManagement ?: DataSourceManagementPluginSetup ;
@@ -71,3 +75,50 @@ export const QueryInsightsDataSourceMenu = React.memo(
71
75
prevProps . selectedDataSource . id === newProps . selectedDataSource . id &&
72
76
prevProps . dataSourcePickerReadOnly === newProps . dataSourcePickerReadOnly
73
77
) ;
78
+
79
+ export const WLMDataSourceMenu = React . memo (
80
+ ( props : DataSourceMenuProps ) => {
81
+ const {
82
+ coreStart,
83
+ depsStart,
84
+ dataSourceManagement,
85
+ params,
86
+ setDataSource,
87
+ selectedDataSource,
88
+ onManageDataSource,
89
+ onSelectedDataSource,
90
+ dataSourcePickerReadOnly,
91
+ } = props ;
92
+ const { setHeaderActionMenu } = params ;
93
+ const DataSourceMenu = dataSourceManagement ?. ui . getDataSourceMenu < DataSourceSelectableConfig > ( ) ;
94
+
95
+ const dataSourceEnabled = ! ! depsStart . dataSource ?. dataSourceEnabled ;
96
+
97
+ const wrapSetDataSourceWithUpdateUrl = ( dataSources : DataSourceOption [ ] ) => {
98
+ window . history . replaceState ( { } , '' , getDataSourceEnabledUrl ( dataSources [ 0 ] ) . toString ( ) ) ;
99
+ setDataSource ( dataSources [ 0 ] ) ;
100
+ onSelectedDataSource ( ) ;
101
+ } ;
102
+
103
+ return dataSourceEnabled ? (
104
+ < DataSourceMenu
105
+ onManageDataSource = { onManageDataSource }
106
+ setMenuMountPoint = { setHeaderActionMenu }
107
+ componentType = { dataSourcePickerReadOnly ? 'DataSourceView' : 'DataSourceSelectable' }
108
+ componentConfig = { {
109
+ onManageDataSource,
110
+ savedObjects : coreStart . savedObjects . client ,
111
+ notifications : coreStart . notifications ,
112
+ activeOption :
113
+ selectedDataSource . id || selectedDataSource . label ? [ selectedDataSource ] : undefined ,
114
+ onSelectedDataSources : wrapSetDataSourceWithUpdateUrl ,
115
+ fullWidth : true ,
116
+ dataSourceFilter : isWLMDataSourceCompatible ,
117
+ } }
118
+ />
119
+ ) : null ;
120
+ } ,
121
+ ( prevProps , newProps ) =>
122
+ prevProps . selectedDataSource . id === newProps . selectedDataSource . id &&
123
+ prevProps . dataSourcePickerReadOnly === newProps . dataSourcePickerReadOnly
124
+ ) ;
0 commit comments