Skip to content

Commit 62297c2

Browse files
committed
refactor: Clean up debug logs and improve big number block conversion handling
1 parent 87f4a09 commit 62297c2

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

src/notebooks/deepnote/converters/chartBigNumberBlockConverter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { parseJsonWithFallback } from '../dataConversionUtils';
77
import { z } from 'zod';
88

99
export const DEEPNOTE_VSCODE_RAW_CONTENT_KEY = 'deepnote_jupyter_raw_content';
10+
const DEFAULT_BIG_NUMBER_CONFIG = DeepnoteBigNumberMetadataSchema.parse({});
1011

1112
export class ChartBigNumberBlockConverter implements BlockConverter {
1213
applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void {
@@ -37,8 +38,6 @@ export class ChartBigNumberBlockConverter implements BlockConverter {
3738
}
3839

3940
convertToCell(block: DeepnoteBlock): NotebookCellData {
40-
console.log('Converting big number block to cell:', block);
41-
4241
const deepnoteJupyterRawContentResult = z.string().safeParse(block.metadata?.[DEEPNOTE_VSCODE_RAW_CONTENT_KEY]);
4342
const deepnoteBigNumberMetadataResult = DeepnoteBigNumberMetadataSchema.safeParse(block.metadata);
4443

@@ -51,7 +50,7 @@ export class ChartBigNumberBlockConverter implements BlockConverter {
5150
? deepnoteJupyterRawContentResult.data
5251
: deepnoteBigNumberMetadataResult.success
5352
? JSON.stringify(deepnoteBigNumberMetadataResult.data, null, 2)
54-
: JSON.stringify(DeepnoteBigNumberMetadataSchema.parse({}), null, 2);
53+
: JSON.stringify(DEFAULT_BIG_NUMBER_CONFIG);
5554

5655
const cell = new NotebookCellData(NotebookCellKind.Code, configStr, 'json');
5756
console.log(cell);

src/notebooks/deepnote/deepnoteSerializer.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ export class DeepnoteNotebookSerializer implements NotebookSerializer {
6464

6565
const cells = this.converter.convertBlocksToCells(selectedNotebook.blocks);
6666

67-
// for (const cell of cells) {
68-
// console.log(cell.kind, cell.languageId, cell);
69-
// for (const output of cell.outputs ?? []) {
70-
// for (const item of output.items) {
71-
// console.log(' ', item.mime, decodeContent(item.data));
72-
// }
73-
// }
74-
// }
75-
7667
console.log(`Converted ${cells.length} cells from notebook blocks.`);
7768

7869
this.notebookManager.storeOriginalProject(deepnoteProject.project.id, deepnoteProject, selectedNotebook.id);

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function ChartBigNumberOutputRenderer({
99
output: DeepnoteChartBigNumberOutput;
1010
metadata: DeepnoteBigNumberMetadata;
1111
}) {
12+
// TODO: either remove or handle here .. currently handled in the parent
1213
const hasErrors = false;
1314

1415
const title = useMemo(() => {
@@ -62,6 +63,10 @@ export function ChartBigNumberOutputRenderer({
6263
}
6364

6465
if (metadata.deepnote_big_number_comparison_type === 'percentage-change') {
66+
if (parsedComparisonValue === 0) {
67+
return undefined;
68+
}
69+
6570
return (parsedValue - parsedComparisonValue) / parsedComparisonValue;
6671
}
6772

@@ -77,7 +82,7 @@ export function ChartBigNumberOutputRenderer({
7782
return '-';
7883
}
7984

80-
if (!comparisonValue) {
85+
if (comparisonValue == null) {
8186
return '-';
8287
}
8388

@@ -91,7 +96,7 @@ export function ChartBigNumberOutputRenderer({
9196
}, [comparisonValue, metadata.deepnote_big_number_format, hasErrors, metadata.deepnote_big_number_comparison_type]);
9297

9398
const changeDirection = useMemo(() => {
94-
if (!comparisonValue) {
99+
if (comparisonValue == null) {
95100
return 1;
96101
}
97102

@@ -130,12 +135,9 @@ export function ChartBigNumberOutputRenderer({
130135
</p>
131136
</div>
132137
{output.comparisonTitle != null ? (
133-
<>
134-
{' '}
135-
<div>
136-
<p className="deepnote-comparison-title">{output.comparisonTitle}</p>
137-
</div>
138-
</>
138+
<div>
139+
<p className="deepnote-comparison-title">{output.comparisonTitle}</p>
140+
</div>
139141
) : null}
140142
</div>
141143
</div>

src/webviews/webview-side/chart-big-number-renderer/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ export const activate: ActivationFunction = (_context: RendererContext<unknown>)
1515
return {
1616
renderOutputItem(outputItem: OutputItem, element: HTMLElement) {
1717
try {
18-
// .slice(1, -1) is to remove the quotes from the json string
19-
const data = JSON.parse(outputItem.text().slice(1, -1));
18+
// Remove single quotes from start and end of string if present
19+
const data = JSON.parse(outputItem.text().replace(/^'|'$/g, ''));
2020
const metadata = DeepnoteBigNumberMetadataSchema.parse(outputItem.metadata);
21-
console.log('Chart Big Number renderer - received data:', data);
2221

2322
const chartBigNumberOutput = DeepnoteChartBigNumberOutputSchema.parse(data);
24-
console.log('bigNumberConfig', chartBigNumberOutput);
2523

2624
const root = document.createElement('div');
2725
element.appendChild(root);

0 commit comments

Comments
 (0)