Skip to content

Commit

Permalink
fix: Save or discard a changed notebook does not close modal on first…
Browse files Browse the repository at this point in the history
… click (#1188)

Fixes #1187
  • Loading branch information
mattrunyon authored Mar 30, 2023
1 parent f1f3abf commit bba2d01
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ interface NotebookPanelState {
scriptCode: string;

itemName?: string;

shouldPromptClose: boolean;
}

class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
Expand Down Expand Up @@ -274,8 +272,6 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
showSaveAsModal: false,

scriptCode: '',

shouldPromptClose: true,
};

log.debug('constructor', props, this.state);
Expand Down Expand Up @@ -348,15 +344,22 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
this.initTabClasses(tab);
}

/**
* Adds a beforeClose handler to check if a notebook needs to be saved
* Call panel close with force if the check can be skipped
*
* Note that firing a close event manually may trigger before state update occurs
* In those instances, use force
*/
initTabCloseOverride() {
const { glContainer } = this.props;
glContainer.beforeClose((options?: CloseOptions) => {
if (options?.force === true) {
return true;
}

const { changeCount, savedChangeCount, shouldPromptClose } = this.state;
if (changeCount !== savedChangeCount && shouldPromptClose) {
const { changeCount, savedChangeCount } = this.state;
if (changeCount !== savedChangeCount) {
this.setState({ showCloseModal: true });
return false;
}
Expand Down Expand Up @@ -589,21 +592,21 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
}

handleCloseDiscard(): void {
this.setState({ shouldPromptClose: false, showCloseModal: false });
this.setState({ showCloseModal: false });
const { glContainer } = this.props;
glContainer.close();
glContainer.close({ force: true });
}

handleCloseSave(): void {
this.setState({ shouldPromptClose: false, showCloseModal: false });
this.setState({ showCloseModal: false });
if (this.save()) {
const { glContainer } = this.props;
glContainer.close();
glContainer.close({ force: true });
}
}

handleCloseCancel(): void {
this.setState({ shouldPromptClose: true, showCloseModal: false });
this.setState({ showCloseModal: false });
}

/**
Expand Down Expand Up @@ -1032,7 +1035,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
}

runCommand(command?: string): void {
if (command === undefined) {
if (command === undefined || command === '') {
log.debug('Ignoring empty command.');
return;
}
Expand Down

0 comments on commit bba2d01

Please sign in to comment.