(core) Update active view id when default view id changes

Summary:
This fixes a bug where deleting a page with the page id
missing from the URL would cause JS errors to be thrown.

Test Plan:
Verified manually in dev environment. Browser test added
that should hopefully replicate the repro steps and catch
any regressions.

Reviewers: dsagal, paulfitz

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2856
This commit is contained in:
George Gevoian 2021-06-09 20:48:39 -07:00
parent 6f02987d10
commit 982711dbba

View File

@ -153,7 +153,9 @@ export class GristDoc extends DisposableWithEvents {
const defaultViewId = this.docInfo.newDefaultViewId; const defaultViewId = this.docInfo.newDefaultViewId;
// Grainjs observable for current view id, which may be a string such as 'code'. // Grainjs observable for current view id, which may be a string such as 'code'.
this.activeViewId = Computed.create(this, urlState().state, (use, s) => s.docPage || defaultViewId.peek()); this.activeViewId = Computed.create(this, (use) => {
return use(urlState().state).docPage || use(defaultViewId);
});
// This viewModel reflects the currently active view, relying on the fact that // This viewModel reflects the currently active view, relying on the fact that
// createFloatingRowModel() supports an observable rowId for its argument. // createFloatingRowModel() supports an observable rowId for its argument.