Skip to content

Commit 2a641de

Browse files
opensearch-trigger-bot[bot]github-actions[bot]opensearch-changeset-bot[bot]
authored
Refactor saved object management plugin to use datasourceManagement ui API to get DataSourceSelector (#6544) (#6556)
* Refactor saved object management plugin to use datasourceManagement ui API get DataSourceSelector * Changeset file for PR #6544 created/updated --------- (cherry picked from commit 36a91dd) Signed-off-by: Zhongnan Su <szhongna@amazon.com> 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: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent f0a46d8 commit 2a641de

File tree

9 files changed

+44
-192
lines changed

9 files changed

+44
-192
lines changed

changelogs/fragments/6544.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
refactor:
2+
- Refactor saved object management plugin to use datasourceManagement ui API to get DataSourceSelector ([#6544](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6544))

src/plugins/saved_objects_management/opensearch_dashboards.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"home",
1212
"visBuilder",
1313
"visAugmenter",
14-
"dataSource"
14+
"dataSource",
15+
"dataSourceManagement"
1516
],
1617
"extraPublicDirs": ["public/lib"],
17-
"requiredBundles": ["opensearchDashboardsReact", "home", "dataSourceManagement"]
18+
"requiredBundles": ["opensearchDashboardsReact", "home"]
1819
}

src/plugins/saved_objects_management/public/management_section/mount_section.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { I18nProvider } from '@osd/i18n/react';
3535
import { i18n } from '@osd/i18n';
3636
import { EuiLoadingSpinner } from '@elastic/eui';
3737
import { CoreSetup } from 'src/core/public';
38+
import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
3839
import { ManagementAppMountParams } from '../../../management/public';
3940
import { StartDependencies, SavedObjectsManagementPluginStart } from '../plugin';
4041
import { ISavedObjectsManagementServiceRegistry } from '../services';
@@ -45,7 +46,7 @@ interface MountParams {
4546
serviceRegistry: ISavedObjectsManagementServiceRegistry;
4647
mountParams: ManagementAppMountParams;
4748
dataSourceEnabled: boolean;
48-
hideLocalCluster: boolean;
49+
dataSourceManagement?: DataSourceManagementPluginSetup;
4950
}
5051

5152
let allowedObjectTypes: string[] | undefined;
@@ -61,7 +62,7 @@ export const mountManagementSection = async ({
6162
mountParams,
6263
serviceRegistry,
6364
dataSourceEnabled,
64-
hideLocalCluster,
65+
dataSourceManagement,
6566
}: MountParams) => {
6667
const [coreStart, { data, uiActions }, pluginStart] = await core.getStartServices();
6768
const { element, history, setBreadcrumbs } = mountParams;
@@ -113,7 +114,7 @@ export const mountManagementSection = async ({
113114
allowedTypes={allowedObjectTypes}
114115
setBreadcrumbs={setBreadcrumbs}
115116
dataSourceEnabled={dataSourceEnabled}
116-
hideLocalCluster={hideLocalCluster}
117+
dataSourceManagement={dataSourceManagement}
117118
/>
118119
</Suspense>
119120
</RedirectToHomeIfUnauthorized>

src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap

Lines changed: 2 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.test.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ const legacyMockFile = ({
5555
path: '/home/foo.json',
5656
} as unknown) as File;
5757

58+
const dataSourceManagementMock = {
59+
ui: {
60+
DataSourceSelector: () => <div>Mock DataSourceSelector</div>,
61+
},
62+
};
63+
5864
describe('Flyout', () => {
5965
let defaultProps: FlyoutProps;
6066

@@ -99,27 +105,11 @@ describe('Flyout', () => {
99105
expect(component).toMatchSnapshot();
100106
});
101107

102-
it('should render cluster selector and import options when local cluster option is not hidden', async () => {
103-
const component = shallowRender({
104-
...defaultProps,
105-
dataSourceEnabled: true,
106-
hideLocalCluster: false,
107-
notifications: notificationServiceMock.createStartContract(),
108-
});
109-
110-
// Ensure all promises resolve
111-
await new Promise((resolve) => process.nextTick(resolve));
112-
// Ensure the state changes are reflected
113-
component.update();
114-
115-
expect(component).toMatchSnapshot();
116-
});
117-
118-
it('should render cluster selector and import options when local cluster option is hidden', async () => {
108+
it('should render cluster selector and import options when datasource is enabled', async () => {
119109
const component = shallowRender({
120110
...defaultProps,
121111
dataSourceEnabled: true,
122-
hideLocalCluster: true,
112+
dataSourceManagement: dataSourceManagementMock,
123113
notifications: notificationServiceMock.createStartContract(),
124114
});
125115

src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ import {
5454
} from '@elastic/eui';
5555
import { i18n } from '@osd/i18n';
5656
import { FormattedMessage } from '@osd/i18n/react';
57-
import { OverlayStart, HttpStart } from 'src/core/public';
58-
import { DataSourceSelector } from '../../../../../data_source_management/public';
57+
import {
58+
OverlayStart,
59+
HttpStart,
60+
NotificationsStart,
61+
SavedObjectsClientContract,
62+
} from 'src/core/public';
63+
import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
5964
import {
6065
IndexPatternsContract,
6166
IIndexPattern,
@@ -80,6 +85,7 @@ import { FailedImportConflict, RetryDecision } from '../../../lib/resolve_import
8085
import { OverwriteModal } from './overwrite_modal';
8186
import { ImportModeControl, ImportMode } from './import_mode_control';
8287
import { ImportSummary } from './import_summary';
88+
8389
const CREATE_NEW_COPIES_DEFAULT = true;
8490
const OVERWRITE_ALL_DEFAULT = true;
8591

@@ -94,9 +100,9 @@ export interface FlyoutProps {
94100
http: HttpStart;
95101
search: DataPublicPluginStart['search'];
96102
dataSourceEnabled: boolean;
97-
hideLocalCluster: boolean;
98103
savedObjects: SavedObjectsClientContract;
99104
notifications: NotificationsStart;
105+
dataSourceManagement?: DataSourceManagementPluginSetup;
100106
}
101107

102108
export interface FlyoutState {
@@ -805,6 +811,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
805811
}
806812

807813
renderImportControlForDataSource(importMode: ImportMode, isLegacyFile: boolean) {
814+
const DataSourceSelector = this.props.dataSourceManagement!.ui.DataSourceSelector;
808815
return (
809816
<div className="savedObjectImportControlForDataSource">
810817
<EuiSpacer />
@@ -822,8 +829,8 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
822829
notifications={this.props.notifications.toasts}
823830
onSelectedDataSource={this.onSelectedDataSourceChange}
824831
disabled={!this.props.dataSourceEnabled}
825-
hideLocalCluster={this.props.hideLocalCluster}
826832
fullWidth={true}
833+
isClearable={false}
827834
/>
828835
</EuiFormFieldset>
829836
<EuiSpacer />
@@ -849,7 +856,8 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
849856
let confirmButton;
850857

851858
let importButtonDisabled = false;
852-
if (this.props.dataSourceEnabled && this.props.hideLocalCluster && !selectedDataSourceId) {
859+
// If a data source is enabled, the import button should be disabled when there's no selected data source
860+
if (this.props.dataSourceEnabled && selectedDataSourceId === undefined) {
853861
importButtonDisabled = true;
854862
}
855863

src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
} from '@elastic/eui';
5959
import { i18n } from '@osd/i18n';
6060
import { FormattedMessage } from '@osd/i18n/react';
61+
import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
6162
import {
6263
SavedObjectsClientContract,
6364
SavedObjectsFindOptions,
@@ -119,7 +120,7 @@ export interface SavedObjectsTableProps {
119120
canGoInApp: (obj: SavedObjectWithMetadata) => boolean;
120121
dateFormat: string;
121122
dataSourceEnabled: boolean;
122-
hideLocalCluster: boolean;
123+
dataSourceManagement?: DataSourceManagementPluginSetup;
123124
}
124125

125126
export interface SavedObjectsTableState {
@@ -588,9 +589,9 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
588589
overlays={this.props.overlays}
589590
search={this.props.search}
590591
dataSourceEnabled={this.props.dataSourceEnabled}
591-
hideLocalCluster={this.props.hideLocalCluster}
592592
savedObjects={this.props.savedObjectsClient}
593593
notifications={this.props.notifications}
594+
dataSourceManagement={this.props.dataSourceManagement}
594595
/>
595596
);
596597
}

0 commit comments

Comments
 (0)