diff --git a/changelogs/fragments/6544.yml b/changelogs/fragments/6544.yml new file mode 100644 index 000000000000..53d6283a6d47 --- /dev/null +++ b/changelogs/fragments/6544.yml @@ -0,0 +1,2 @@ +refactor: +- Refactor saved object management plugin to use datasourceManagement ui API to get DataSourceSelector ([#6544](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6544)) \ No newline at end of file diff --git a/src/plugins/saved_objects_management/opensearch_dashboards.json b/src/plugins/saved_objects_management/opensearch_dashboards.json index a4a4aa3853a0..225fe67e9f57 100644 --- a/src/plugins/saved_objects_management/opensearch_dashboards.json +++ b/src/plugins/saved_objects_management/opensearch_dashboards.json @@ -11,8 +11,9 @@ "home", "visBuilder", "visAugmenter", - "dataSource" + "dataSource", + "dataSourceManagement" ], "extraPublicDirs": ["public/lib"], - "requiredBundles": ["opensearchDashboardsReact", "home", "dataSourceManagement"] + "requiredBundles": ["opensearchDashboardsReact", "home"] } diff --git a/src/plugins/saved_objects_management/public/management_section/mount_section.tsx b/src/plugins/saved_objects_management/public/management_section/mount_section.tsx index 967dd93290d2..1c9bf676d5b3 100644 --- a/src/plugins/saved_objects_management/public/management_section/mount_section.tsx +++ b/src/plugins/saved_objects_management/public/management_section/mount_section.tsx @@ -35,6 +35,7 @@ import { I18nProvider } from '@osd/i18n/react'; import { i18n } from '@osd/i18n'; import { EuiLoadingSpinner } from '@elastic/eui'; import { CoreSetup } from 'src/core/public'; +import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public'; import { ManagementAppMountParams } from '../../../management/public'; import { StartDependencies, SavedObjectsManagementPluginStart } from '../plugin'; import { ISavedObjectsManagementServiceRegistry } from '../services'; @@ -45,7 +46,7 @@ interface MountParams { serviceRegistry: ISavedObjectsManagementServiceRegistry; mountParams: ManagementAppMountParams; dataSourceEnabled: boolean; - hideLocalCluster: boolean; + dataSourceManagement?: DataSourceManagementPluginSetup; } let allowedObjectTypes: string[] | undefined; @@ -61,7 +62,7 @@ export const mountManagementSection = async ({ mountParams, serviceRegistry, dataSourceEnabled, - hideLocalCluster, + dataSourceManagement, }: MountParams) => { const [coreStart, { data, uiActions }, pluginStart] = await core.getStartServices(); const { element, history, setBreadcrumbs } = mountParams; @@ -113,7 +114,7 @@ export const mountManagementSection = async ({ allowedTypes={allowedObjectTypes} setBreadcrumbs={setBreadcrumbs} dataSourceEnabled={dataSourceEnabled} - hideLocalCluster={hideLocalCluster} + dataSourceManagement={dataSourceManagement} /> diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap index d4a33e4a0569..97616da2352b 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap @@ -528,7 +528,7 @@ Array [ ] `; -exports[`Flyout should render cluster selector and import options when local cluster option is hidden 1`] = ` +exports[`Flyout should render cluster selector and import options when datasource is enabled 1`] = ` `; -exports[`Flyout should render cluster selector and import options when local cluster option is not hidden 1`] = ` - - - -

- -

-
-
- - - - } - labelType="label" - > - - } - onChange={[Function]} - /> - -
- - - - Import options - - , - } - } - > - - - - - - -
-
-
- - - - - - - - - - - - - - -
-`; - exports[`Flyout should render import step 1`] = `
Mock DataSourceSelector
, + }, +}; + describe('Flyout', () => { let defaultProps: FlyoutProps; @@ -99,27 +105,11 @@ describe('Flyout', () => { expect(component).toMatchSnapshot(); }); - it('should render cluster selector and import options when local cluster option is not hidden', async () => { - const component = shallowRender({ - ...defaultProps, - dataSourceEnabled: true, - hideLocalCluster: false, - notifications: notificationServiceMock.createStartContract(), - }); - - // Ensure all promises resolve - await new Promise((resolve) => process.nextTick(resolve)); - // Ensure the state changes are reflected - component.update(); - - expect(component).toMatchSnapshot(); - }); - - it('should render cluster selector and import options when local cluster option is hidden', async () => { + it('should render cluster selector and import options when datasource is enabled', async () => { const component = shallowRender({ ...defaultProps, dataSourceEnabled: true, - hideLocalCluster: true, + dataSourceManagement: dataSourceManagementMock, notifications: notificationServiceMock.createStartContract(), }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx index 03b15ada3201..fb2f98855364 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx @@ -54,8 +54,13 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; -import { OverlayStart, HttpStart } from 'src/core/public'; -import { DataSourceSelector } from '../../../../../data_source_management/public'; +import { + OverlayStart, + HttpStart, + NotificationsStart, + SavedObjectsClientContract, +} from 'src/core/public'; +import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public'; import { IndexPatternsContract, IIndexPattern, @@ -80,6 +85,7 @@ import { FailedImportConflict, RetryDecision } from '../../../lib/resolve_import import { OverwriteModal } from './overwrite_modal'; import { ImportModeControl, ImportMode } from './import_mode_control'; import { ImportSummary } from './import_summary'; + const CREATE_NEW_COPIES_DEFAULT = true; const OVERWRITE_ALL_DEFAULT = true; @@ -94,9 +100,9 @@ export interface FlyoutProps { http: HttpStart; search: DataPublicPluginStart['search']; dataSourceEnabled: boolean; - hideLocalCluster: boolean; savedObjects: SavedObjectsClientContract; notifications: NotificationsStart; + dataSourceManagement?: DataSourceManagementPluginSetup; } export interface FlyoutState { @@ -811,6 +817,7 @@ export class Flyout extends Component { } renderImportControlForDataSource(importMode: ImportMode, isLegacyFile: boolean) { + const DataSourceSelector = this.props.dataSourceManagement!.ui.DataSourceSelector; return (
@@ -828,8 +835,8 @@ export class Flyout extends Component { notifications={this.props.notifications.toasts} onSelectedDataSource={this.onSelectedDataSourceChange} disabled={!this.props.dataSourceEnabled} - hideLocalCluster={this.props.hideLocalCluster} fullWidth={true} + isClearable={false} /> @@ -855,7 +862,8 @@ export class Flyout extends Component { let confirmButton; let importButtonDisabled = false; - if (this.props.dataSourceEnabled && this.props.hideLocalCluster && !selectedDataSourceId) { + // If a data source is enabled, the import button should be disabled when there's no selected data source + if (this.props.dataSourceEnabled && selectedDataSourceId === undefined) { importButtonDisabled = true; } diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 5533359e345a..56e7950efeea 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -58,6 +58,7 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; +import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public'; import { SavedObjectsClientContract, SavedObjectsFindOptions, @@ -121,7 +122,7 @@ export interface SavedObjectsTableProps { canGoInApp: (obj: SavedObjectWithMetadata) => boolean; dateFormat: string; dataSourceEnabled: boolean; - hideLocalCluster: boolean; + dataSourceManagement?: DataSourceManagementPluginSetup; } export interface SavedObjectsTableState { @@ -650,9 +651,9 @@ export class SavedObjectsTable extends Component ); } diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index 42889d6d8095..425baca096d2 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -32,11 +32,13 @@ import React, { useEffect } from 'react'; import { get } from 'lodash'; import { i18n } from '@osd/i18n'; import { CoreStart, ChromeBreadcrumb } from 'src/core/public'; +import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public'; import { DataPublicPluginStart } from '../../../data/public'; import { ISavedObjectsManagementServiceRegistry, SavedObjectsManagementActionServiceStart, SavedObjectsManagementColumnServiceStart, + SavedObjectsManagementNamespaceServiceStart, } from '../services'; import { SavedObjectsTable } from './objects_table'; @@ -50,7 +52,7 @@ const SavedObjectsTablePage = ({ namespaceRegistry, setBreadcrumbs, dataSourceEnabled, - hideLocalCluster, + dataSourceManagement, }: { coreStart: CoreStart; dataStart: DataPublicPluginStart; @@ -61,7 +63,7 @@ const SavedObjectsTablePage = ({ namespaceRegistry: SavedObjectsManagementNamespaceServiceStart; setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void; dataSourceEnabled: boolean; - hideLocalCluster: boolean; + dataSourceManagement?: DataSourceManagementPluginSetup; }) => { const capabilities = coreStart.application.capabilities; const itemsPerPage = coreStart.uiSettings.get('savedObjects:perPage', 50); @@ -108,7 +110,7 @@ const SavedObjectsTablePage = ({ return inAppUrl ? Boolean(get(capabilities, inAppUrl.uiCapabilitiesPath)) : false; }} dataSourceEnabled={dataSourceEnabled} - hideLocalCluster={hideLocalCluster} + dataSourceManagement={dataSourceManagement} /> ); }; diff --git a/src/plugins/saved_objects_management/public/plugin.ts b/src/plugins/saved_objects_management/public/plugin.ts index 035bf096a1af..831daa0df443 100644 --- a/src/plugins/saved_objects_management/public/plugin.ts +++ b/src/plugins/saved_objects_management/public/plugin.ts @@ -32,6 +32,7 @@ import { i18n } from '@osd/i18n'; import { CoreSetup, CoreStart, Plugin } from 'src/core/public'; import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; +import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public'; import { VisBuilderStart } from '../../vis_builder/public'; import { ManagementSetup } from '../../management/public'; import { UiActionsSetup, UiActionsStart } from '../../ui_actions/public'; @@ -79,6 +80,7 @@ export interface SetupDependencies { home?: HomePublicPluginSetup; uiActions: UiActionsSetup; dataSource?: DataSourcePluginSetup; + dataSourceManagement?: DataSourceManagementPluginSetup; } export interface StartDependencies { @@ -107,7 +109,7 @@ export class SavedObjectsManagementPlugin public setup( core: CoreSetup, - { home, management, uiActions, dataSource }: SetupDependencies + { home, management, uiActions, dataSource, dataSourceManagement }: SetupDependencies ): SavedObjectsManagementPluginSetup { const actionSetup = this.actionService.setup(); const columnSetup = this.columnService.setup(); @@ -144,7 +146,7 @@ export class SavedObjectsManagementPlugin serviceRegistry: this.serviceRegistry, mountParams, dataSourceEnabled: !!dataSource, - hideLocalCluster: dataSource?.hideLocalCluster ?? false, + dataSourceManagement, }); }, });