Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add copy/rename/delete options to notebook overflow menu #1551

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 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,29 @@ 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, glEventHub } = this.props;
const { fileMetadata } = this.state;

log.debug('handleDeleteConfirm', fileMetadata?.itemName);

if (!fileMetadata) {
return;
}

glEventHub.emit(NotebookEvent.CLOSE_FILE, fileMetadata, { force: true });
fileStorage.deleteFile(fileMetadata.itemName);
}

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

handleEditorInitialized(innerEditor: editor.IStandaloneCodeEditor): void {
this.editor = innerEditor;
}
Expand Down Expand Up @@ -1118,6 +1170,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 +1361,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
Loading