Skip to content

Commit 95fd687

Browse files
committed
feat(big-number): Integrate react-error-boundary for error handling and enhance big number output rendering
1 parent 6ee3612 commit 95fd687

File tree

11 files changed

+115
-39
lines changed

11 files changed

+115
-39
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = {
7474
'import/no-unresolved': [
7575
'error',
7676
{
77-
ignore: ['monaco-editor', 'vscode']
77+
ignore: ['monaco-editor', 'vscode', 'error-boundary']
7878
}
7979
],
8080
'import/prefer-default-export': 'off',

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,7 @@
22042204
"react": "^16.5.2",
22052205
"react-data-grid": "^6.0.2-0",
22062206
"react-dom": "^16.5.2",
2207+
"react-error-boundary": "^6.0.0",
22072208
"react-redux": "^7.1.1",
22082209
"react-svg-pan-zoom": "3.9.0",
22092210
"react-svgmt": "1.1.11",

src/kernels/execution/cellExecutionMessageHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,8 @@ export class CellExecutionMessageHandler implements IDisposable {
11841184
);
11851185

11861186
const data = msg.content.data;
1187+
// deepnote-toolkit returns the text/plain mime type for big number outputs
1188+
// and for the custom renderer to be used, we need to return the application/vnd.deepnote.chart.big-number+json mime type
11871189
if (outputToBeUpdated.cell.metadata['__deepnotePocket']?.['type'] === 'big-number') {
11881190
data[CHART_BIG_NUMBER_MIME_TYPE] = data['text/plain'];
11891191
delete data['text/plain'];

src/kernels/execution/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ function translateDisplayDataOutput(
262262
}
263263
}
264264
*/
265-
// TODO - add DeepnotePocket zod schema validation
266265
const deepnotePocket = cellMetadata?.__deepnotePocket as Pocket | undefined;
267266
const deepnoteBlockType = deepnotePocket?.type;
268267

src/notebooks/deepnote/deepnoteDataConverter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,10 @@ export class DeepnoteDataConverter {
358358
);
359359
}
360360

361-
// Plain text as fallback (always last)
362361
if (data['text/plain']) {
363362
let mimeType = 'text/plain';
363+
// deepnote-toolkit returns the text/plain mime type for big number outputs
364+
// and for the custom renderer to be used, we need to return the application/vnd.deepnote.chart.big-number+json mime type
364365
if (blockType === 'big-number' && !(CHART_BIG_NUMBER_MIME_TYPE in data)) {
365366
mimeType = CHART_BIG_NUMBER_MIME_TYPE;
366367
}

src/notebooks/deepnote/deepnoteSchemas.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ export const DeepnoteBigNumberMetadataSchema = z.object({
1212
deepnote_big_number_title: z
1313
.string()
1414
.nullish()
15-
.transform((val) => val ?? null),
15+
.transform((val) => val ?? ''),
1616
deepnote_big_number_value: z
1717
.string()
1818
.nullish()
19-
.transform((val) => val ?? null),
19+
.transform((val) => val ?? ''),
2020
deepnote_big_number_format: z
2121
.string()
2222
.nullish()
23-
.transform((val) => val ?? null),
23+
.transform((val) => val ?? 'number'),
2424
deepnote_big_number_comparison_type: z
2525
.string()
2626
.nullish()
27-
.transform((val) => val ?? null),
27+
.transform((val) => val ?? ''),
2828
deepnote_big_number_comparison_title: z
2929
.string()
3030
.nullish()
31-
.transform((val) => val ?? null),
31+
.transform((val) => val ?? ''),
3232
deepnote_big_number_comparison_value: z
3333
.string()
3434
.nullish()
35-
.transform((val) => val ?? null),
35+
.transform((val) => val ?? ''),
3636
deepnote_big_number_comparison_format: z
3737
.string()
3838
.nullish()
39-
.transform((val) => val ?? null),
39+
.transform((val) => val ?? ''),
4040
deepnote_big_number_comparison_enabled: z
4141
.boolean()
4242
.nullish()
43-
.transform((val) => val ?? null)
43+
.transform((val) => val ?? false)
4444
});
4545

4646
export type DeepnoteChartBigNumberOutput = z.infer<typeof DeepnoteChartBigNumberOutputSchema>;

src/webviews/webview-side/chart-big-number-renderer/ChartBigNumberOutputRenderer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function ChartBigNumberOutputRenderer({
99
output: DeepnoteChartBigNumberOutput;
1010
metadata: DeepnoteBigNumberMetadata;
1111
}) {
12-
// TODO: either remove or handle here .. currently handled in the parent
1312
const title = useMemo(() => {
1413
return output.title || 'Title';
1514
}, [output.title]);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
3+
import {
4+
DeepnoteBigNumberMetadataSchema,
5+
DeepnoteChartBigNumberOutputSchema
6+
} from '../../../notebooks/deepnote/deepnoteSchemas';
7+
import { ChartBigNumberOutputRenderer } from './ChartBigNumberOutputRenderer';
8+
9+
export function ChartBigNumberOutputRendererContainer({
10+
outputText,
11+
outputMetadata
12+
}: {
13+
outputText: string;
14+
outputMetadata: unknown;
15+
}) {
16+
// Remove single quotes from start and end of string if present
17+
const data = JSON.parse(outputText.replace(/^'|'$/g, ''));
18+
const blockMetadata = DeepnoteBigNumberMetadataSchema.parse(outputMetadata);
19+
20+
const chartBigNumberOutput = DeepnoteChartBigNumberOutputSchema.parse(data);
21+
22+
return <ChartBigNumberOutputRenderer output={chartBigNumberOutput} metadata={blockMetadata} />;
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import type { FallbackProps } from 'react-error-boundary';
3+
4+
export function ErrorFallback({ error }: FallbackProps) {
5+
return (
6+
<div
7+
style={{
8+
padding: '16px',
9+
color: 'var(--vscode-errorForeground)',
10+
backgroundColor: 'var(--vscode-inputValidation-errorBackground)',
11+
border: '1px solid var(--vscode-inputValidation-errorBorder)',
12+
borderRadius: '4px',
13+
fontFamily: 'var(--vscode-font-family)',
14+
fontSize: '13px'
15+
}}
16+
>
17+
<div style={{ fontWeight: 'bold', marginBottom: '8px' }}>Error rendering big number</div>
18+
<div style={{ marginBottom: '8px' }}>{error.message}</div>
19+
<details style={{ marginTop: '8px', cursor: 'pointer' }}>
20+
<summary>Stack trace</summary>
21+
<pre
22+
style={{
23+
marginTop: '8px',
24+
padding: '8px',
25+
backgroundColor: 'var(--vscode-editor-background)',
26+
overflow: 'auto',
27+
fontSize: '11px',
28+
whiteSpace: 'pre-wrap',
29+
wordBreak: 'break-word'
30+
}}
31+
>
32+
{error.stack}
33+
</pre>
34+
</details>
35+
</div>
36+
);
37+
}

0 commit comments

Comments
 (0)