Skip to content

Commit 3f44449

Browse files
authored
refactor: Group Add input block buttons in toolbar (#287)
* feat: Add commands to add Text blocks to notebooks * Minor changes * refactor: Group Add input block buttons in toolbar * Fix typo * Minor changes * Change picker items labels * refactor: Replace InputBlockType definition with a constant array and add description to input block picker items * feat: Enhance input block picker with description and detail matching
1 parent 44483f7 commit 3f44449

4 files changed

Lines changed: 71 additions & 42 deletions

File tree

package.json

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
"category": "Deepnote",
231231
"icon": "$(add)"
232232
},
233+
{
234+
"command": "deepnote.addInputBlock",
235+
"title": "%deepnote.commands.addInputBlock.title%",
236+
"category": "Deepnote",
237+
"icon": "$(symbol-parameter)"
238+
},
233239
{
234240
"command": "deepnote.addTextBlock",
235241
"title": "%deepnote.commands.addTextBlock.title%",
@@ -1022,43 +1028,13 @@
10221028
"when": "notebookType == 'deepnote'"
10231029
},
10241030
{
1025-
"command": "deepnote.addInputTextBlock",
1031+
"command": "deepnote.addInputBlock",
10261032
"group": "navigation@6",
10271033
"when": "notebookType == 'deepnote'"
10281034
},
1029-
{
1030-
"command": "deepnote.addInputTextareaBlock",
1031-
"group": "navigation@7",
1032-
"when": "notebookType == 'deepnote'"
1033-
},
1034-
{
1035-
"command": "deepnote.addInputSelectBlock",
1036-
"group": "navigation@8",
1037-
"when": "notebookType == 'deepnote'"
1038-
},
1039-
{
1040-
"command": "deepnote.addInputSliderBlock",
1041-
"group": "navigation@9",
1042-
"when": "notebookType == 'deepnote'"
1043-
},
1044-
{
1045-
"command": "deepnote.addInputCheckboxBlock",
1046-
"group": "navigation@10",
1047-
"when": "notebookType == 'deepnote'"
1048-
},
1049-
{
1050-
"command": "deepnote.addInputDateBlock",
1051-
"group": "navigation@11",
1052-
"when": "notebookType == 'deepnote'"
1053-
},
1054-
{
1055-
"command": "deepnote.addInputDateRangeBlock",
1056-
"group": "navigation@12",
1057-
"when": "notebookType == 'deepnote'"
1058-
},
10591035
{
10601036
"command": "deepnote.addTextBlock",
1061-
"group": "navigation@13",
1037+
"group": "navigation@7",
10621038
"when": "notebookType == 'deepnote'"
10631039
},
10641040
{

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
"deepnote.commands.addInputDateRangeBlock.title": "Add Input Date Range Block",
267267
"deepnote.commands.addInputFileBlock.title": "Add Input File Block",
268268
"deepnote.commands.addButtonBlock.title": "Add Button Block",
269+
"deepnote.commands.addInputBlock.title": "Add Input Block",
269270
"deepnote.commands.addTextBlock.title": "Add Text Block",
270271
"deepnote.commands.addTextBlockParagraph.title": "Add Paragraph Block",
271272
"deepnote.commands.addTextBlockHeading1.title": "Add Heading 1 Block",

src/notebooks/deepnote/deepnoteNotebookCommandListener.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ import {
3737
import { DATAFRAME_SQL_INTEGRATION_ID } from '../../platform/notebooks/deepnote/integrationTypes';
3838
import { Pocket } from '../../platform/deepnote/pocket';
3939

40-
export type InputBlockType =
41-
| 'input-text'
42-
| 'input-textarea'
43-
| 'input-select'
44-
| 'input-slider'
45-
| 'input-checkbox'
46-
| 'input-date'
47-
| 'input-date-range'
48-
| 'input-file'
49-
| 'button';
40+
export const INPUT_BLOCK_TYPES = [
41+
'input-text',
42+
'input-textarea',
43+
'input-select',
44+
'input-slider',
45+
'input-checkbox',
46+
'input-date',
47+
'input-date-range',
48+
'input-file',
49+
'button'
50+
] as const;
51+
52+
export type InputBlockType = (typeof INPUT_BLOCK_TYPES)[number];
5053

5154
export const TEXT_BLOCK_TYPES = ['text-cell-p', 'text-cell-h1', 'text-cell-h2', 'text-cell-h3'] as const;
5255

@@ -188,6 +191,9 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
188191
this.disposableRegistry.push(
189192
commands.registerCommand(Commands.AddButtonBlock, () => this.addInputBlock('button'))
190193
);
194+
this.disposableRegistry.push(
195+
commands.registerCommand(Commands.AddInputBlock, () => this.addInputBlockThroughPicker())
196+
);
191197
this.disposableRegistry.push(
192198
commands.registerCommand(Commands.AddTextBlock, () => this.addTextBlockThroughPicker())
193199
);
@@ -437,6 +443,51 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
437443
await this.addTextBlock({ editor, textBlockType: selected.textBlockType });
438444
}
439445

446+
public async addInputBlockThroughPicker(): Promise<void> {
447+
const INPUT_BLOCK_TYPE_LABELS = {
448+
'input-text': l10n.t('Text Input'),
449+
'input-textarea': l10n.t('Textarea'),
450+
'input-select': l10n.t('Select Dropdown'),
451+
'input-slider': l10n.t('Slider'),
452+
'input-checkbox': l10n.t('Checkbox'),
453+
'input-date': l10n.t('Date'),
454+
'input-date-range': l10n.t('Date Range'),
455+
'input-file': l10n.t('File Upload'),
456+
button: l10n.t('Button')
457+
} as const satisfies Record<InputBlockType, string>;
458+
459+
const editor = window.activeNotebookEditor;
460+
if (!editor) {
461+
throw new Error(l10n.t('No active notebook editor found'));
462+
}
463+
464+
const items: (QuickPickItem & { inputBlockType: InputBlockType })[] = INPUT_BLOCK_TYPES.map(
465+
(inputBlockType) => {
466+
const label = INPUT_BLOCK_TYPE_LABELS[inputBlockType];
467+
const description = l10n.t('Add a {0} block', label);
468+
return {
469+
label,
470+
description,
471+
inputBlockType
472+
};
473+
}
474+
);
475+
476+
const selected = await window.showQuickPick(items, {
477+
placeHolder: l10n.t('Select an input block type'),
478+
matchOnDescription: true,
479+
matchOnDetail: true
480+
});
481+
482+
if (selected == null) {
483+
return;
484+
}
485+
486+
logger.info(`Selected input block type: ${selected.inputBlockType}`);
487+
488+
await this.addInputBlock(selected.inputBlockType);
489+
}
490+
440491
public async addTextBlockCommandHandler({ textBlockType }: { textBlockType: TextBlockType }): Promise<void> {
441492
const editor = window.activeNotebookEditor;
442493
if (!editor) {

src/platform/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export namespace Commands {
236236
export const AddInputDateRangeBlock = 'deepnote.addInputDateRangeBlock';
237237
export const AddInputFileBlock = 'deepnote.addInputFileBlock';
238238
export const AddButtonBlock = 'deepnote.addButtonBlock';
239+
export const AddInputBlock = 'deepnote.addInputBlock';
239240
export const AddTextBlock = 'deepnote.addTextBlock';
240241
export const AddTextBlockParagraph = 'deepnote.addTextBlockParagraph';
241242
export const AddTextBlockHeading1 = 'deepnote.addTextBlockHeading1';

0 commit comments

Comments
 (0)