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

[MD] Expose picker using function in data source management plugin setup #6030

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Discover] Fix table cell content overflowing in Safari ([#5948](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5948))
- [BUG][MD]Fix schema for test connection to separate validation based on auth type ([#5997](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5997))
- [Discover] Enable 'Back to Top' Feature in Discover for scrolling to top ([#6008](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6008))
- [BUG][MD]Expose picker using function in data source management plugin setup([#6030](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6030))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [BUG][MD]Expose picker using function in data source management plugin setup([#6030](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6030))
- [BUG][MD]Expose DataSourceSelector using function in data source management plugin setup([#6030](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6030))


### 🚞 Infrastructure

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we rename this file to DataSourceSelector.tsx

interface ClusterSelectorProps {
export interface ClusterSelectorProps {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export interface ClusterSelectorProps {
export interface DataSourceSelectorProps {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut another issue to address the naming #6038

savedObjectsClient: SavedObjectsClientContract;
notifications: ToastsStart;
onSelectedDataSource: (clusterOption: ClusterOption[]) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onSelectedDataSource: (clusterOption: ClusterOption[]) => void;
onSelectedDataSource: (dataSourceOption: DataSourceOption[]) => void;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onSelectedDataSource: (clusterOption: ClusterOption[]) => void;
onSelectedDataSource: (dataSourceOption: DataSourceOption[]) => void;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onSelectedDataSource: (clusterOption: ClusterOption[]) => void;
onSelectedDataSource: (dataSourceOption: DataSourceOption[]) => 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { createClusterSelector } from './create_cluster_selector';
import { dataSourceSelector } from './data_source_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', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('create cluster selector', () => {
describe('create datasource 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const TestComponent = createClusterSelector();
const TestComponent = createDataSourceSelector();

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { ClusterSelector, ClusterSelectorProps } from './cluster_selector';
import { DataSourceSelector, DataSourceSelectorProps } from './datasource_selector';


export function createClusterSelector() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function createClusterSelector() {
export function createDataSourceSelector() {

return (props: ClusterSelectorProps) => <ClusterSelector {...props} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (props: ClusterSelectorProps) => <ClusterSelector {...props} />;
return (props: DataSourceSelectorProps) => <DataSourceSelector {...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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { createClusterSelector } from './components/cluster_selector/create_cluster_selector';
import { createDataSourceSelector } from './components/datasource_selector/create_datasource_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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { ClusterSelectorProps } from './components/cluster_selector/cluster_selector';
import { DataSourceSelectorProps } from './components/datasource_selector/datasource_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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getDataSourcePicker: React.ComponentType<ClusterSelectorProps>;
getDataSourcePicker: React.ComponentType<DataSourceSelectorProps>;

}

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

return { registerAuthenticationMethod };
return {
registerAuthenticationMethod,
getDataSourcePicker: createClusterSelector(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I am understanding correctly, this will expose a function getDataSourcePicker, that plugins should be able to consume via optionalPlugins?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getDataSourcePicker: createClusterSelector(),
getDataSourcePicker: createDataSourceSelector(),

};
}

public start(core: CoreStart) {
Expand Down
Loading