Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [MD]Refactor dev tool to use dataSourceManagement.ui API to get DataSourceSelector #6521

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6477.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- Refactor dev tool to use dataSourceManagement.ui API to get DataSourceSelector ([#6477](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6477))
5 changes: 2 additions & 3 deletions src/plugins/dev_tools/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "opensearchDashboards",
"server": false,
"ui": true,
"optionalPlugins": ["dataSource", "managementOverview"],
"requiredPlugins": ["urlForwarding"],
"requiredBundles": ["dataSourceManagement"]
"optionalPlugins": ["dataSource", "managementOverview", "dataSourceManagement"],
"requiredPlugins": ["urlForwarding"]
}
48 changes: 23 additions & 25 deletions src/plugins/dev_tools/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ import {
ApplicationStart,
ChromeStart,
CoreStart,
IUiSettingsClient,
NotificationsStart,
SavedObjectsStart,
ScopedHistory,
} from 'src/core/public';

import { DataSourceSelector } from '../../data_source_management/public';
import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
import { DevToolApp } from './dev_tool';
import { DevToolsSetupDependencies } from './plugin';
import { addHelpMenuToAppChrome } from './utils/util';
Expand All @@ -56,8 +55,7 @@ interface DevToolsWrapperProps {
savedObjects: SavedObjectsStart;
notifications: NotificationsStart;
dataSourceEnabled: boolean;
hideLocalCluster: boolean;
uiSettings: IUiSettingsClient;
dataSourceManagement?: DataSourceManagementPluginSetup;
}

interface MountedDevToolDescriptor {
Expand All @@ -73,8 +71,7 @@ function DevToolsWrapper({
savedObjects,
notifications: { toasts },
dataSourceEnabled,
hideLocalCluster,
uiSettings,
dataSourceManagement,
}: DevToolsWrapperProps) {
const mountedTool = useRef<MountedDevToolDescriptor | null>(null);
const [isLoading, setIsLoading] = React.useState<boolean>(true);
Expand Down Expand Up @@ -117,6 +114,21 @@ function DevToolsWrapper({
setIsLoading(false);
};

const renderDataSourceSelector = () => {
const DataSourceSelector = dataSourceManagement!.ui.DataSourceSelector;
return (
<div className="devAppDataSourceSelector">
<DataSourceSelector
savedObjectsClient={savedObjects.client}
notifications={toasts}
onSelectedDataSource={onChange}
disabled={!dataSourceEnabled}
fullWidth={false}
/>
</div>
);
};

return (
<main className="devApp">
<EuiTabs className="devAppTabs">
Expand All @@ -135,19 +147,7 @@ function DevToolsWrapper({
</EuiTab>
</EuiToolTip>
))}
{dataSourceEnabled && !isLoading ? (
<div className="devAppDataSourceSelector">
<DataSourceSelector
savedObjectsClient={savedObjects.client}
notifications={toasts}
onSelectedDataSource={onChange}
disabled={!dataSourceEnabled}
hideLocalCluster={hideLocalCluster}
fullWidth={false}
uiSettings={uiSettings}
/>
</div>
) : null}
{dataSourceEnabled && !isLoading && dataSourceManagement && renderDataSourceSelector()}
</EuiTabs>

<div
Expand All @@ -162,7 +162,7 @@ function DevToolsWrapper({
mountedTool.current.mountpoint !== element)
) {
let initialDataSourceId;
if (!dataSourceEnabled || (dataSourceEnabled && !hideLocalCluster)) {
if (!dataSourceEnabled) {
initialDataSourceId = '';
}

Expand Down Expand Up @@ -218,14 +218,13 @@ function setBreadcrumbs(chrome: ChromeStart) {
}

export function renderApp(
{ application, chrome, docLinks, savedObjects, notifications, uiSettings }: CoreStart,
{ application, chrome, docLinks, savedObjects, notifications }: CoreStart,
element: HTMLElement,
history: ScopedHistory,
devTools: readonly DevToolApp[],
{ dataSource }: DevToolsSetupDependencies
{ dataSourceManagement, dataSource }: DevToolsSetupDependencies
) {
const dataSourceEnabled = !!dataSource;
const hideLocalCluster = dataSource?.hideLocalCluster ?? false;
if (redirectOnMissingCapabilities(application)) {
return () => {};
}
Expand Down Expand Up @@ -255,8 +254,7 @@ export function renderApp(
savedObjects={savedObjects}
notifications={notifications}
dataSourceEnabled={dataSourceEnabled}
hideLocalCluster={hideLocalCluster}
uiSettings={uiSettings}
dataSourceManagement={dataSourceManagement}
/>
)}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Plugin, CoreSetup, AppMountParameters } from 'src/core/public';
import { AppUpdater } from 'opensearch-dashboards/public';
import { i18n } from '@osd/i18n';
import { sortBy } from 'lodash';

import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
import { DataSourcePluginSetup } from 'src/plugins/data_source/public';
import { AppNavLinkStatus, DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { UrlForwardingSetup } from '../../url_forwarding/public';
Expand All @@ -43,8 +43,9 @@ import './index.scss';
import { ManagementOverViewPluginSetup } from '../../management_overview/public';

export interface DevToolsSetupDependencies {
dataSource?: DataSourcePluginSetup;
urlForwarding: UrlForwardingSetup;
dataSource?: DataSourcePluginSetup;
dataSourceManagement?: DataSourceManagementPluginSetup;
managementOverview?: ManagementOverViewPluginSetup;
}

Expand Down
Loading