Skip to content

Commit

Permalink
add empty state and test except the aggregated view (#6499)
Browse files Browse the repository at this point in the history
* add empty state and test except the aggregated view

Signed-off-by: yujin-emma <[email protected]>

* update change log

Signed-off-by: yujin-emma <[email protected]>

* adjust the order for filter options and empty state check

Signed-off-by: yujin-emma <[email protected]>

* fix lint

Signed-off-by: yujin-emma <[email protected]>

---------

Signed-off-by: yujin-emma <[email protected]>
Signed-off-by: Yu Jin <[email protected]>
(cherry picked from commit c4af2ab)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Apr 18, 2024
1 parent 2f157bc commit bc54113
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SavedObjectsClientContract, ToastsStart } from 'opensearch-dashboards/p
import { getDataSourcesWithFields, handleDataSourceFetchError } from '../utils';
import { SavedObject } from '../../../../../core/public';
import { DataSourceAttributes } from '../../types';
import { NoDataSource } from '../no_data_source';
import { DataSourceErrorMenu } from '../data_source_error_menu';
import { DataSourceBaseState } from '../data_source_menu/types';

Expand Down Expand Up @@ -46,6 +47,7 @@ export class DataSourceAggregatedView extends React.Component<
this.state = {
isPopoverOpen: false,
allDataSourcesIdToTitleMap: new Map(),
showEmptyState: false,
showError: false,
};
}
Expand Down Expand Up @@ -73,7 +75,6 @@ export class DataSourceAggregatedView extends React.Component<
this.props.dataSourceFilter!(ds)
);
}

const allDataSourcesIdToTitleMap = new Map();

filteredDataSources.forEach((ds) => {
Expand Down Expand Up @@ -101,6 +102,9 @@ export class DataSourceAggregatedView extends React.Component<
}

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
}
if (this.state.showError) {
return <DataSourceErrorMenu />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DataSourceSelectable } from '../data_source_selectable';

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

function renderDataSourceView(config: DataSourceViewConfig): ReactElement | null {
const {
activeOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface DataSourceBaseConfig {
}

export interface DataSourceBaseState {
showEmptyState: boolean;
showError: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';
import { SavedObjectsClientContract, ToastsStart } from 'opensearch-dashboards/public';
import { IUiSettingsClient } from 'src/core/public';
import { DataSourceFilterGroup, SelectedDataSourceOption } from './data_source_filter_group';
import { NoDataSource } from '../no_data_source';
import { getDataSourcesWithFields, handleDataSourceFetchError } from '../utils';
import { DataSourceBaseState } from '../data_source_menu/types';
import { DataSourceErrorMenu } from '../data_source_error_menu';
Expand Down Expand Up @@ -39,6 +40,7 @@ export class DataSourceMultiSelectable extends React.Component<
dataSourceOptions: [],
selectedOptions: [],
defaultDataSource: null,
showEmptyState: false,
showError: false,
};
}
Expand Down Expand Up @@ -82,6 +84,7 @@ export class DataSourceMultiSelectable extends React.Component<
...this.state,
selectedOptions,
defaultDataSource,
showEmptyState: (fetchedDataSources?.length === 0 && this.props.hideLocalCluster) || false,
});

this.props.onSelectedDataSources(selectedOptions);
Expand All @@ -107,6 +110,9 @@ export class DataSourceMultiSelectable extends React.Component<
}

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
}
if (this.state.showError) {
return <DataSourceErrorMenu />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ describe('DataSourceSelectable', () => {
],
defaultDataSource: null,
isPopoverOpen: false,
showEmptyState: false,
selectedOption: [
{
id: 'test2',
Expand All @@ -159,6 +160,7 @@ describe('DataSourceSelectable', () => {
],
defaultDataSource: null,
isPopoverOpen: false,
showEmptyState: false,
selectedOption: [
{
checked: 'on',
Expand Down Expand Up @@ -337,6 +339,7 @@ describe('DataSourceSelectable', () => {
],
defaultDataSource: null,
isPopoverOpen: false,
showEmptyState: false,
selectedOption: [
{
id: 'test2',
Expand Down Expand Up @@ -371,6 +374,7 @@ describe('DataSourceSelectable', () => {
defaultDataSource: null,
isPopoverOpen: false,
selectedOption: [],
showEmptyState: false,
showError: true,
});

Expand All @@ -385,6 +389,7 @@ describe('DataSourceSelectable', () => {
],
defaultDataSource: null,
isPopoverOpen: false,
showEmptyState: false,
selectedOption: [
{
checked: 'on',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
} from '../data_source_menu/types';
import { DataSourceErrorMenu } from '../data_source_error_menu';
import { DataSourceItem } from '../data_source_item';
import { NoDataSource } from '../no_data_source';
import './data_source_selectable.scss';
import { DataSourceDropDownHeader } from '../drop_down_header';
import '../button_title.scss';
import './data_source_selectable.scss';
Expand Down Expand Up @@ -81,6 +83,7 @@ export class DataSourceSelectable extends React.Component<
isPopoverOpen: false,
selectedOption: [],
defaultDataSource: null,
showEmptyState: false,
showError: false,
};

Expand Down Expand Up @@ -186,6 +189,10 @@ export class DataSourceSelectable extends React.Component<
this.props.dataSourceFilter
);

if (dataSourceOptions.length === 0 && this.props.hideLocalCluster) {
this.setState({ showEmptyState: true });
}

if (!this.props.hideLocalCluster) {
dataSourceOptions.unshift(LocalCluster);
}
Expand Down Expand Up @@ -243,6 +250,9 @@ export class DataSourceSelectable extends React.Component<
};

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
}
if (this.state.showError) {
return <DataSourceErrorMenu />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
handleNoAvailableDataSourceError,
} from '../utils';
import { LocalCluster } from '../constants';
import { NoDataSource } from '../no_data_source';

interface DataSourceViewProps {
fullWidth: boolean;
Expand All @@ -43,6 +44,7 @@ export class DataSourceView extends React.Component<DataSourceViewProps, DataSou
this.state = {
isPopoverOpen: false,
selectedOption: this.props.selectedOption ? this.props.selectedOption : [],
showEmptyState: !this.props.selectedOption?.length && this.props.hideLocalCluster,
showError: false,
};
}
Expand Down Expand Up @@ -138,6 +140,9 @@ export class DataSourceView extends React.Component<DataSourceViewProps, DataSou
}

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
}
if (this.state.showError) {
return <DataSourceErrorMenu />;
}
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
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { NoDataSource } from './no_data_source';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ShallowWrapper, shallow } from 'enzyme';
import React from 'react';
import { NoDataSource } from './no_data_source';

describe('NoDataSource', () => {
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
it('should render normally', () => {
component = shallow(<NoDataSource />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';

import { EuiButtonEmpty } from '@elastic/eui';

export const NoDataSource = () => {
const label = ' No data sources';
return (
<EuiButtonEmpty
className="euiHeaderLink"
data-test-subj="dataSourceViewContextMenuHeaderLink"
iconType="alert"
iconSide="left"
size="s"
color="primary"
>
{label}
</EuiButtonEmpty>
);
};

0 comments on commit bc54113

Please sign in to comment.