Skip to content

Commit 605536b

Browse files
authored
Merge branch 'main' into ls/open-in-deepnote
2 parents 21bf3ce + c1b5526 commit 605536b

30 files changed

+1853
-208
lines changed

package-lock.json

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

package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
"category": "Deepnote",
136136
"icon": "$(graph)"
137137
},
138+
{
139+
"command": "deepnote.addChartBlock",
140+
"title": "%deepnote.commands.addChartBlock.title%",
141+
"category": "Deepnote",
142+
"icon": "$(graph-line)"
143+
},
138144
{
139145
"command": "deepnote.addInputTextBlock",
140146
"title": "%deepnote.commands.addInputTextBlock.title%",
@@ -861,6 +867,51 @@
861867
"group": "navigation@1",
862868
"when": "notebookType == 'deepnote'"
863869
},
870+
{
871+
"command": "deepnote.addChartBlock",
872+
"group": "navigation@2",
873+
"when": "notebookType == 'deepnote'"
874+
},
875+
{
876+
"command": "deepnote.addBigNumberChartBlock",
877+
"group": "navigation@3",
878+
"when": "notebookType == 'deepnote'"
879+
},
880+
{
881+
"command": "deepnote.addInputTextBlock",
882+
"group": "navigation@4",
883+
"when": "notebookType == 'deepnote'"
884+
},
885+
{
886+
"command": "deepnote.addInputTextareaBlock",
887+
"group": "navigation@5",
888+
"when": "notebookType == 'deepnote'"
889+
},
890+
{
891+
"command": "deepnote.addInputSelectBlock",
892+
"group": "navigation@6",
893+
"when": "notebookType == 'deepnote'"
894+
},
895+
{
896+
"command": "deepnote.addInputSliderBlock",
897+
"group": "navigation@7",
898+
"when": "notebookType == 'deepnote'"
899+
},
900+
{
901+
"command": "deepnote.addInputCheckboxBlock",
902+
"group": "navigation@8",
903+
"when": "notebookType == 'deepnote'"
904+
},
905+
{
906+
"command": "deepnote.addInputDateBlock",
907+
"group": "navigation@9",
908+
"when": "notebookType == 'deepnote'"
909+
},
910+
{
911+
"command": "deepnote.addInputDateRangeBlock",
912+
"group": "navigation@10",
913+
"when": "notebookType == 'deepnote'"
914+
},
864915
{
865916
"command": "jupyter.restartkernel",
866917
"group": "navigation/execute@5",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@
255255
"deepnote.commands.importNotebook.title": "Import Notebook",
256256
"deepnote.commands.importJupyterNotebook.title": "Import Jupyter Notebook",
257257
"deepnote.commands.addSqlBlock.title": "Add SQL Block",
258-
"deepnote.commands.addBigNumberChartBlock.title": "Add Big Number Chart Block",
258+
"deepnote.commands.addBigNumberChartBlock.title": "Add Big Number Block",
259+
"deepnote.commands.addChartBlock.title": "Add Chart Block",
259260
"deepnote.commands.addInputTextBlock.title": "Add Input Text Block",
260261
"deepnote.commands.addInputTextareaBlock.title": "Add Input Textarea Block",
261262
"deepnote.commands.addInputSelectBlock.title": "Add Input Select Block",

src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export interface ICommandNameArgumentTypeMapping {
188188
[DSCommands.ContinueEditSessionInCodespace]: [];
189189
[DSCommands.AddSqlBlock]: [];
190190
[DSCommands.AddBigNumberChartBlock]: [];
191+
[DSCommands.AddChartBlock]: [];
191192
[DSCommands.AddInputTextBlock]: [];
192193
[DSCommands.AddInputTextareaBlock]: [];
193194
[DSCommands.AddInputSelectBlock]: [];

src/messageTypes.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export type LocalizedMessages = {
182182
// Integration type labels
183183
integrationsPostgresTypeLabel: string;
184184
integrationsBigQueryTypeLabel: string;
185+
integrationsSnowflakeTypeLabel: string;
185186
// PostgreSQL form strings
186187
integrationsPostgresNameLabel: string;
187188
integrationsPostgresNamePlaceholder: string;
@@ -204,9 +205,36 @@ export type LocalizedMessages = {
204205
integrationsBigQueryCredentialsLabel: string;
205206
integrationsBigQueryCredentialsPlaceholder: string;
206207
integrationsBigQueryCredentialsRequired: string;
208+
// Snowflake form strings
209+
integrationsSnowflakeNameLabel: string;
210+
integrationsSnowflakeNamePlaceholder: string;
211+
integrationsSnowflakeAccountLabel: string;
212+
integrationsSnowflakeAccountPlaceholder: string;
213+
integrationsSnowflakeAuthMethodLabel: string;
214+
integrationsSnowflakeAuthMethodSubLabel: string;
215+
integrationsSnowflakeAuthMethodUsernamePassword: string;
216+
integrationsSnowflakeAuthMethodKeyPair: string;
217+
integrationsSnowflakeUnsupportedAuthMethod: string;
218+
integrationsSnowflakeUsernameLabel: string;
219+
integrationsSnowflakePasswordLabel: string;
220+
integrationsSnowflakePasswordPlaceholder: string;
221+
integrationsSnowflakeServiceAccountUsernameLabel: string;
222+
integrationsSnowflakeServiceAccountUsernameHelp: string;
223+
integrationsSnowflakePrivateKeyLabel: string;
224+
integrationsSnowflakePrivateKeyHelp: string;
225+
integrationsSnowflakePrivateKeyPlaceholder: string;
226+
integrationsSnowflakePrivateKeyPassphraseLabel: string;
227+
integrationsSnowflakePrivateKeyPassphraseHelp: string;
228+
integrationsSnowflakeDatabaseLabel: string;
229+
integrationsSnowflakeDatabasePlaceholder: string;
230+
integrationsSnowflakeRoleLabel: string;
231+
integrationsSnowflakeRolePlaceholder: string;
232+
integrationsSnowflakeWarehouseLabel: string;
233+
integrationsSnowflakeWarehousePlaceholder: string;
207234
// Common form strings
208235
integrationsRequiredField: string;
209236
integrationsOptionalField: string;
237+
integrationsUnnamedIntegration: string;
210238
};
211239
// Map all messages to specific payloads
212240
export class IInteractiveWindowMapping {

src/notebooks/deepnote/deepnoteNotebookCommandListener.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IExtensionSyncActivationService } from '../../platform/activation/types
1717
import { IDisposableRegistry } from '../../platform/common/types';
1818
import { Commands } from '../../platform/common/constants';
1919
import { chainWithPendingUpdates } from '../../kernels/execution/notebookUpdater';
20+
import { WrappedError } from '../../platform/errors/types';
2021
import {
2122
DeepnoteBigNumberMetadataSchema,
2223
DeepnoteTextInputMetadataSchema,
@@ -30,6 +31,7 @@ import {
3031
DeepnoteButtonMetadataSchema,
3132
DeepnoteSqlMetadata
3233
} from './deepnoteSchemas';
34+
import { DATAFRAME_SQL_INTEGRATION_ID } from '../../platform/notebooks/deepnote/integrationTypes';
3335

3436
export type InputBlockType =
3537
| 'input-text'
@@ -75,7 +77,10 @@ export function getInputBlockMetadata(blockType: InputBlockType, variableName: s
7577

7678
export function safeParseDeepnoteVariableNameFromContentJson(content: string): string | undefined {
7779
try {
78-
const variableNameResult = z.string().safeParse(JSON.parse(content)['deepnote_variable_name']);
80+
const parsed = JSON.parse(content);
81+
// Chart blocks use 'variable' key, other blocks use 'deepnote_variable_name'
82+
const variableName = parsed['variable'] ?? parsed['deepnote_variable_name'];
83+
const variableNameResult = z.string().safeParse(variableName);
7984
return variableNameResult.success ? variableNameResult.data : undefined;
8085
} catch (error) {
8186
logger.error('Error parsing deepnote variable name from content JSON', error);
@@ -147,6 +152,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
147152
this.disposableRegistry.push(
148153
commands.registerCommand(Commands.AddBigNumberChartBlock, () => this.addBigNumberChartBlock())
149154
);
155+
this.disposableRegistry.push(commands.registerCommand(Commands.AddChartBlock, () => this.addChartBlock()));
150156
this.disposableRegistry.push(
151157
commands.registerCommand(Commands.AddInputTextBlock, () => this.addInputBlock('input-text'))
152158
);
@@ -189,7 +195,7 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
189195
const defaultMetadata: DeepnoteSqlMetadata = {
190196
deepnote_variable_name: deepnoteVariableName,
191197
deepnote_return_variable_type: 'dataframe',
192-
sql_integration_id: 'deepnote-dataframe-sql'
198+
sql_integration_id: DATAFRAME_SQL_INTEGRATION_ID
193199
};
194200

195201
// Determine the index where to insert the new cell (below current selection or at the end)
@@ -261,6 +267,61 @@ export class DeepnoteNotebookCommandListener implements IExtensionSyncActivation
261267
await commands.executeCommand('notebook.cell.edit');
262268
}
263269

270+
public async addChartBlock(): Promise<void> {
271+
const editor = window.activeNotebookEditor;
272+
273+
if (!editor) {
274+
throw new WrappedError(l10n.t('No active notebook editor found'));
275+
}
276+
277+
const document = editor.notebook;
278+
const selection = editor.selection;
279+
const insertIndex = selection ? selection.end : document.cellCount;
280+
281+
const defaultVisualizationSpec = {
282+
mark: 'line',
283+
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
284+
data: { values: [] },
285+
encoding: {
286+
x: { field: 'x', type: 'quantitative' },
287+
y: { field: 'y', type: 'quantitative' }
288+
}
289+
};
290+
291+
const cellContent = {
292+
variable: 'df_1',
293+
spec: defaultVisualizationSpec,
294+
filters: []
295+
};
296+
297+
const metadata = {
298+
__deepnotePocket: {
299+
type: 'visualization'
300+
}
301+
};
302+
303+
const result = await chainWithPendingUpdates(document, (edit) => {
304+
const newCell = new NotebookCellData(NotebookCellKind.Code, JSON.stringify(cellContent, null, 2), 'json');
305+
306+
newCell.metadata = metadata;
307+
308+
const nbEdit = NotebookEdit.insertCells(insertIndex, [newCell]);
309+
310+
edit.set(document.uri, [nbEdit]);
311+
});
312+
313+
if (result !== true) {
314+
throw new WrappedError(l10n.t('Failed to insert chart block'));
315+
}
316+
317+
const notebookRange = new NotebookRange(insertIndex, insertIndex + 1);
318+
319+
editor.revealRange(notebookRange, NotebookEditorRevealType.Default);
320+
editor.selection = notebookRange;
321+
322+
await commands.executeCommand('notebook.cell.edit');
323+
}
324+
264325
public async addInputBlock(blockType: InputBlockType): Promise<void> {
265326
const editor = window.activeNotebookEditor;
266327
if (!editor) {

0 commit comments

Comments
 (0)