Skip to content

Commit

Permalink
feat: show more information when loading chart (apache#27255)
Browse files Browse the repository at this point in the history
(cherry picked from commit fbc8943)
  • Loading branch information
betodealmeida authored and sadpandajoe committed Apr 1, 2024
1 parent 168e6d4 commit 7b663bf
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions superset-frontend/src/components/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ const Styles = styled.div`
}
`;

const LoadingDiv = styled.div`
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
`;

const MessageSpan = styled.span`
display: block;
margin: ${({ theme }) => theme.gridUnit * 4}px auto;
width: fit-content;
color: ${({ theme }) => theme.colors.grayscale.base};
`;

const MonospaceDiv = styled.div`
font-family: ${({ theme }) => theme.typography.families.monospace};
word-break: break-word;
Expand Down Expand Up @@ -232,16 +246,49 @@ class Chart extends React.PureComponent {
);
}

renderSpinner(databaseName) {
const message = databaseName
? t('Waiting on %s', databaseName)
: t('Waiting on database...');

return (
<LoadingDiv>
<Loading position="inline-centered" />
<MessageSpan>{message}</MessageSpan>
</LoadingDiv>
);
}

renderChartContainer() {
return (
<div className="slice_container" data-test="slice-container">
{this.props.isInView ||
!isFeatureEnabled(FeatureFlag.DashboardVirtualization) ||
isCurrentUserBot() ? (
<ChartRenderer
{...this.props}
source={this.props.dashboardId ? 'dashboard' : 'explore'}
data-test={this.props.vizType}
/>
) : (
<Loading />
)}
</div>
);
}

render() {
const {
height,
chartAlert,
chartStatus,
datasource,
errorMessage,
chartIsStale,
queriesResponse = [],
width,
} = this.props;
const databaseName = datasource?.database?.name;

const isLoading = chartStatus === 'loading';
this.renderContainerStartTime = Logger.getTimestamp();
Expand Down Expand Up @@ -297,20 +344,9 @@ class Chart extends React.PureComponent {
height={height}
width={width}
>
<div className="slice_container" data-test="slice-container">
{this.props.isInView ||
!isFeatureEnabled(FeatureFlag.DashboardVirtualization) ||
isCurrentUserBot() ? (
<ChartRenderer
{...this.props}
source={this.props.dashboardId ? 'dashboard' : 'explore'}
data-test={this.props.vizType}
/>
) : (
<Loading />
)}
</div>
{isLoading && <Loading />}
{isLoading
? this.renderSpinner(databaseName)
: this.renderChartContainer()}
</Styles>
</ErrorBoundary>
);
Expand Down

0 comments on commit 7b663bf

Please sign in to comment.