Skip to content

Commit

Permalink
fix(dashboard): Empty states overflowing small chart containers (#19095)
Browse files Browse the repository at this point in the history
* fix(dashboard): Empty states overflowing small chart containers

* Fix test
  • Loading branch information
kgabryje committed Mar 10, 2022
1 parent b8091e3 commit 70081a6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
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();
});
});

0 comments on commit 70081a6

Please sign in to comment.