(core) Fix non-existent page ID showing all raw data widgets

Summary: Check that view exists first, otherwise fall back to default

Test Plan: Manual

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3260
pull/131/head
Alex Hall 2 years ago
parent 592a43ec36
commit 1c855537d6

@ -53,7 +53,7 @@ import {DisposableWithEvents} from 'app/common/DisposableWithEvents';
import {isSchemaAction, UserAction} from 'app/common/DocActions';
import {OpenLocalDocResult} from 'app/common/DocListAPI';
import {isList, isRefListType, RecalcWhen} from 'app/common/gristTypes';
import {HashLink, IDocPage} from 'app/common/gristUrls';
import {HashLink, IDocPage, SpecialDocPage} from 'app/common/gristUrls';
import {undef, waitObs} from 'app/common/gutil';
import {LocalPlugin} from "app/common/plugin";
import {StringUnion} from 'app/common/StringUnion';
@ -166,13 +166,20 @@ export class GristDoc extends DisposableWithEvents {
// Grainjs observable for current view id, which may be a string such as 'code'.
this.activeViewId = Computed.create(this, (use) => {
let result = use(urlState().state).docPage;
if (result === 'GristDocTour') {
// GristDocTour is a special table that is usually hidden from users, but putting /p/GristDocTour
// in the URL navigates to it and makes it visible in the list of pages in the sidebar
result = this.docModel.views.tableData.findRow('name', result);
const {docPage} = use(urlState().state);
// Return most special pages like 'code' and 'acl' as is
if (typeof docPage === 'string' && docPage !== 'GristDocTour' && SpecialDocPage.guard(docPage)) {
return docPage;
}
return result || use(defaultViewId);
// GristDocTour is a special table that is usually hidden from users, but putting /p/GristDocTour
// in the URL navigates to it and makes it visible in the list of pages in the sidebar
// For GristDocTour, find the view with that name.
// Otherwise find the view with the given row ID, because letting a non-existent row ID pass through here is bad.
// If no such view exists, return the default view.
const viewId = this.docModel.views.tableData.findRow(docPage === 'GristDocTour' ? 'name' : 'id', docPage);
return viewId || use(defaultViewId);
});
// This viewModel reflects the currently active view, relying on the fact that

@ -10,7 +10,7 @@ import {Document} from 'app/common/UserAPI';
import clone = require('lodash/clone');
import pickBy = require('lodash/pickBy');
const SpecialDocPage = StringUnion('code', 'acl', 'data', 'GristDocTour');
export const SpecialDocPage = StringUnion('code', 'acl', 'data', 'GristDocTour');
type SpecialDocPage = typeof SpecialDocPage.type;
export type IDocPage = number | SpecialDocPage;

Loading…
Cancel
Save