Skip to content

Commit bba2d01

Browse files
authored
fix: Save or discard a changed notebook does not close modal on first click (#1188)
Fixes #1187
1 parent f1f3abf commit bba2d01

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

packages/dashboard-core-plugins/src/panels/NotebookPanel.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ interface NotebookPanelState {
119119
scriptCode: string;
120120

121121
itemName?: string;
122-
123-
shouldPromptClose: boolean;
124122
}
125123

126124
class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
@@ -274,8 +272,6 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
274272
showSaveAsModal: false,
275273

276274
scriptCode: '',
277-
278-
shouldPromptClose: true,
279275
};
280276

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

347+
/**
348+
* Adds a beforeClose handler to check if a notebook needs to be saved
349+
* Call panel close with force if the check can be skipped
350+
*
351+
* Note that firing a close event manually may trigger before state update occurs
352+
* In those instances, use force
353+
*/
351354
initTabCloseOverride() {
352355
const { glContainer } = this.props;
353356
glContainer.beforeClose((options?: CloseOptions) => {
354357
if (options?.force === true) {
355358
return true;
356359
}
357360

358-
const { changeCount, savedChangeCount, shouldPromptClose } = this.state;
359-
if (changeCount !== savedChangeCount && shouldPromptClose) {
361+
const { changeCount, savedChangeCount } = this.state;
362+
if (changeCount !== savedChangeCount) {
360363
this.setState({ showCloseModal: true });
361364
return false;
362365
}
@@ -589,21 +592,21 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
589592
}
590593

591594
handleCloseDiscard(): void {
592-
this.setState({ shouldPromptClose: false, showCloseModal: false });
595+
this.setState({ showCloseModal: false });
593596
const { glContainer } = this.props;
594-
glContainer.close();
597+
glContainer.close({ force: true });
595598
}
596599

597600
handleCloseSave(): void {
598-
this.setState({ shouldPromptClose: false, showCloseModal: false });
601+
this.setState({ showCloseModal: false });
599602
if (this.save()) {
600603
const { glContainer } = this.props;
601-
glContainer.close();
604+
glContainer.close({ force: true });
602605
}
603606
}
604607

605608
handleCloseCancel(): void {
606-
this.setState({ shouldPromptClose: true, showCloseModal: false });
609+
this.setState({ showCloseModal: false });
607610
}
608611

609612
/**
@@ -1032,7 +1035,7 @@ class NotebookPanel extends Component<NotebookPanelProps, NotebookPanelState> {
10321035
}
10331036

10341037
runCommand(command?: string): void {
1035-
if (command === undefined) {
1038+
if (command === undefined || command === '') {
10361039
log.debug('Ignoring empty command.');
10371040
return;
10381041
}

0 commit comments

Comments
 (0)