-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add support for MDS * MDS for all paths, pages with dummy dataSourceId * Fix all pages and apis * Push data source into the url * Persist data source selection across pages * fix when local cluster id is empty * fix manage link based on OpenSearch-Dashboards/pull/9059 * refresh page data when data source is changed * fix lint * fix unit tests and cypress tests * make data source picker read only on detail pages --------- (cherry picked from commit e4ccdb8) Signed-off-by: Derek Ho <[email protected]> Signed-off-by: David Zane <[email protected]> Signed-off-by: Chenyang Ji <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Derek Ho <[email protected]> Co-authored-by: David Zane <[email protected]>
1 parent
c3b2c47
commit c58cc2b
Showing
22 changed files
with
852 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
DataSourceManagementPluginSetup, | ||
DataSourceOption, | ||
DataSourceSelectableConfig, | ||
} from 'src/plugins/data_source_management/public'; | ||
import { AppMountParameters, CoreStart } from '../../../../src/core/public'; | ||
import { QueryInsightsDashboardsPluginStartDependencies } from '../types'; | ||
|
||
export interface DataSourceMenuProps { | ||
dataSourceManagement: DataSourceManagementPluginSetup; | ||
depsStart: QueryInsightsDashboardsPluginStartDependencies; | ||
coreStart: CoreStart; | ||
params: AppMountParameters; | ||
setDataSource: React.Dispatch<React.SetStateAction<DataSourceOption>>; | ||
selectedDataSource: DataSourceOption; | ||
onManageDataSource: () => void; | ||
onSelectedDataSource: () => void; | ||
dataSourcePickerReadOnly: boolean; | ||
} | ||
|
||
export function getDataSourceEnabledUrl(dataSource: DataSourceOption) { | ||
const url = new URL(window.location.href); | ||
url.searchParams.set('dataSource', JSON.stringify(dataSource)); | ||
return url; | ||
} | ||
|
||
export function getDataSourceFromUrl(): DataSourceOption { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const dataSourceParam = (urlParams && urlParams.get('dataSource')) || '{}'; | ||
// following block is needed if the dataSource param is set to non-JSON value, say 'undefined' | ||
try { | ||
return JSON.parse(dataSourceParam); | ||
} catch (e) { | ||
return JSON.parse('{}'); // Return an empty object or some default value if parsing fails | ||
} | ||
} | ||
|
||
export const QueryInsightsDataSourceMenu = React.memo( | ||
(props: DataSourceMenuProps) => { | ||
const { | ||
coreStart, | ||
depsStart, | ||
dataSourceManagement, | ||
params, | ||
setDataSource, | ||
selectedDataSource, | ||
onManageDataSource, | ||
onSelectedDataSource, | ||
dataSourcePickerReadOnly, | ||
} = props; | ||
const { setHeaderActionMenu } = params; | ||
const DataSourceMenu = dataSourceManagement?.ui.getDataSourceMenu<DataSourceSelectableConfig>(); | ||
|
||
const dataSourceEnabled = !!depsStart.dataSource?.dataSourceEnabled; | ||
|
||
const wrapSetDataSourceWithUpdateUrl = (dataSources: DataSourceOption[]) => { | ||
window.history.replaceState({}, '', getDataSourceEnabledUrl(dataSources[0]).toString()); | ||
setDataSource(dataSources[0]); | ||
onSelectedDataSource(); | ||
}; | ||
|
||
return dataSourceEnabled ? ( | ||
<DataSourceMenu | ||
onManageDataSource={onManageDataSource} | ||
setMenuMountPoint={setHeaderActionMenu} | ||
componentType={dataSourcePickerReadOnly ? 'DataSourceView' : 'DataSourceSelectable'} | ||
componentConfig={{ | ||
onManageDataSource, | ||
savedObjects: coreStart.savedObjects.client, | ||
notifications: coreStart.notifications, | ||
activeOption: | ||
selectedDataSource.id || selectedDataSource.label ? [selectedDataSource] : undefined, | ||
onSelectedDataSources: wrapSetDataSourceWithUpdateUrl, | ||
fullWidth: true, | ||
}} | ||
/> | ||
) : null; | ||
}, | ||
(prevProps, newProps) => | ||
prevProps.selectedDataSource.id === newProps.selectedDataSource.id && | ||
prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.