Skip to content

Commit 9854628

Browse files
committed
feat: add warning comment to button blocks
1 parent b04f5f2 commit 9854628

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

src/notebooks/deepnote/converters/inputConverters.unit.test.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ suite('ButtonBlockConverter', () => {
923923
});
924924

925925
suite('convertToCell', () => {
926-
test('converts button block with set_variable behavior', () => {
926+
test('converts button block to Python cell with comment', () => {
927927
const block: DeepnoteBlock = {
928928
blockGroup: '22e563550e734e75b35252e4975c3110',
929929
content: '',
@@ -941,15 +941,11 @@ suite('ButtonBlockConverter', () => {
941941
const cell = converter.convertToCell(block);
942942

943943
assert.strictEqual(cell.kind, NotebookCellKind.Code);
944-
assert.strictEqual(cell.languageId, 'json');
945-
946-
const parsed = JSON.parse(cell.value);
947-
assert.strictEqual(parsed.deepnote_button_title, 'Run');
948-
assert.strictEqual(parsed.deepnote_button_behavior, 'set_variable');
949-
assert.strictEqual(parsed.deepnote_button_color_scheme, 'blue');
944+
assert.strictEqual(cell.languageId, 'python');
945+
assert.strictEqual(cell.value, '# Buttons only work in Deepnote apps');
950946
});
951947

952-
test('converts button block with run behavior', () => {
948+
test('converts button block with run behavior to Python cell with comment', () => {
953949
const block: DeepnoteBlock = {
954950
blockGroup: '2a1e97120eb24494adff278264625a4f',
955951
content: '',
@@ -966,9 +962,9 @@ suite('ButtonBlockConverter', () => {
966962

967963
const cell = converter.convertToCell(block);
968964

969-
const parsed = JSON.parse(cell.value);
970-
assert.strictEqual(parsed.deepnote_button_title, 'Run notebook button');
971-
assert.strictEqual(parsed.deepnote_button_behavior, 'run');
965+
assert.strictEqual(cell.kind, NotebookCellKind.Code);
966+
assert.strictEqual(cell.languageId, 'python');
967+
assert.strictEqual(cell.value, '# Buttons only work in Deepnote apps');
972968
});
973969

974970
test('handles missing metadata with default config', () => {
@@ -982,27 +978,27 @@ suite('ButtonBlockConverter', () => {
982978

983979
const cell = converter.convertToCell(block);
984980

985-
const parsed = JSON.parse(cell.value);
986-
assert.strictEqual(parsed.deepnote_button_title, 'Run');
987-
assert.strictEqual(parsed.deepnote_button_behavior, 'set_variable');
981+
assert.strictEqual(cell.kind, NotebookCellKind.Code);
982+
assert.strictEqual(cell.languageId, 'python');
983+
assert.strictEqual(cell.value, '# Buttons only work in Deepnote apps');
988984
});
989985
});
990986

991987
suite('applyChangesToBlock', () => {
992-
test('applies valid JSON with button configuration', () => {
988+
test('preserves existing metadata and ignores cell content', () => {
993989
const block: DeepnoteBlock = {
994990
blockGroup: 'test-group',
995991
content: '',
996992
id: 'block-123',
993+
metadata: {
994+
deepnote_button_title: 'Click Me',
995+
deepnote_button_behavior: 'run',
996+
deepnote_button_color_scheme: 'red'
997+
},
997998
sortingKey: 'a0',
998999
type: 'button'
9991000
};
1000-
const cellValue = JSON.stringify({
1001-
deepnote_button_title: 'Click Me',
1002-
deepnote_button_behavior: 'run',
1003-
deepnote_button_color_scheme: 'red'
1004-
});
1005-
const cell = new NotebookCellData(NotebookCellKind.Code, cellValue, 'json');
1001+
const cell = new NotebookCellData(NotebookCellKind.Code, '# Buttons only work in Deepnote apps', 'python');
10061002

10071003
converter.applyChangesToBlock(block, cell);
10081004

@@ -1012,38 +1008,41 @@ suite('ButtonBlockConverter', () => {
10121008
assert.strictEqual(block.metadata?.deepnote_button_color_scheme, 'red');
10131009
});
10141010

1015-
test('applies different color schemes', () => {
1011+
test('applies default config when metadata is missing', () => {
10161012
const block: DeepnoteBlock = {
10171013
blockGroup: 'test-group',
10181014
content: '',
10191015
id: 'block-123',
10201016
sortingKey: 'a0',
10211017
type: 'button'
10221018
};
1023-
const cellValue = JSON.stringify({
1024-
deepnote_button_color_scheme: 'green'
1025-
});
1026-
const cell = new NotebookCellData(NotebookCellKind.Code, cellValue, 'json');
1019+
const cell = new NotebookCellData(NotebookCellKind.Code, '# Buttons only work in Deepnote apps', 'python');
10271020

10281021
converter.applyChangesToBlock(block, cell);
10291022

1030-
assert.strictEqual(block.metadata?.deepnote_button_color_scheme, 'green');
1023+
assert.strictEqual(block.content, '');
1024+
assert.strictEqual(block.metadata?.deepnote_button_title, 'Run');
1025+
assert.strictEqual(block.metadata?.deepnote_button_behavior, 'set_variable');
1026+
assert.strictEqual(block.metadata?.deepnote_button_color_scheme, 'blue');
10311027
});
10321028

1033-
test('handles invalid JSON', () => {
1029+
test('removes raw content key from metadata', () => {
10341030
const block: DeepnoteBlock = {
10351031
blockGroup: 'test-group',
10361032
content: '',
10371033
id: 'block-123',
1034+
metadata: {
1035+
[DEEPNOTE_VSCODE_RAW_CONTENT_KEY]: 'some raw content',
1036+
deepnote_button_title: 'Test'
1037+
},
10381038
sortingKey: 'a0',
10391039
type: 'button'
10401040
};
1041-
const invalidJson = '}{';
1042-
const cell = new NotebookCellData(NotebookCellKind.Code, invalidJson, 'json');
1041+
const cell = new NotebookCellData(NotebookCellKind.Code, '# Buttons only work in Deepnote apps', 'python');
10431042

10441043
converter.applyChangesToBlock(block, cell);
10451044

1046-
assert.strictEqual(block.metadata?.[DEEPNOTE_VSCODE_RAW_CONTENT_KEY], invalidJson);
1045+
assert.strictEqual(block.metadata?.[DEEPNOTE_VSCODE_RAW_CONTENT_KEY], undefined);
10471046
});
10481047
});
10491048
});

src/notebooks/deepnote/inputBlockContentFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function formatInputBlockCellContent(blockType: string, metadata: Record<
8282
}
8383

8484
case 'button': {
85-
return '';
85+
return '# Buttons only work in Deepnote apps';
8686
}
8787

8888
default:

0 commit comments

Comments
 (0)