Skip to content

Commit 7c84190

Browse files
committed
frontend/latex,qmd,rmd: showProjectRestartDialog for all 3 of them for outdated projects
1 parent 3f3b718 commit 7c84190

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

src/packages/backend/exec-stream.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ export async function executeStream(
180180
}
181181

182182
// Stats monitoring is now handled by execute-code.ts via streamCB
183-
// No need for duplicate monitoring here
184183
} catch (err) {
185184
stream({ error: `${err}` });
186185
stream(null); // End the stream

src/packages/frontend/frame-editors/generic/client.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
Typescript async/await rewrite of @cocalc/util/client.coffee...
88
*/
99

10+
import { Modal } from "antd";
1011
import { Map } from "immutable";
12+
1113
import { redux } from "@cocalc/frontend/app-framework";
14+
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
1215
import { webapp_client } from "@cocalc/frontend/webapp-client";
1316
import { CompressedPatch } from "@cocalc/sync/editor/generic/types";
1417
import { callback2 } from "@cocalc/util/async-utils";
1518
import { Config as FormatterConfig } from "@cocalc/util/code-formatter";
16-
import { FakeSyncstring } from "./syncstring-fake";
1719
import { type UserSearchResult as User } from "@cocalc/util/db-schema/accounts";
20+
import { FakeSyncstring } from "./syncstring-fake";
1821
export { type User };
19-
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
2022

2123
import type { ExecOpts, ExecOutput } from "@cocalc/util/db-schema/projects";
2224
export type { ExecOpts, ExecOutput };
@@ -25,6 +27,40 @@ import * as schema from "@cocalc/util/schema";
2527

2628
import { DEFAULT_FONT_SIZE } from "@cocalc/util/db-schema";
2729

30+
// Track which projects have already shown the restart dialog
31+
const shownRestartDialogs = new Set<string>();
32+
33+
export function showProjectRestartDialog(project_id: string): void {
34+
// Only show the dialog once per project
35+
if (shownRestartDialogs.has(project_id)) {
36+
return;
37+
}
38+
39+
shownRestartDialogs.add(project_id);
40+
41+
const actions = redux.getActions("projects");
42+
43+
Modal.confirm({
44+
title: "Project Needs Update",
45+
content: `This project needs to be restarted to support the new streaming compilation feature.
46+
Your work is automatically saved and will not be lost.`,
47+
okText: "Restart Project",
48+
cancelText: "Not Now",
49+
width: 500,
50+
onOk: () => {
51+
if (actions) {
52+
actions.restart_project(project_id);
53+
}
54+
// Clear the tracking when user clicks OK
55+
shownRestartDialogs.delete(project_id);
56+
},
57+
onCancel: () => {
58+
// Clear the tracking when user dismisses the dialog
59+
shownRestartDialogs.delete(project_id);
60+
},
61+
});
62+
}
63+
2864
export function server_time(): Date {
2965
return webapp_client.time_client.server_time();
3066
}

src/packages/frontend/frame-editors/latex-editor/util.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55

66
// data and functions specific to the latex editor.
77

8-
import { Modal } from "antd";
9-
10-
import { redux } from "@cocalc/frontend/app-framework";
11-
import { ExecOutput } from "@cocalc/frontend/frame-editors/generic/client";
8+
import {
9+
ExecOutput,
10+
showProjectRestartDialog,
11+
} from "@cocalc/frontend/frame-editors/generic/client";
1212
import { webapp_client } from "@cocalc/frontend/webapp-client";
1313
import { ExecOptsBlocking } from "@cocalc/util/db-schema/projects";
1414
import { separate_file_extension } from "@cocalc/util/misc";
1515
import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code";
1616
import { TIMEOUT_LATEX_JOB_S } from "./constants";
1717

18-
// Track which projects have already shown the restart dialog
19-
const shownRestartDialogs = new Set<string>();
20-
2118
export function pdf_path(path: string): string {
2219
// if it is already a pdf, don't change the upper/lower casing -- #4562
2320
const { name, ext } = separate_file_extension(path);
@@ -188,34 +185,3 @@ export async function runJob(opts: RunJobOpts): Promise<ExecOutput> {
188185
});
189186
});
190187
}
191-
192-
function showProjectRestartDialog(project_id: string): void {
193-
// Only show the dialog once per project
194-
if (shownRestartDialogs.has(project_id)) {
195-
return;
196-
}
197-
198-
shownRestartDialogs.add(project_id);
199-
200-
const actions = redux.getActions("projects");
201-
202-
Modal.confirm({
203-
title: "Project Needs Update",
204-
content: `This project needs to be restarted to support the new streaming compilation feature.
205-
Your work is automatically saved and will not be lost.`,
206-
okText: "Restart Project",
207-
cancelText: "Not Now",
208-
width: 500,
209-
onOk: () => {
210-
if (actions) {
211-
actions.restart_project(project_id);
212-
}
213-
// Clear the tracking when user clicks OK
214-
shownRestartDialogs.delete(project_id);
215-
},
216-
onCancel: () => {
217-
// Clear the tracking when user dismisses the dialog
218-
shownRestartDialogs.delete(project_id);
219-
},
220-
});
221-
}

src/packages/frontend/frame-editors/rmd-editor/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { join } from "path";
88
import { webapp_client } from "@cocalc/frontend/webapp-client";
99
import { change_filename_extension, path_split } from "@cocalc/util/misc";
1010
import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code";
11-
import { ExecOutput } from "../generic/client";
11+
import { ExecOutput, showProjectRestartDialog } from "../generic/client";
1212

1313
// something in the rmarkdown source code replaces all spaces by dashes
1414
// [hsy] I think this is because of calling pandoc.
@@ -158,7 +158,13 @@ export async function runJob(opts: RunJobOpts): Promise<ExecOutput> {
158158
});
159159

160160
stream.on("error", (err) => {
161-
reject(err);
161+
// Check if this is a 503 error (exec-stream service not available in old project)
162+
if (err?.code === 503) {
163+
showProjectRestartDialog(project_id);
164+
reject(err);
165+
} else {
166+
reject(err);
167+
}
162168
});
163169
});
164170
}

0 commit comments

Comments
 (0)