Skip to content

Commit

Permalink
fix: DOCTYPE_XXX better reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaltation committed Jan 16, 2025
1 parent 913c45d commit e4756cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions app/client/models/DocPageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ import {buildUrlId, IGristUrlState, parseUrlId, UrlIdParts} from 'app/common/gri
import {getReconnectTimeout} from 'app/common/gutil';
import {canEdit, isOwner} from 'app/common/roles';
import {UserInfo} from 'app/common/User';
import {Document, NEW_DOCUMENT_CODE, Organization, UserAPI, Workspace} from 'app/common/UserAPI';
import {
DOCTYPE_TEMPLATE,
DOCTYPE_TUTORIAL,
Document,
NEW_DOCUMENT_CODE,
Organization,
UserAPI,
Workspace
} from 'app/common/UserAPI';
import {Holder, Observable, subscribe} from 'grainjs';
import {Computed, Disposable, dom, DomArg, DomElementArg} from 'grainjs';
import {makeT} from 'app/client/lib/localization';
Expand Down Expand Up @@ -503,7 +511,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
const isBareFork = isFork && idParts.trunkId === NEW_DOCUMENT_CODE;
const isSnapshot = Boolean(idParts.snapshotId);
const type = doc.type;
const isTutorial = type === 'tutorial';
const isTutorial = type === DOCTYPE_TUTORIAL;
const isTutorialTrunk = isTutorial && !isFork && mode !== 'default';
const isTutorialFork = isTutorial && isFork;

Expand All @@ -515,7 +523,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
// mode. Since the document's 'openMode' has no effect, don't bother trying
// to set it here, as it'll potentially be confusing for other code reading it.
openMode = 'default';
} else if (!isFork && type === 'template') {
} else if (!isFork && type === DOCTYPE_TEMPLATE) {
// Templates should always open in fork mode by default.
openMode = 'fork';
} else {
Expand All @@ -525,7 +533,7 @@ function buildDocInfo(doc: Document, mode: OpenDocMode | undefined): DocInfo {
}

const isPreFork = openMode === 'fork';
const isTemplate = type === 'template' && (isFork || isPreFork);
const isTemplate = type === DOCTYPE_TEMPLATE && (isFork || isPreFork);
const isEditable = !isSnapshot && (canEdit(doc.access) || isPreFork);
return {
...doc,
Expand Down
4 changes: 2 additions & 2 deletions app/common/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export interface Workspace extends WorkspaceProperties {
isSupportWorkspace?: boolean;
}

// null stands for normal document type, the one set by default at document creation.
export const DOCTYPE_NORMAL = null;
export const DOCTYPE_TEMPLATE = 'template';
export const DOCTYPE_TUTORIAL = 'tutorial';

// null stands for normal document type, the one set by default at document creation.
export type DocumentType = 'template'|'tutorial'|null;
export type DocumentType = typeof DOCTYPE_NORMAL | typeof DOCTYPE_TEMPLATE | typeof DOCTYPE_TUTORIAL;

// Non-core options for a document.
// "Non-core" means bundled into a single options column in the database.
Expand Down

0 comments on commit e4756cf

Please sign in to comment.