Skip to content

Commit

Permalink
[MD] Expose picker using function in data source management plugin se…
Browse files Browse the repository at this point in the history
…tup (#6030) (#6037)

* expose picker using function in plugin setup

Signed-off-by: Lu Yu <nluyu@amazon.com>

* add changelog and test

Signed-off-by: Lu Yu <nluyu@amazon.com>

---------

Signed-off-by: Lu Yu <nluyu@amazon.com>
(cherry picked from commit 49d1649)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3213c31 commit 0cad69d
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 2 deletions.

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 @@ -16,7 +16,7 @@ export const LocalCluster: ClusterOption = {
id: '',
};

interface ClusterSelectorProps {
export interface ClusterSelectorProps {
savedObjectsClient: SavedObjectsClientContract;
notifications: ToastsStart;
onSelectedDataSource: (clusterOption: ClusterOption[]) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { createClusterSelector } from './create_cluster_selector';
import { SavedObjectsClientContract } from '../../../../../core/public';
import { notificationServiceMock } from '../../../../../core/public/mocks';
import React from 'react';
import { render } from '@testing-library/react';

describe('create cluster selector', () => {
let client: SavedObjectsClientContract;
const { toasts } = notificationServiceMock.createStartContract();

beforeEach(() => {
client = {
find: jest.fn().mockResolvedValue([]),
} as any;
});

it('should render normally', () => {
const props = {
savedObjectsClient: client,
notifications: toasts,
onSelectedDataSource: jest.fn(),
disabled: false,
hideLocalCluster: false,
fullWidth: false,
};
const TestComponent = createClusterSelector();
const component = render(<TestComponent {...props} />);
expect(component).toMatchSnapshot();
expect(client.find).toBeCalledWith({
fields: ['id', 'description', 'title'],
perPage: 10000,
type: 'data-source',
});
expect(toasts.addWarning).toBeCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { ClusterSelector, ClusterSelectorProps } from './cluster_selector';

export function createClusterSelector() {
return (props: ClusterSelectorProps) => <ClusterSelector {...props} />;
}
8 changes: 7 additions & 1 deletion src/plugins/data_source_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DataSourcePluginSetup } from 'src/plugins/data_source/public';
import { CoreSetup, CoreStart, Plugin } from '../../../core/public';

import { PLUGIN_NAME } from '../common';
import { createClusterSelector } from './components/cluster_selector/create_cluster_selector';

import { ManagementSetup } from '../../management/public';
import { IndexPatternManagementSetup } from '../../index_pattern_management/public';
Expand All @@ -17,6 +18,7 @@ import {
AuthenticationMethodRegistery,
} from './auth_registry';
import { noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod } from './types';
import { ClusterSelectorProps } from './components/cluster_selector/cluster_selector';

export interface DataSourceManagementSetupDependencies {
management: ManagementSetup;
Expand All @@ -26,6 +28,7 @@ export interface DataSourceManagementSetupDependencies {

export interface DataSourceManagementPluginSetup {
registerAuthenticationMethod: (authMethodValues: AuthenticationMethod) => void;
getDataSourcePicker: React.ComponentType<ClusterSelectorProps>;
}

export interface DataSourceManagementPluginStart {
Expand Down Expand Up @@ -91,7 +94,10 @@ export class DataSourceManagementPlugin
registerAuthenticationMethod(sigV4AuthMethod);
}

return { registerAuthenticationMethod };
return {
registerAuthenticationMethod,
getDataSourcePicker: createClusterSelector(),
};
}

public start(core: CoreStart) {
Expand Down

0 comments on commit 0cad69d

Please sign in to comment.