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

[Backport 2.x] [MD]Read hideLocalCluster setting from yml and set in data source selector and data source menu #6374

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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

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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface DataSourceBaseConfig {
export interface DataSourceMenuProps<T = any> {
componentType: DataSourceComponentType;
componentConfig: T;
hideLocalCluster?: boolean;
uiSettings?: IUiSettingsClient;
setMenuMountPoint?: (menuMount: MountPoint | undefined) => void;
}
Expand All @@ -47,7 +48,6 @@ export interface DataSourceAggregatedViewConfig extends DataSourceBaseConfig {
savedObjects: SavedObjectsClientContract;
notifications: NotificationsStart;
activeDataSourceIds?: string[];
hideLocalCluster?: boolean;
displayAllCompatibleDataSources?: boolean;
dataSourceFilter?: (dataSource: SavedObject<DataSourceAttributes>) => boolean;
}
Expand All @@ -57,13 +57,11 @@ export interface DataSourceSelectableConfig extends DataSourceBaseConfig {
savedObjects: SavedObjectsClientContract;
notifications: NotificationsStart;
activeOption?: DataSourceOption[];
hideLocalCluster?: boolean;
dataSourceFilter?: (dataSource: SavedObject<DataSourceAttributes>) => boolean;
}

export interface DataSourceMultiSelectableConfig extends DataSourceBaseConfig {
onSelectedDataSources: (dataSources: DataSourceOption[]) => void;
savedObjects: SavedObjectsClientContract;
notifications: NotificationsStart;
hideLocalCluster?: boolean;
}
Loading
Loading