Skip to content

Commit

Permalink
[Multiple Datasource] add popover for Data Source empty state (#6514)
Browse files Browse the repository at this point in the history
* add empty state popover

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

* fix failed test

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 d8ddc1a)
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 08c8a5d commit 63c9581
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,22 @@ describe('DataSourceSelectable', () => {
expect(onSelectedDataSource).toBeCalledWith([{ id: 'test2', label: 'test2' }]);
expect(onSelectedDataSource).toHaveBeenCalled();
});
it('should render no data source when no data source filtered out and hide local cluster', async () => {
const onSelectedDataSource = jest.fn();
const container = render(
<DataSourceSelectable
savedObjectsClient={client}
notifications={toasts}
onSelectedDataSources={onSelectedDataSource}
disabled={false}
hideLocalCluster={true}
fullWidth={false}
selectedOption={[{ id: 'test2' }]}
dataSourceFilter={(ds) => false}
/>
);
await nextTick();
const button = await container.findByTestId('dataSourceEmptyStateHeaderButton');
expect(button).toHaveTextContent('No data sources');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ export class DataSourceSelectable extends React.Component<

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
return (
<NoDataSource
totalDataSourceCount={this.state.dataSourceOptions.length}
application={this.props.application}
/>
);
}
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
Expand Up @@ -136,4 +136,21 @@ describe('DataSourceView', () => {
button.click();
expect(container).toMatchSnapshot();
});

it('should render no data source when no data source filtered out and hide local cluster', async () => {
const onSelectedDataSource = jest.fn();
const container = render(
<DataSourceView
savedObjectsClient={client}
notifications={toasts}
onSelectedDataSources={onSelectedDataSource}
hideLocalCluster={true}
fullWidth={false}
selectedOption={[{ id: '' }]}
dataSourceFilter={(ds) => false}
/>
);
const button = await container.findByTestId('dataSourceEmptyStateHeaderButton');
expect(button).toHaveTextContent('No data sources');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ interface DataSourceViewProps {
fullWidth: boolean;
selectedOption: DataSourceOption[];
hideLocalCluster: boolean;
application?: ApplicationStart;
savedObjectsClient?: SavedObjectsClientContract;
notifications?: ToastsStart;
uiSettings?: IUiSettingsClient;
application?: ApplicationStart;
dataSourceFilter?: (dataSource: any) => boolean;
onSelectedDataSources?: (dataSources: DataSourceOption[]) => void;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export class DataSourceView extends React.Component<DataSourceViewProps, DataSou
) {
this.setState({
selectedOption: [],
defaultDataSource,
showEmptyState: true,
});
if (this.props.onSelectedDataSources) {
this.props.onSelectedDataSources([]);
Expand Down Expand Up @@ -146,7 +146,12 @@ export class DataSourceView extends React.Component<DataSourceViewProps, DataSou

render() {
if (this.state.showEmptyState) {
return <NoDataSource />;
return (
<NoDataSource
totalDataSourceCount={this.state.selectedOption.length}
application={this.props.application}
/>
);
}
if (this.state.showError) {
return <DataSourceErrorMenu />;
Expand Down
Loading

0 comments on commit 63c9581

Please sign in to comment.