Skip to content

Commit

Permalink
[MD]Read hideLocalCluster setting from yml and set in data source sel…
Browse files Browse the repository at this point in the history
…ector and data source menu

Signed-off-by: Zhongnan Su <szhongna@amazon.com>
  • Loading branch information
zhongnansu committed Apr 7, 2024
1 parent a0eaf84 commit 519501d
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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
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 { 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 @@ -32,7 +34,10 @@ describe('create data source menu', () => {
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 @@ -52,6 +57,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 +97,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,30 @@
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,
dataSource: DataSourcePluginSetup
) {
return (props: DataSourceMenuProps<T>) => {
const { hideLocalCluster } = dataSource;
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} 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

0 comments on commit 519501d

Please sign in to comment.