Skip to content

Commit

Permalink
Refactor saved object management plugin to use datasourceManagement u…
Browse files Browse the repository at this point in the history
…i API to get DataSourceSelector (#6544)

* Refactor saved object management plugin to use datasourceManagement ui API get DataSourceSelector

Signed-off-by: Zhongnan Su <szhongna@amazon.com>

* Changeset file for PR #6544 created/updated

---------

Signed-off-by: Zhongnan Su <szhongna@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 36a91dd)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent f0a46d8 commit 1fa23b5
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 192 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6544.yml
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"home",
"visBuilder",
"visAugmenter",
"dataSource"
"dataSource",
"dataSourceManagement"
],
"extraPublicDirs": ["public/lib"],
"requiredBundles": ["opensearchDashboardsReact", "home", "dataSourceManagement"]
"requiredBundles": ["opensearchDashboardsReact", "home"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -45,7 +46,7 @@ interface MountParams {
serviceRegistry: ISavedObjectsManagementServiceRegistry;
mountParams: ManagementAppMountParams;
dataSourceEnabled: boolean;
hideLocalCluster: boolean;
dataSourceManagement?: DataSourceManagementPluginSetup;
}

let allowedObjectTypes: string[] | undefined;
Expand All @@ -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;
Expand Down Expand Up @@ -113,7 +114,7 @@ export const mountManagementSection = async ({
allowedTypes={allowedObjectTypes}
setBreadcrumbs={setBreadcrumbs}
dataSourceEnabled={dataSourceEnabled}
hideLocalCluster={hideLocalCluster}
dataSourceManagement={dataSourceManagement}
/>
</Suspense>
</RedirectToHomeIfUnauthorized>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const legacyMockFile = ({
path: '/home/foo.json',
} as unknown) as File;

const dataSourceManagementMock = {
ui: {
DataSourceSelector: () => <div>Mock DataSourceSelector</div>,
},
};

describe('Flyout', () => {
let defaultProps: FlyoutProps;

Expand Down Expand Up @@ -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(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -805,6 +811,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
}

renderImportControlForDataSource(importMode: ImportMode, isLegacyFile: boolean) {
const DataSourceSelector = this.props.dataSourceManagement!.ui.DataSourceSelector;
return (
<div className="savedObjectImportControlForDataSource">
<EuiSpacer />
Expand All @@ -822,8 +829,8 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
notifications={this.props.notifications.toasts}
onSelectedDataSource={this.onSelectedDataSourceChange}
disabled={!this.props.dataSourceEnabled}
hideLocalCluster={this.props.hideLocalCluster}
fullWidth={true}
isClearable={false}
/>
</EuiFormFieldset>
<EuiSpacer />
Expand All @@ -849,7 +856,8 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -119,7 +120,7 @@ export interface SavedObjectsTableProps {
canGoInApp: (obj: SavedObjectWithMetadata) => boolean;
dateFormat: string;
dataSourceEnabled: boolean;
hideLocalCluster: boolean;
dataSourceManagement?: DataSourceManagementPluginSetup;
}

export interface SavedObjectsTableState {
Expand Down Expand Up @@ -588,9 +589,9 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
overlays={this.props.overlays}
search={this.props.search}
dataSourceEnabled={this.props.dataSourceEnabled}
hideLocalCluster={this.props.hideLocalCluster}
savedObjects={this.props.savedObjectsClient}
notifications={this.props.notifications}
dataSourceManagement={this.props.dataSourceManagement}
/>
);
}
Expand Down
Loading

0 comments on commit 1fa23b5

Please sign in to comment.