-
Notifications
You must be signed in to change notification settings - Fork 884
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
Changes from all commits
0422236
89c8623
9e1ffee
2609a0c
0aa33c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ export const LocalCluster: ClusterOption = { | |||||||||||||
id: '', | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
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'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
export function createClusterSelector() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return (props: ClusterSelectorProps) => <ClusterSelector {...props} />; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
import { ManagementSetup } from '../../management/public'; | ||||||
import { IndexPatternManagementSetup } from '../../index_pattern_management/public'; | ||||||
|
@@ -17,6 +18,7 @@ import { | |||||
AuthenticationMethodRegistery, | ||||||
} from './auth_registry'; | ||||||
import { noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod } from './types'; | ||||||
import { ClusterSelectorProps } from './components/cluster_selector/cluster_selector'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
export interface DataSourceManagementSetupDependencies { | ||||||
management: ManagementSetup; | ||||||
|
@@ -26,6 +28,7 @@ export interface DataSourceManagementSetupDependencies { | |||||
|
||||||
export interface DataSourceManagementPluginSetup { | ||||||
registerAuthenticationMethod: (authMethodValues: AuthenticationMethod) => void; | ||||||
getDataSourcePicker: React.ComponentType<ClusterSelectorProps>; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
export interface DataSourceManagementPluginStart { | ||||||
|
@@ -91,7 +94,10 @@ export class DataSourceManagementPlugin | |||||
registerAuthenticationMethod(sigV4AuthMethod); | ||||||
} | ||||||
|
||||||
return { registerAuthenticationMethod }; | ||||||
return { | ||||||
registerAuthenticationMethod, | ||||||
getDataSourcePicker: createClusterSelector(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if I am understanding correctly, this will expose a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}; | ||||||
} | ||||||
|
||||||
public start(core: CoreStart) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.