Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into copy
Browse files Browse the repository at this point in the history
  • Loading branch information
gaobinlong committed Apr 9, 2024
2 parents 23d5515 + b4130aa commit ac7afb8
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Workspace] Add base path when parse url in http service ([#6233](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6233))
- [Multiple Datasource] Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset ([#6282](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6282))
- [BUG][Multiple Datasource]Fix bug in data source aggregated view to change it to depend on displayAllCompatibleDataSources property to show the badge value ([#6291](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6291))
- [BUG][Multiple Datasource]Read hideLocalCluster setting from yml and set in data source selector and data source menu ([#6361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6361))

### 🚞 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 @@ -5,15 +5,17 @@

import { createDataSourceMenu } from './create_data_source_menu';
import { MountPoint, SavedObjectsClientContract } from '../../../../../core/public';
import { notificationServiceMock } from '../../../../../core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../core/public/mocks';
import React from 'react';
import { act, render } from '@testing-library/react';
import { act, getByText, render } from '@testing-library/react';
import { DataSourceComponentType, DataSourceSelectableConfig } from './types';
import { ReactWrapper } from 'enzyme';
import { mockDataSourcePluginSetupWithShowLocalCluster } from '../../mocks';

describe('create data source menu', () => {
let client: SavedObjectsClientContract;
const notifications = notificationServiceMock.createStartContract();
const { uiSettings } = coreMock.createSetup();

beforeEach(() => {
client = {
Expand All @@ -26,13 +28,16 @@ describe('create data source menu', () => {
componentType: DataSourceComponentType.DataSourceSelectable,
componentConfig: {
fullWidth: true,
hideLocalCluster: true,
onSelectedDataSources: jest.fn(),
savedObjects: client,
notifications,
},
};
const TestComponent = createDataSourceMenu<DataSourceSelectableConfig>();
const TestComponent = createDataSourceMenu<DataSourceSelectableConfig>(
uiSettings,
mockDataSourcePluginSetupWithShowLocalCluster
);

const component = render(<TestComponent {...props} />);
expect(component).toMatchSnapshot();
expect(client.find).toBeCalledWith({
Expand All @@ -42,6 +47,36 @@ describe('create data source menu', () => {
});
expect(notifications.toasts.addWarning).toBeCalledTimes(0);
});

it('should ignore props.hideLocalCluster, and show local cluster when data_source.hideLocalCluster is set to false', async () => {
let component;
const props = {
componentType: DataSourceComponentType.DataSourceSelectable,
hideLocalCluster: true,
componentConfig: {
fullWidth: true,
onSelectedDataSources: jest.fn(),
savedObjects: client,
notifications,
},
};
const TestComponent = createDataSourceMenu<DataSourceSelectableConfig>(
uiSettings,
mockDataSourcePluginSetupWithShowLocalCluster
);
await act(async () => {
component = render(<TestComponent {...props} />);
});

expect(component).toMatchSnapshot();
expect(client.find).toBeCalledWith({
fields: ['id', 'title', 'auth.type'],
perPage: 10000,
type: 'data-source',
});
expect(notifications.toasts.addWarning).toBeCalledTimes(0);
expect(getByText(component.container, 'Local cluster')).toBeInTheDocument();
});
});

describe('when setMenuMountPoint is provided', () => {
Expand All @@ -52,6 +87,7 @@ describe('when setMenuMountPoint is provided', () => {

let client: SavedObjectsClientContract;
const notifications = notificationServiceMock.createStartContract();
const { uiSettings } = coreMock.createSetup();

const refresh = () => {
new Promise(async (resolve) => {
Expand Down Expand Up @@ -91,7 +127,10 @@ describe('when setMenuMountPoint is provided', () => {
notifications,
},
};
const TestComponent = createDataSourceMenu<DataSourceSelectableConfig>();
const TestComponent = createDataSourceMenu<DataSourceSelectableConfig>(
uiSettings,
mockDataSourcePluginSetupWithShowLocalCluster
);
const component = render(<TestComponent {...props} />);
act(() => {
mountPoint(portalTarget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
import React from 'react';
import { EuiHeaderLinks } from '@elastic/eui';
import { IUiSettingsClient } from 'src/core/public';
import { DataSourcePluginSetup } from 'src/plugins/data_source/public';
import { DataSourceMenu } from './data_source_menu';
import { DataSourceMenuProps } from './types';
import { MountPointPortal } from '../../../../opensearch_dashboards_react/public';

export function createDataSourceMenu<T>(uiSettings: IUiSettingsClient) {
export function createDataSourceMenu<T>(
uiSettings: IUiSettingsClient,
dataSourcePluginSetup: DataSourcePluginSetup
) {
return (props: DataSourceMenuProps<T>) => {
const { hideLocalCluster } = dataSourcePluginSetup;
if (props.setMenuMountPoint) {
return (
<MountPointPortal setMountPoint={props.setMenuMountPoint}>
<EuiHeaderLinks data-test-subj="top-nav" gutterSize="xs">
<DataSourceMenu {...props} uiSettings={uiSettings} />
<DataSourceMenu
{...props}
uiSettings={uiSettings}
hideLocalCluster={hideLocalCluster}
/>
</EuiHeaderLinks>
</MountPointPortal>
);
}
return <DataSourceMenu {...props} />;
return (
<DataSourceMenu {...props} uiSettings={uiSettings} hideLocalCluster={hideLocalCluster} />
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceSelectable}
componentConfig={{
fullWidth: true,
hideLocalCluster: false,
onSelectedDataSources: jest.fn(),
savedObjects: client,
notifications,
Expand All @@ -43,9 +42,9 @@ describe('DataSourceMenu', () => {
component = shallow(
<DataSourceMenu
componentType={DataSourceComponentType.DataSourceSelectable}
hideLocalCluster={true}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
onSelectedDataSources: jest.fn(),
savedObjects: client,
notifications,
Expand All @@ -61,7 +60,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceView}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
savedObjects: client,
notifications,
}}
Expand All @@ -76,7 +74,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceView}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
notifications,
}}
/>
Expand All @@ -90,7 +87,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceView}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
savedObjects: client,
notifications,
activeOption: [{ id: 'test', label: 'test-label' }],
Expand All @@ -106,7 +102,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceView}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
savedObjects: client,
notifications,
activeOption: [{ id: 'test' }],
Expand All @@ -122,7 +117,6 @@ describe('DataSourceMenu', () => {
componentType={DataSourceComponentType.DataSourceAggregatedView}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
savedObjects: client,
notifications,
displayAllCompatibleDataSources: true,
Expand All @@ -138,7 +132,6 @@ describe('DataSourceMenu', () => {
componentType={''}
componentConfig={{
fullWidth: true,
hideLocalCluster: true,
savedObjects: client,
notifications,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { DataSourceSelectable } from '../data_source_selectable';

export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement | null {
const { componentType, componentConfig, uiSettings } = props;
const { componentType, componentConfig, uiSettings, hideLocalCluster } = props;

function renderDataSourceView(config: DataSourceViewConfig): ReactElement | null {
const { activeOption, fullWidth, savedObjects, notifications } = config;
Expand All @@ -36,13 +36,7 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
function renderDataSourceMultiSelectable(
config: DataSourceMultiSelectableConfig
): ReactElement | null {
const {
fullWidth,
hideLocalCluster,
savedObjects,
notifications,
onSelectedDataSources,
} = config;
const { fullWidth, savedObjects, notifications, onSelectedDataSources } = config;
return (
<DataSourceMultiSelectable
fullWidth={fullWidth}
Expand All @@ -59,7 +53,6 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
onSelectedDataSources,
disabled,
activeOption,
hideLocalCluster,
fullWidth,
savedObjects,
notifications,
Expand All @@ -85,7 +78,6 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
): ReactElement | null {
const {
fullWidth,
hideLocalCluster,
activeDataSourceIds,
displayAllCompatibleDataSources,
savedObjects,
Expand Down
Loading

0 comments on commit ac7afb8

Please sign in to comment.