Skip to content

Commit

Permalink
FIX: Document conversion work in multi-worker env
Browse files Browse the repository at this point in the history
Co-authored-by: fflorent <[email protected]>
  • Loading branch information
hexaltation and fflorent committed Jan 16, 2025
1 parent 78cca12 commit 913c45d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/client/ui/DocumentSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {commonUrls, GristLoadConfig} from 'app/common/gristUrls';
import {not, propertyCompare} from 'app/common/gutil';
import {getCurrency, locales} from 'app/common/Locales';
import {isOwner, isOwnerOrEditor} from 'app/common/roles';
import {DOCTYPE_NORMAL, DOCTYPE_TEMPLATE, DOCTYPE_TUTORIAL, DocumentType, persistType} from 'app/common/UserAPI';
import {DOCTYPE_NORMAL, DOCTYPE_TEMPLATE, DOCTYPE_TUTORIAL, DocumentType} from 'app/common/UserAPI';
import {
Computed,
Disposable,
Expand Down Expand Up @@ -333,7 +333,6 @@ export class DocSettingsPage extends Disposable {
const selected = Observable.create<DocTypeOption>(owner, currentDocTypeOption);

const doSetDocumentType = async () => {
const docId = docPageModel.currentDocId.get();
let docType: DocumentType;
if (selected.get() === DocTypeOption.Regular) {
docType = DOCTYPE_NORMAL;
Expand All @@ -342,8 +341,9 @@ export class DocSettingsPage extends Disposable {
} else {
docType = DOCTYPE_TUTORIAL;
}
await persistType(docType, docId);

const {trunkId} = docPageModel.currentDoc.get()!.idParts;
await docPageModel.appModel.api.persistType(docType, trunkId);
window.location.replace(urlState().makeUrl({
docPage: "settings",
fork: undefined, // will be automatically set once the page is reloaded
Expand Down
18 changes: 8 additions & 10 deletions app/common/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ 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 function persistType(type: DocumentType, docId: string|undefined) {
docId = docId?.split("~")[0];
return fetch(`/o/docs/api/docs/${docId}`, {
method: 'PATCH',
headers: {"Content-Type": "application/json"},
credentials: 'include',
body: JSON.stringify({type})
});
}

// Non-core options for a document.
// "Non-core" means bundled into a single options column in the database.
// TODO: consider smoothing over this distinction in the API.
Expand Down Expand Up @@ -431,6 +421,7 @@ export interface UserAPI {
onUploadProgress?: (ev: AxiosProgressEvent) => void,
}): Promise<string>;
deleteUser(userId: number, name: string): Promise<void>;
persistType(type: DocumentType, docId: string): Promise<void>;
getBaseUrl(): string; // Get the prefix for all the endpoints this object wraps.
forRemoved(): UserAPI; // Get a version of the API that works on removed resources.
getWidgets(): Promise<ICustomWidget[]>;
Expand Down Expand Up @@ -889,6 +880,13 @@ export class UserAPIImpl extends BaseAPI implements UserAPI {
await this.request(`${this._url}/api/doom/org`, {method: 'DELETE'});
}

public async persistType(type: DocumentType, trunkId: string) {
await this.request(`${this._url}/api/docs/${trunkId}`, {
method: 'PATCH',
body: JSON.stringify({type})
});
}

public getBaseUrl(): string { return this._url; }

// Recomputes the URL on every call to pick up changes in the URL when switching orgs.
Expand Down

0 comments on commit 913c45d

Please sign in to comment.