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

feat: Add render blocking errors to Chart #2255

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 36 additions & 14 deletions packages/chart/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@
isDownsampleInProgress: boolean;
isDownsamplingDisabled: boolean;

/** Any other kind of error */
/** Any other kind of error that doesn't completely block the chart from rendering */
error: unknown;
shownError: string | null;
layout: Partial<Layout>;
revision: number;

/** A message that blocks the chart from rendering */
shownBlocker: string | null;
jnumainville marked this conversation as resolved.
Show resolved Hide resolved
}

class Chart extends Component<ChartProps, ChartState> {
Expand Down Expand Up @@ -180,6 +183,7 @@
datarevision: 0,
},
revision: 0,
shownBlocker: null,
};
}

Expand Down Expand Up @@ -512,6 +516,15 @@
onError(new Error(error));
break;
}
case ChartModel.EVENT_BLOCKER: {
const blocker = `${detail}`;
this.setState({ shownBlocker: blocker });
break;
}
case ChartModel.EVENT_BLOCKER_CLEAR: {
this.setState({ shownBlocker: null });
break;
}
default:
log.debug('Unknown event type', type, event);
}
Expand Down Expand Up @@ -705,6 +718,7 @@
shownError,
layout,
revision,
shownBlocker,
} = this.state;
const config = this.getCachedConfig(
downsamplingError,
Expand All @@ -714,7 +728,7 @@
data ?? [],
error
);
const isPlotShown = data != null;
const isPlotShown = data != null && shownBlocker == null;

return (
<div className="h-100 w-100 chart-wrapper" ref={this.plotWrapperMerged}>
Expand All @@ -735,24 +749,32 @@
style={{ height: '100%', width: '100%' }}
/>
)}
{downsamplingError != null && shownError == null && (
{downsamplingError != null &&
shownError == null &&
shownBlocker == null && (
<ChartErrorOverlay
errorMessage={`${downsamplingError}`}
onDiscard={() => {
this.handleDownsampleErrorClose();
}}
onConfirm={() => {
this.handleDownsampleErrorClose();
this.handleDownsampleClick();
}}
/>
)}
jnumainville marked this conversation as resolved.
Show resolved Hide resolved
{shownError != null && shownBlocker == null && (
<ChartErrorOverlay
errorMessage={`${downsamplingError}`}
errorMessage={`${shownError}`}
onDiscard={() => {
this.handleDownsampleErrorClose();
}}
onConfirm={() => {
this.handleDownsampleErrorClose();
this.handleDownsampleClick();
this.handleErrorClose();
}}
/>
)}
{shownError != null && (
{shownBlocker != null && (
<ChartErrorOverlay
errorMessage={`${shownError}`}
onDiscard={() => {
this.handleErrorClose();
}}
errorMessage={`${shownBlocker}`}
onConfirm={this.props.model.fireBlockerClear}

Check failure on line 777 in packages/chart/src/Chart.tsx

View workflow job for this annotation

GitHub Actions / unit

Must use destructuring props assignment
jnumainville marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
</div>
Expand Down
12 changes: 12 additions & 0 deletions packages/chart/src/ChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ChartModel {

static EVENT_ERROR = 'ChartModel.EVENT_ERROR';

static EVENT_BLOCKER = 'ChartModel.EVENT_BLOCKER';

static EVENT_BLOCKER_CLEAR = 'ChartModel.EVENT_BLOCKER_CLEAR';

constructor(dh: typeof DhType) {
this.dh = dh;
this.listeners = [];
Expand Down Expand Up @@ -184,6 +188,14 @@ class ChartModel {
fireError(detail: string[]): void {
this.fireEvent(new CustomEvent(ChartModel.EVENT_ERROR, { detail }));
}

fireBlocker(detail: string[]): void {
this.fireEvent(new CustomEvent(ChartModel.EVENT_BLOCKER, { detail }));
}

fireBlockerClear(): void {
this.fireEvent(new CustomEvent(ChartModel.EVENT_BLOCKER_CLEAR));
}
jnumainville marked this conversation as resolved.
Show resolved Hide resolved
}

export default ChartModel;
Loading