Skip to content

Commit

Permalink
Merge branch 'main' into current-workspace-in-server-side
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe authored Apr 10, 2024
2 parents c8d5b9e + 8151ef5 commit 60ba1bb
Show file tree
Hide file tree
Showing 33 changed files with 1,635 additions and 261 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Enhanced data source selector with default datasource shows as first choice ([#6293](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6293))
- [Multiple Datasource] Add multi data source support to sample vega visualizations ([#6218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6218))
- [Multiple Datasource] Fetch data source title for DataSourceView when only id is provided ([#6315](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6315)
- [Multiple Datasource] Get data source label when only id is provided in DataSourceSelectable ([#6358](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6358)
- [Workspace] Add permission control logic ([#6052](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6052))
- [Multiple Datasource] Add default icon for selectable component and make sure the default datasource shows automatically ([#6327](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6327))
- [Multiple Datasource] Pass selected data sources to plugin consumers when the multi-select component initially loads ([#6333](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6333))
- [Multiple Datasource] Add installedPlugins list to data source saved object ([#6348](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6348))
- [Multiple Datasource] Add default icon in multi-selectable picker ([#6357](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6357))
- [Workspace] Add APIs to support plugin state in request ([#6303](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6303))
- [Workspace] Filter left nav menu items according to the current workspace ([#6234](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6234))
- [Multiple Datasource] Refactor data source selector component to include placeholder and add tests ([#6372](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6372))
- [Workspace] Support workspace in saved objects client in server side. ([#6365](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6365))

### 🐛 Bug Fixes
Expand All @@ -105,6 +109,8 @@ 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))
- [BUG] Fix for checkForFunctionProperty so that order does not matter ([#6248](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6248))

### 🚞 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,35 @@ 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(2);
});
});

describe('when setMenuMountPoint is provided', () => {
Expand All @@ -52,6 +86,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 +126,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,20 +36,15 @@ 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}
hideLocalCluster={hideLocalCluster || false}
savedObjectsClient={savedObjects!}
notifications={notifications!.toasts}
onSelectedDataSources={onSelectedDataSources!}
uiSettings={uiSettings}
/>
);
}
Expand All @@ -59,7 +54,6 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
onSelectedDataSources,
disabled,
activeOption,
hideLocalCluster,
fullWidth,
savedObjects,
notifications,
Expand All @@ -85,7 +79,6 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
): ReactElement | null {
const {
fullWidth,
hideLocalCluster,
activeDataSourceIds,
displayAllCompatibleDataSources,
savedObjects,
Expand Down
Loading

0 comments on commit 60ba1bb

Please sign in to comment.