Skip to content

Commit

Permalink
Add flag to ViewManagerModel.selectViewAsync for whether a user sho…
Browse files Browse the repository at this point in the history
…uld be alerted to unsaved changes (#3888)
  • Loading branch information
ghsolomon authored Jan 6, 2025
1 parent c84d714 commit e7a22fa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmp/viewmanager/ViewManagerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,19 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
}
}

async selectViewAsync(info: ViewInfo): Promise<void> {
async selectViewAsync(info: ViewInfo, opts = {alertUnsavedChanges: true}): Promise<void> {
// ensure any pending auto-save gets completed
if (this.isValueDirty && this.isViewAutoSavable) {
await this.maybeAutoSaveAsync();
}

// if still dirty, require confirm
if (this.isValueDirty && this.view.isOwned && !(await this.confirmDiscardChangesAsync())) {
if (
opts.alertUnsavedChanges &&
this.isValueDirty &&
this.view.isOwned &&
!(await this.confirmDiscardChangesAsync())
) {
return;
}

Expand Down

0 comments on commit e7a22fa

Please sign in to comment.