Skip to content

Commit 4c1c4e2

Browse files
committed
Merge remote-tracking branch 'origin/tomaskislan/grn-4762-support-big-number-blocks' into tomaskislan/grn-4776-support-input-blocks
2 parents f2c01ee + 05ab7a0 commit 4c1c4e2

File tree

12 files changed

+138
-62
lines changed

12 files changed

+138
-62
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/converters/chartBigNumberBlockConverter.unit.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ suite('ChartBigNumberBlockConverter', () => {
268268

269269
const config = JSON.parse(cell.value);
270270
assert.deepStrictEqual(config, {
271-
deepnote_big_number_title: null,
272-
deepnote_big_number_value: null,
273-
deepnote_big_number_format: null,
274-
deepnote_big_number_comparison_type: null,
275-
deepnote_big_number_comparison_title: null,
276-
deepnote_big_number_comparison_value: null,
277-
deepnote_big_number_comparison_format: null,
278-
deepnote_big_number_comparison_enabled: null
271+
deepnote_big_number_title: '',
272+
deepnote_big_number_value: '',
273+
deepnote_big_number_format: 'number',
274+
deepnote_big_number_comparison_type: '',
275+
deepnote_big_number_comparison_title: '',
276+
deepnote_big_number_comparison_value: '',
277+
deepnote_big_number_comparison_format: '',
278+
deepnote_big_number_comparison_enabled: false
279279
});
280280
});
281281

@@ -296,14 +296,14 @@ suite('ChartBigNumberBlockConverter', () => {
296296

297297
const config = JSON.parse(cell.value);
298298
assert.deepStrictEqual(config, {
299-
deepnote_big_number_title: null,
300-
deepnote_big_number_value: null,
301-
deepnote_big_number_format: null,
302-
deepnote_big_number_comparison_type: null,
303-
deepnote_big_number_comparison_title: null,
304-
deepnote_big_number_comparison_value: null,
305-
deepnote_big_number_comparison_format: null,
306-
deepnote_big_number_comparison_enabled: null
299+
deepnote_big_number_title: '',
300+
deepnote_big_number_value: '',
301+
deepnote_big_number_format: 'number',
302+
deepnote_big_number_comparison_type: '',
303+
deepnote_big_number_comparison_title: '',
304+
deepnote_big_number_comparison_value: '',
305+
deepnote_big_number_comparison_format: '',
306+
deepnote_big_number_comparison_enabled: false
307307
});
308308
});
309309
});
@@ -445,13 +445,13 @@ suite('ChartBigNumberBlockConverter', () => {
445445
metadata: {
446446
custom: 'value',
447447
deepnote_big_number_title: 'new title',
448-
deepnote_big_number_comparison_enabled: null,
449-
deepnote_big_number_comparison_format: null,
450-
deepnote_big_number_comparison_title: null,
451-
deepnote_big_number_comparison_type: null,
452-
deepnote_big_number_comparison_value: null,
453-
deepnote_big_number_format: null,
454-
deepnote_big_number_value: null
448+
deepnote_big_number_comparison_enabled: false,
449+
deepnote_big_number_comparison_format: '',
450+
deepnote_big_number_comparison_title: '',
451+
deepnote_big_number_comparison_type: '',
452+
deepnote_big_number_comparison_value: '',
453+
deepnote_big_number_format: 'number',
454+
deepnote_big_number_value: ''
455455
},
456456
outputs: [],
457457
sortingKey: 'a0',

src/notebooks/deepnote/deepnoteDataConverter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,10 @@ export class DeepnoteDataConverter {
378378
);
379379
}
380380

381-
// Plain text as fallback (always last)
382381
if (data['text/plain']) {
383382
let mimeType = 'text/plain';
383+
// deepnote-toolkit returns the text/plain mime type for big number outputs
384+
// and for the custom renderer to be used, we need to return the application/vnd.deepnote.chart.big-number+json mime type
384385
if (blockType === 'big-number' && !(CHART_BIG_NUMBER_MIME_TYPE in data)) {
385386
mimeType = CHART_BIG_NUMBER_MIME_TYPE;
386387
}

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 const DeepnoteTextInputMetadataSchema = z.object({

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+
}

0 commit comments

Comments
 (0)