Skip to content

Commit

Permalink
feat: Add copy/rename/delete options to notebook overflow menu (deeph…
Browse files Browse the repository at this point in the history
…aven#1551)

* Adds options to make a copy of, rename, or delete the file currently
being viewed in the notebook panel
* Resolves deephaven#1359

#### Testing Instructions:
* Open any file create a new file
* Navigate to the overflow menu in the top right of the notebook panel
* The "copy file" option should create a copy of the currently open file
with all of its contents copied over
* The created copy should not appear in the file explorer until a save
operation is done on it
* The "rename file" option should cause the file to appear in the file
explorer with the same contents and specified name
* If the file was saved under a different name before, the old file
should be deleted
* If the file was never saved before, this operation will be identical
to a save
* The "delete file" option should close the file that the notebook panel
is currently displaying.
* If the file has been saved before, the saved file should be deleted
and no longer in the file explorer
* If the file was never saved before, this operation will be identical
to closing the file and discarding any changes

---------

Co-authored-by: georgecwan <[email protected]>
  • Loading branch information
georgecwan and georgecwan authored Sep 28, 2023
1 parent f06fbb0 commit 4441109
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
vsPlay,
dhRunSelection,
vsCheck,
vsCopy,
dhICursor,
vsTrash,
} from '@deephaven/icons';
import {
getFileStorage,
Expand Down Expand Up @@ -112,6 +115,7 @@ interface NotebookPanelState {
panelState: PanelState;

showCloseModal: boolean;
showDeleteModal: boolean;
showSaveAsModal: boolean;

scriptCode: string;
Expand Down Expand Up @@ -164,6 +168,9 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
this.handleCloseDiscard = this.handleCloseDiscard.bind(this);
this.handleCloseSave = this.handleCloseSave.bind(this);
this.handleCopy = this.handleCopy.bind(this);
this.handleDelete = this.handleDelete.bind(this);
this.handleDeleteConfirm = this.handleDeleteConfirm.bind(this);
this.handleDeleteCancel = this.handleDeleteCancel.bind(this);
this.handleEditorInitialized = this.handleEditorInitialized.bind(this);
this.handleEditorWillDestroy = this.handleEditorWillDestroy.bind(this);
this.handleEditorChange = this.handleEditorChange.bind(this);
Expand Down Expand Up @@ -268,6 +275,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
},

showCloseModal: false,
showDeleteModal: false,
showSaveAsModal: false,

scriptCode: '',
Expand Down Expand Up @@ -547,19 +555,40 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
shortcut: SHORTCUTS.NOTEBOOK.FIND,
order: 10,
},
{
title: 'Copy File',
icon: vsCopy,
action: this.handleCopy,
group: ContextActions.groups.medium,
order: 20,
},
{
title: 'Rename File',
icon: dhICursor,
action: this.handleShowRename,
group: ContextActions.groups.medium,
order: 30,
},
{
title: 'Delete File',
icon: vsTrash,
action: this.handleDelete,
group: ContextActions.groups.medium,
order: 40,
},
{
title: 'Show Minimap',
icon: isMinimapEnabled ? vsCheck : undefined,
action: this.handleMinimapChange,
group: ContextActions.groups.medium,
group: ContextActions.groups.low,
shortcut: SHORTCUTS.NOTEBOOK.MINIMAP,
order: 20,
},
{
title: 'Word Wrap',
icon: isWordWrapEnabled ? vsCheck : undefined,
action: this.handleWordWrapChange,
group: ContextActions.groups.medium,
group: ContextActions.groups.low,
shortcut: SHORTCUTS.NOTEBOOK.WORDWRAP,
order: 30,
},
Expand Down Expand Up @@ -650,6 +679,34 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
this.createNotebook(copyName, language, content);
}

handleDelete(): void {
log.debug('handleDelete, pending confirmation');
this.setState({ showDeleteModal: true });
}

handleDeleteConfirm(): void {
const { fileStorage, glContainer, glEventHub } = this.props;
const { fileMetadata } = this.state;

log.debug('handleDeleteConfirm', fileMetadata?.itemName);
this.setState({ showDeleteModal: false });

if (!fileMetadata) {
return;
}

if (FileUtils.hasPath(fileMetadata.itemName)) {
glEventHub.emit(NotebookEvent.CLOSE_FILE, fileMetadata, { force: true });
fileStorage.deleteFile(fileMetadata.itemName);
} else {
glContainer.close({ force: true });
}
}

handleDeleteCancel(): void {
this.setState({ showDeleteModal: false });
}

handleEditorInitialized(innerEditor: editor.IStandaloneCodeEditor): void {
this.editor = innerEditor;
}
Expand Down Expand Up @@ -1118,6 +1175,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
sessionLanguage,
settings: initialSettings,
showCloseModal,
showDeleteModal,
showSaveAsModal,
} = this.state;
// We don't want to steal focus if this isn't shown or it's just a preview
Expand Down Expand Up @@ -1308,6 +1366,14 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
notifyOnExtensionChange
storage={fileStorage}
/>
<BasicModal
isOpen={showDeleteModal}
headerText={`Are you sure you want to delete "${itemName}"?`}
bodyText="You cannot undo this action."
onCancel={this.handleDeleteCancel}
onConfirm={this.handleDeleteConfirm}
confirmButtonText="Delete"
/>
<BasicModal
isOpen={showCloseModal}
headerText={`Do you want to save the changes you made to ${itemName}?`}
Expand Down

0 comments on commit 4441109

Please sign in to comment.