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

fix(dashboard): Empty states overflowing small chart containers #19095

Merged
merged 2 commits into from
Mar 10, 2022
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
6 changes: 5 additions & 1 deletion superset-frontend/src/components/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ class Chart extends React.PureComponent {
className={`slice_container ${isFaded ? ' faded' : ''}`}
data-test="slice-container"
>
<ChartRenderer {...this.props} data-test={this.props.vizType} />
<ChartRenderer
{...this.props}
source={this.props.dashboardId ? 'dashboard' : 'explore'}
data-test={this.props.vizType}
/>
</div>

{!isLoading && !chartAlert && isFaded && (
Expand Down
39 changes: 29 additions & 10 deletions superset-frontend/src/components/Chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { SuperChart, logging, Behavior, t } from '@superset-ui/core';
import { Logger, LOG_ACTIONS_RENDER_CHART } from 'src/logger/LogUtils';
import { EmptyStateBig } from 'src/components/EmptyState';
import { EmptyStateBig, EmptyStateSmall } from 'src/components/EmptyState';

const propTypes = {
annotationData: PropTypes.object,
Expand All @@ -48,10 +48,14 @@ const propTypes = {
onFilterMenuOpen: PropTypes.func,
onFilterMenuClose: PropTypes.func,
ownState: PropTypes.object,
source: PropTypes.oneOf(['dashboard', 'explore']),
};

const BLANK = {};

const BIG_NO_RESULT_MIN_WIDTH = 300;
const BIG_NO_RESULT_MIN_HEIGHT = 220;

const defaultProps = {
addFilter: () => BLANK,
onFilterMenuOpen: () => BLANK,
Expand Down Expand Up @@ -212,6 +216,29 @@ class ChartRenderer extends React.Component {
}`
: '';

let noResultsComponent;
const noResultTitle = t('No results were returned for this query');
const noResultDescription =
this.props.source === 'explore'
? t(
'Make sure that the controls are configured properly and the datasource contains data for the selected time range',
)
: undefined;
const noResultImage = 'chart.svg';
if (width > BIG_NO_RESULT_MIN_WIDTH && height > BIG_NO_RESULT_MIN_HEIGHT) {
noResultsComponent = (
<EmptyStateBig
title={noResultTitle}
description={noResultDescription}
image={noResultImage}
/>
);
} else {
noResultsComponent = (
<EmptyStateSmall title={noResultTitle} image={noResultImage} />
);
}

return (
<SuperChart
disableErrorBoundary
Expand All @@ -232,15 +259,7 @@ class ChartRenderer extends React.Component {
queriesData={queriesResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
noResults={
<EmptyStateBig
title={t('No results were returned for this query')}
description={t(
'Make sure that the controls are configured properly and the datasource contains data for the selected time range',
)}
image="chart.svg"
/>
}
noResults={noResultsComponent}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ describe('ChartHolder', () => {
screen.getByText('No results were returned for this query'),
).toBeVisible();
expect(
screen.getByText(
screen.queryByText(
'Make sure that the controls are configured properly and the datasource contains data for the selected time range',
),
).toBeVisible();
).not.toBeInTheDocument(); // description should display only in Explore view
expect(screen.getByAltText('empty')).toBeVisible();
});
});