Skip to content

Commit a23b28f

Browse files
committed
feat: Extract command ids into separate config files
Signed-off-by: Tomas Kislan <[email protected]>
1 parent bc86068 commit a23b28f

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

src/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,13 @@ export interface ICommandNameArgumentTypeMapping {
197197
[DSCommands.AddInputDateRangeBlock]: [];
198198
[DSCommands.AddInputFileBlock]: [];
199199
[DSCommands.AddButtonBlock]: [];
200+
[DSCommands.NewProject]: [];
201+
[DSCommands.ImportNotebook]: [];
202+
[DSCommands.ImportJupyterNotebook]: [];
203+
[DSCommands.RenameProject]: [];
204+
[DSCommands.DeleteProject]: [];
205+
[DSCommands.RenameNotebook]: [];
206+
[DSCommands.DeleteNotebook]: [];
207+
[DSCommands.DuplicateNotebook]: [];
208+
[DSCommands.AddNotebookToProject]: [];
200209
}

src/notebooks/deepnote/deepnoteExplorerView.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DeepnoteTreeDataProvider } from './deepnoteTreeDataProvider';
99
import { type DeepnoteTreeItem, DeepnoteTreeItemType, type DeepnoteTreeItemContext } from './deepnoteTreeItem';
1010
import { generateUuid } from '../../platform/common/uuid';
1111
import type { DeepnoteFile, DeepnoteNotebook, DeepnoteBlock } from '../../platform/deepnote/deepnoteTypes';
12+
import { Commands } from '../../platform/common/constants';
1213

