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: Improve conditional rendering in ChartWidget #36806

Merged
merged 10 commits into from
Oct 11, 2024
78 changes: 43 additions & 35 deletions app/client/src/widgets/ChartWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,43 +225,51 @@ class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {

getWidgetView() {
const errors = syntaxErrorsFromProps(this.props);
const isLoading = this.props.isLoading;
const hasErrors = errors.length > 0;
const isEmptyChart = emptyChartData(this.props);

if (errors.length == 0) {
if (emptyChartData(this.props)) {
return <EmptyChartData />;
} else {
return (
<Suspense fallback={<Skeleton />}>
<ChartComponent
allowScroll={this.props.allowScroll}
borderRadius={this.props.borderRadius}
boxShadow={this.props.boxShadow}
chartData={this.props.chartData}
chartName={this.props.chartName}
chartType={this.props.chartType}
customEChartConfig={this.props.customEChartConfig}
customFusionChartConfig={this.props.customFusionChartConfig}
dimensions={this.props}
fontFamily={ChartWidget.fontFamily}
hasOnDataPointClick={Boolean(this.props.onDataPointClick)}
isLoading={this.props.isLoading}
isVisible={this.props.isVisible}
key={this.props.widgetId}
labelOrientation={this.props.labelOrientation}
onDataPointClick={this.onDataPointClick}
primaryColor={this.props.accentColor ?? Colors.ROYAL_BLUE_2}
setAdaptiveYMin={this.props.setAdaptiveYMin}
showDataPointLabel={this.props.showDataPointLabel}
widgetId={this.props.widgetId}
xAxisName={this.props.xAxisName}
yAxisName={this.props.yAxisName}
/>
</Suspense>
);
}
} else {
return <ChartErrorComponent error={errors[0]} />;
if (isEmptyChart && !isLoading) {
return <EmptyChartData />;
}

if (isLoading || !hasErrors) {
return this.renderChartWithData();
}

// There are errors and chart is not loading
return <ChartErrorComponent error={errors[0]} />;
}
rahulbarwal marked this conversation as resolved.
Show resolved Hide resolved

renderChartWithData() {
return (
<Suspense fallback={<Skeleton />}>
<ChartComponent
allowScroll={this.props.allowScroll}
borderRadius={this.props.borderRadius}
boxShadow={this.props.boxShadow}
chartData={this.props.chartData}
chartName={this.props.chartName}
chartType={this.props.chartType}
customEChartConfig={this.props.customEChartConfig}
customFusionChartConfig={this.props.customFusionChartConfig}
dimensions={this.props}
fontFamily={ChartWidget.fontFamily}
hasOnDataPointClick={Boolean(this.props.onDataPointClick)}
isLoading={this.props.isLoading}
isVisible={this.props.isVisible}
key={this.props.widgetId}
labelOrientation={this.props.labelOrientation}
onDataPointClick={this.onDataPointClick}
rahulbarwal marked this conversation as resolved.
Show resolved Hide resolved
primaryColor={this.props.accentColor ?? Colors.ROYAL_BLUE_2}
setAdaptiveYMin={this.props.setAdaptiveYMin}
showDataPointLabel={this.props.showDataPointLabel}
widgetId={this.props.widgetId}
xAxisName={this.props.xAxisName}
yAxisName={this.props.yAxisName}
/>
</Suspense>
);
}
}

Expand Down
Loading