Skip to content

Commit c383ebb

Browse files
Lindsay-00Lingxi Chen
andauthored
Added version decoupling for wlm dashboard (#361)
--------- Signed-off-by: Lingxi Chen <[email protected]> Co-authored-by: Lingxi Chen <[email protected]>
1 parent 861664d commit c383ebb

File tree

6 files changed

+69
-8
lines changed

6 files changed

+69
-8
lines changed

cypress/e2e/7_WLM_details.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('WLM Details Page', () => {
1717
}).then((res) => {
1818
const groups = res.body?.workload_groups ?? [];
1919
groups.forEach((g) => {
20-
if (g.name !== 'DEFAUL_WORKLOAD_GROUP') {
20+
if (g.name !== 'DEFAULT_WORKLOAD_GROUP') {
2121
cy.request({
2222
method: 'DELETE',
2323
url: `/api/_wlm/workload_group/${g.name}`,

public/components/DataSourcePicker.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
} from 'src/plugins/data_source_management/public';
1212
import { AppMountParameters, CoreStart } from '../../../../src/core/public';
1313
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';
1519

1620
export interface DataSourceMenuProps {
1721
dataSourceManagement?: DataSourceManagementPluginSetup;
@@ -71,3 +75,50 @@ export const QueryInsightsDataSourceMenu = React.memo(
7175
prevProps.selectedDataSource.id === newProps.selectedDataSource.id &&
7276
prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly
7377
);
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+
);

public/pages/WorkloadManagement/WLMCreate/WLMCreate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { CoreStart, AppMountParameters } from 'opensearch-dashboards/public';
2222
import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
2323
import { QueryInsightsDashboardsPluginStartDependencies } from '../../../types';
2424
import { WLM_CREATE, WLM_MAIN } from '../WorkloadManagement';
25-
import { QueryInsightsDataSourceMenu } from '../../../components/DataSourcePicker';
25+
import { WLMDataSourceMenu } from '../../../components/DataSourcePicker';
2626
import { DataSourceContext } from '../WorkloadManagement';
2727
import { getDataSourceEnabledUrl } from '../../../utils/datasource-utils';
2828
import { PageHeader } from '../../../components/PageHeader';
@@ -160,7 +160,7 @@ export const WLMCreate = ({
160160
coreStart={core}
161161
depsStart={depsStart}
162162
fallBackComponent={
163-
<QueryInsightsDataSourceMenu
163+
<WLMDataSourceMenu
164164
coreStart={core}
165165
depsStart={depsStart}
166166
params={params}

public/pages/WorkloadManagement/WLMDetails/WLMDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_managem
3232
import { PageHeader } from '../../../components/PageHeader';
3333
import { QueryInsightsDashboardsPluginStartDependencies } from '../../../types';
3434
import { WLM_MAIN, DataSourceContext } from '../WorkloadManagement';
35-
import { QueryInsightsDataSourceMenu } from '../../../components/DataSourcePicker';
35+
import { WLMDataSourceMenu } from '../../../components/DataSourcePicker';
3636
import { getDataSourceEnabledUrl } from '../../../utils/datasource-utils';
3737

3838
// === Constants & Types ===
@@ -564,7 +564,7 @@ export const WLMDetails = ({
564564
depsStart={depsStart}
565565
fallBackComponent={
566566
<>
567-
<QueryInsightsDataSourceMenu
567+
<WLMDataSourceMenu
568568
coreStart={core}
569569
depsStart={depsStart}
570570
params={params}

public/pages/WorkloadManagement/WLMMain/WLMMain.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { PageHeader } from '../../../components/PageHeader';
2727
import { QueryInsightsDashboardsPluginStartDependencies } from '../../../types';
2828
import { WLM_CREATE } from '../WorkloadManagement';
2929
import { DataSourceContext } from '../WorkloadManagement';
30-
import { QueryInsightsDataSourceMenu } from '../../../components/DataSourcePicker';
30+
import { WLMDataSourceMenu } from '../../../components/DataSourcePicker';
3131
import { getDataSourceEnabledUrl } from '../../../utils/datasource-utils';
3232

3333
export const WLM = '/workloadManagement';
@@ -583,7 +583,7 @@ export const WorkloadManagementMain = ({
583583
coreStart={core}
584584
depsStart={depsStart}
585585
fallBackComponent={
586-
<QueryInsightsDataSourceMenu
586+
<WLMDataSourceMenu
587587
coreStart={core}
588588
depsStart={depsStart}
589589
params={params}

public/utils/datasource-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ export const isDataSourceCompatible = (dataSource: SavedObject<DataSourceAttribu
6363
}
6464
return true;
6565
};
66+
67+
export const isWLMDataSourceCompatible = (dataSource: SavedObject<DataSourceAttributes>) => {
68+
if (
69+
'supportedOSDataSourceVersions' in pluginManifest &&
70+
!semver.satisfies(dataSource.attributes.dataSourceVersion, '>=3.1.0')
71+
) {
72+
return false;
73+
}
74+
return true;
75+
};

0 commit comments

Comments
 (0)