1314
/**
1415
* Manages the Deepnote explorer tree view and related commands
@@ -40,72 +41,72 @@ export class DeepnoteExplorerView {
4041

4142
private registerCommands(): void {
4243
this.extensionContext.subscriptions.push(
43-
commands.registerCommand('deepnote.refreshExplorer', () => this.refreshExplorer())
44+
commands.registerCommand(Commands.RefreshDeepnoteExplorer, () => this.refreshExplorer())
4445
);
4546

4647
this.extensionContext.subscriptions.push(
47-
commands.registerCommand('deepnote.openNotebook', (context: DeepnoteTreeItemContext) =>
48+
commands.registerCommand(Commands.OpenDeepnoteNotebook, (context: DeepnoteTreeItemContext) =>
4849
this.openNotebook(context)
4950
)
5051
);
5152

5253
this.extensionContext.subscriptions.push(
53-
commands.registerCommand('deepnote.openFile', (treeItem: DeepnoteTreeItem) => this.openFile(treeItem))
54+
commands.registerCommand(Commands.OpenDeepnoteFile, (treeItem: DeepnoteTreeItem) => this.openFile(treeItem))
5455
);
5556

5657
this.extensionContext.subscriptions.push(
57-
commands.registerCommand('deepnote.revealInExplorer', () => this.revealActiveNotebook())
58+
commands.registerCommand(Commands.RevealInDeepnoteExplorer, () => this.revealActiveNotebook())
5859
);
5960

6061
this.extensionContext.subscriptions.push(
61-
commands.registerCommand('deepnote.newProject', () => this.newProject())
62+
commands.registerCommand(Commands.NewProject, () => this.newProject())
6263
);
6364

6465
this.extensionContext.subscriptions.push(
65-
commands.registerCommand('deepnote.importNotebook', () => this.importNotebook())
66+
commands.registerCommand(Commands.ImportNotebook, () => this.importNotebook())
6667
);
6768

6869
this.extensionContext.subscriptions.push(
69-
commands.registerCommand('deepnote.importJupyterNotebook', () => this.importJupyterNotebook())
70+
commands.registerCommand(Commands.ImportJupyterNotebook, () => this.importJupyterNotebook())
7071
);
7172

7273
this.extensionContext.subscriptions.push(
73-
commands.registerCommand('deepnote.newNotebook', () => this.newNotebook())
74+
commands.registerCommand(Commands.NewNotebook, () => this.newNotebook())
7475
);
7576

7677
// Context menu commands for tree items
7778
this.extensionContext.subscriptions.push(
78-
commands.registerCommand('deepnote.renameProject', (treeItem: DeepnoteTreeItem) =>
79+
commands.registerCommand(Commands.RenameProject, (treeItem: DeepnoteTreeItem) =>
7980
this.renameProject(treeItem)
8081
)
8182
);
8283

8384
this.extensionContext.subscriptions.push(
84-
commands.registerCommand('deepnote.deleteProject', (treeItem: DeepnoteTreeItem) =>
85+
commands.registerCommand(Commands.DeleteProject, (treeItem: DeepnoteTreeItem) =>
8586
this.deleteProject(treeItem)
8687
)
8788
);
8889

8990
this.extensionContext.subscriptions.push(
90-
commands.registerCommand('deepnote.renameNotebook', (treeItem: DeepnoteTreeItem) =>
91+
commands.registerCommand(Commands.RenameNotebook, (treeItem: DeepnoteTreeItem) =>
9192
this.renameNotebook(treeItem)
9293
)
9394
);
9495

9596
this.extensionContext.subscriptions.push(
96-
commands.registerCommand('deepnote.deleteNotebook', (treeItem: DeepnoteTreeItem) =>
97+
commands.registerCommand(Commands.DeleteNotebook, (treeItem: DeepnoteTreeItem) =>
9798
this.deleteNotebook(treeItem)
9899
)
99100
);
100101

101102
this.extensionContext.subscriptions.push(
102-
commands.registerCommand('deepnote.duplicateNotebook', (treeItem: DeepnoteTreeItem) =>
103+
commands.registerCommand(Commands.DuplicateNotebook, (treeItem: DeepnoteTreeItem) =>
103104
this.duplicateNotebook(treeItem)
104105
)
105106
);
106107

107108
this.extensionContext.subscriptions.push(
108-
commands.registerCommand('deepnote.addNotebookToProject', (treeItem: DeepnoteTreeItem) =>
109+
commands.registerCommand(Commands.AddNotebookToProject, (treeItem: DeepnoteTreeItem) =>
109110
this.addNotebookToProject(treeItem)
110111
)
111112
);
@@ -149,7 +150,10 @@ export class DeepnoteExplorerView {
149150
* @param suggestedName The default suggested name
150151
* @returns The entered notebook name, or undefined if cancelled
151152
*/
152-
private async promptForNotebookName(suggestedName: string): Promise<string | undefined> {
153+
private async promptForNotebookName(
154+
suggestedName: string,
155+
existingNames: Set<string>
156+
): Promise<string | undefined> {
153157
return await window.showInputBox({
154158
prompt: l10n.t('Enter a name for the new notebook'),
155159
placeHolder: suggestedName,
@@ -158,6 +162,9 @@ export class DeepnoteExplorerView {
158162
if (!value || value.trim().length === 0) {
159163
return l10n.t('Notebook name cannot be empty');
160164
}
165+
if (existingNames.has(value)) {
166+
return l10n.t('A notebook with this name already exists');
167+
}
161168
return null;
162169
}
163170
});
@@ -240,14 +247,22 @@ export class DeepnoteExplorerView {
240247
// Read the Deepnote project file
241248
const projectData = await this.readDeepnoteProjectFile(fileUri);
242249

250+
if (projectData.project.id !== projectId) {
251+
await window.showErrorMessage(l10n.t('Project ID mismatch'));
252+
return null;
253+
}
254+
243255
if (!projectData?.project) {
244256
await window.showErrorMessage(l10n.t('Invalid Deepnote file format'));
245257
return null;
246258
}
247259

248260
// Generate suggested name and prompt user
249261
const suggestedName = this.generateSuggestedNotebookName(projectData);
250-
const notebookName = await this.promptForNotebookName(suggestedName);
262+
const notebookName = await this.promptForNotebookName(
263+
suggestedName,
264+
new Set(projectData.project.notebooks?.map((nb: DeepnoteNotebook) => nb.name.toLowerCase()) ?? [])
265+
);
251266

252267
if (!notebookName) {
253268
return null;
@@ -921,7 +936,8 @@ export class DeepnoteExplorerView {
921936
...block,
922937
id: generateUuid(),
923938
blockGroup: generateUuid(),
924-
executionCount: undefined
939+
executionCount: undefined,
940+
...(block.metadata != null ? { metadata: { ...block.metadata } } : {})
925941
}))
926942
};
927943

src/platform/common/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ export namespace Commands {
236236
export const AddInputFileBlock = 'deepnote.addInputFileBlock';
237237
export const AddButtonBlock = 'deepnote.addButtonBlock';
238238
export const NewNotebook = 'deepnote.newNotebook';
239+
export const NewProject = 'deepnote.newProject';
240+
export const ImportNotebook = 'deepnote.importNotebook';
241+
export const ImportJupyterNotebook = 'deepnote.importJupyterNotebook';
242+
export const RenameProject = 'deepnote.renameProject';
243+
export const DeleteProject = 'deepnote.deleteProject';
244+
export const RenameNotebook = 'deepnote.renameNotebook';
245+
export const DeleteNotebook = 'deepnote.deleteNotebook';
246+
export const DuplicateNotebook = 'deepnote.duplicateNotebook';
247+
export const AddNotebookToProject = 'deepnote.addNotebookToProject';
239248
export const ExportAsPythonScript = 'jupyter.exportAsPythonScript';
240249
export const ExportToHTML = 'jupyter.exportToHTML';
241250
export const ExportToPDF = 'jupyter.exportToPDF';

0 commit comments

Comments
 (0)