Skip to content

Commit 2d84f22

Browse files
committed
Merge remote-tracking branch 'origin/master' into api-exec-await
2 parents 2891dd0 + d68f2f0 commit 2d84f22

File tree

14 files changed

+122
-68
lines changed

14 files changed

+122
-68
lines changed

src/packages/frontend/frame-editors/frame-tree/hooks.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
33
* License: MS-RSL – see LICENSE.md for details
44
*/
5-
import { React, redux } from "../../app-framework";
5+
import { redux } from "../../app-framework";
66
import { DEFAULT_FONT_SIZE } from "@cocalc/util/db-schema/defaults";
77

88
// this doesn't react to font size changes. maybe at some point we want to...
@@ -25,17 +25,10 @@ export function baseFontSize() {
2525
// transformOrigin: "center 0", // or "0 0"
2626
// }
2727
export function use_font_size_scaling(font_size: number): number {
28-
const [font_size_prev, set_font_size_prev] =
29-
React.useState<number>(DEFAULT_FONT_SIZE);
30-
const [scaling, set_scaling] = React.useState<number>(1);
31-
32-
if (font_size != font_size_prev) {
33-
set_font_size_prev(font_size);
34-
} else {
35-
return scaling;
36-
}
28+
return getScale(font_size);
29+
}
3730

31+
export function getScale(fontSize: number): number {
3832
const base = baseFontSize();
39-
set_scaling((font_size != null ? font_size : base) / base);
40-
return scaling;
33+
return (fontSize != null ? fontSize : base) / base;
4134
}

src/packages/frontend/frame-editors/jupyter-editor/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class JupyterEditorActions extends BaseActions<JupyterEditorState> {
233233
}
234234

235235
print(_id): void {
236-
this.jupyter_actions.show_nbconvert_dialog("cocalc-html");
236+
this.jupyter_actions.show_nbconvert_dialog("cocalc-pdf");
237237
}
238238

239239
async format(id: string): Promise<void> {

src/packages/frontend/frame-editors/markdown-editor/editor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const EDITOR_SPEC = {
3131
//"print",
3232
"decrease_font_size",
3333
"increase_font_size",
34+
"set_zoom",
3435
"save",
3536
"time_travel",
3637
"show_table_of_contents",
@@ -51,6 +52,7 @@ const EDITOR_SPEC = {
5152
"readonly_view",
5253
"decrease_font_size",
5354
"increase_font_size",
55+
"set_zoom",
5456
"sync",
5557
"show_table_of_contents",
5658
]),
@@ -105,6 +107,7 @@ const EDITOR_SPEC = {
105107
"print",
106108
"decrease_font_size",
107109
"increase_font_size",
110+
"set_zoom",
108111
"show_table_of_contents",
109112
"time_travel",
110113
"undo", // need these because button bars at top let you do something even in rendered only view.

src/packages/frontend/frame-editors/time-travel-editor/actions.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export interface TimeTravelState extends CodeEditorState {
6767
// true if in a git repo
6868
git?: boolean;
6969
//frame_states: Map<string, any>; // todo: really map from frame_id to FrameState as immutable map.
70+
// timetravel has own error state
71+
error: string;
7072
}
7173

7274
export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
@@ -107,6 +109,10 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
107109
return { type: "time_travel" };
108110
}
109111

112+
set_error = (error) => {
113+
this.setState({ error });
114+
};
115+
110116
private init_syncdoc = async (): Promise<void> => {
111117
const persistent = this.docext == "ipynb" || this.docext == "sagews"; // ugly for now (?)
112118
this.syncdoc = await webapp_client.sync_client.open_existing_sync_document({
@@ -179,14 +185,15 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
179185
}
180186
};
181187

182-
load_full_history = async (): Promise<void> => {
188+
loadFullHistory = async (): Promise<void> => {
183189
if (
184190
this.store.get("has_full_history") ||
185191
this.syncdoc == null ||
186192
this.store.get("git_mode")
187-
)
193+
) {
188194
return;
189-
await this.syncdoc.load_full_history(); // todo -- error reporting ...?
195+
}
196+
await this.syncdoc.load_full_history();
190197
this.setState({ has_full_history: true });
191198
this.syncdoc_changed(); // load new versions list.
192199
};
@@ -283,6 +290,17 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
283290
}
284291
};
285292

293+
setNewestVersion = (id: string) => {
294+
const node = this.getFrameNodeGlobal(id);
295+
const versions = node?.get("git_mode")
296+
? this.store.get("git_versions")
297+
: this.store.get("versions");
298+
const v = (versions?.size ?? 0) - 1;
299+
if (v >= 0) {
300+
this.set_version(id, v);
301+
}
302+
};
303+
286304
step = (id: string, delta: number): void => {
287305
const node = this.getFrameNodeGlobal(id);
288306
if (node.get("changes_mode")) {
@@ -498,8 +516,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
498516
});
499517
this.ensureSelectedVersionsAreConsistent({ git_versions });
500518
return git_versions;
501-
} catch (err) {
502-
this.set_error(`${err}`);
519+
} catch (_err) {
520+
// Do NOT report error -- instead, disable git mode. This should
521+
// happen if the file is not in a git repo.
503522
this.setState({ git: false });
504523
return;
505524
}

src/packages/frontend/frame-editors/time-travel-editor/export.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- This is really just some minimal data *about* the history for now.
99
*/
1010

11-
import { Button } from "antd";
11+
import { Button, Tooltip } from "antd";
1212
import { TimeTravelActions } from "./actions";
1313
import { Icon } from "../../components";
1414

@@ -18,11 +18,10 @@ interface Props {
1818

1919
export function Export({ actions }: Props) {
2020
return (
21-
<Button
22-
onClick={() => actions.exportEditHistory()}
23-
title="Export information about edit history to a JSON file"
24-
>
25-
<Icon name={"file-export"} /> Export
26-
</Button>
21+
<Tooltip title={"Export information about edit history to a JSON file"}>
22+
<Button onClick={() => actions.exportEditHistory()}>
23+
<Icon name={"file-export"} /> Export
24+
</Button>
25+
</Tooltip>
2726
);
2827
}

src/packages/frontend/frame-editors/time-travel-editor/load-full-history.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,41 @@
22
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
33
* License: MS-RSL – see LICENSE.md for details
44
*/
5-
6-
import { Button } from "antd";
5+
import { useState } from "react";
6+
import { Button, Spin, Tooltip } from "antd";
77
import { TimeTravelActions } from "./actions";
88
import { Icon } from "../../components";
99

1010
interface Props {
11+
id: string;
1112
actions: TimeTravelActions;
1213
}
1314

14-
export function LoadFullHistory({ actions }: Props) {
15+
export function LoadFullHistory({ id, actions }: Props) {
16+
const [loading, setLoading] = useState<boolean>(false);
1517
return (
16-
<Button
17-
onClick={() => actions.load_full_history()}
18-
title={"Load the complete edit history for this file."}
18+
<Tooltip
19+
title={
20+
"Load the full edit history for this file. This may take a long time."
21+
}
1922
>
20-
<Icon name="file-archive" /> Load All
21-
</Button>
23+
<Button
24+
disabled={loading}
25+
onClick={async () => {
26+
try {
27+
setLoading(true);
28+
await actions.loadFullHistory();
29+
} catch (err) {
30+
console.log("ERROR!", err);
31+
actions.set_error(`${err}`);
32+
} finally {
33+
setLoading(false);
34+
actions.setNewestVersion(id);
35+
}
36+
}}
37+
>
38+
<Icon name="file-archive" /> Load All {loading && <Spin />}
39+
</Button>
40+
</Tooltip>
2241
);
2342
}

src/packages/frontend/frame-editors/time-travel-editor/revert-file.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { Button } from "antd";
6+
import { Button, Tooltip } from "antd";
77
import { TimeTravelActions } from "./actions";
88
import { Icon } from "../../components";
99

@@ -12,20 +12,27 @@ interface Props {
1212
actions: TimeTravelActions;
1313
version: Date | undefined;
1414
doc;
15+
changesMode?: boolean;
1516
}
1617

17-
export function RevertFile({ id, actions, version, doc }: Props) {
18+
export function RevertFile({ id, actions, version, doc, changesMode }: Props) {
1819
return (
19-
<Button
20-
title={`Revert file to the displayed version (this makes a new version, so nothing is lost)`}
21-
onClick={() => {
22-
if (version != null) {
23-
actions.revert(id, version, doc);
24-
}
25-
}}
26-
disabled={version == null || actions.syncdoc?.is_read_only()}
20+
<Tooltip
21+
title={`Revert file to the displayed version (this makes a new version, so nothing is lost). ${
22+
changesMode ? "In changes mode, this uses newer version." : ""
23+
}`}
2724
>
28-
<Icon name="undo" /> Revert
29-
</Button>
25+
{" "}
26+
<Button
27+
onClick={() => {
28+
if (version != null) {
29+
actions.revert(id, version, doc);
30+
}
31+
}}
32+
disabled={version == null || actions.syncdoc?.is_read_only()}
33+
>
34+
<Icon name="undo" /> Revert
35+
</Button>
36+
</Tooltip>
3037
);
3138
}

src/packages/frontend/frame-editors/time-travel-editor/time-travel.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
import { useState } from "react";
99
import { Button, Checkbox, Tooltip } from "antd";
1010
import { Map } from "immutable";
11-
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
11+
import {
12+
redux,
13+
useTypedRedux,
14+
useAsyncEffect,
15+
useEditorRedux,
16+
} from "@cocalc/frontend/app-framework";
1217
import { Loading } from "@cocalc/frontend/components";
1318
import { TimeTravelActions, TimeTravelState } from "./actions";
1419
import { Diff } from "./diff";
@@ -26,11 +31,11 @@ import { Export } from "./export";
2631
import json_stable from "json-stable-stringify";
2732
import { to_ipynb } from "../../jupyter/history-viewer";
2833
import { SagewsDiff } from "./sagews-diff";
29-
import { useAsyncEffect, useEditorRedux } from "@cocalc/frontend/app-framework";
3034
import { Viewer } from "./viewer";
3135
import type { Document } from "@cocalc/sync/editor/generic/types";
3236
import useLicenses from "@cocalc/frontend/site-licenses/use-licenses";
3337
import RequireLicense from "@cocalc/frontend/site-licenses/require-license";
38+
import ShowError from "@cocalc/frontend/components/error";
3439

3540
const HAS_SPECIAL_VIEWER = new Set([
3641
"tasks",
@@ -62,6 +67,7 @@ export function TimeTravel(props: Props) {
6267
"unlicensed_project_timetravel_limit",
6368
);
6469
const licenses = useLicenses({ project_id });
70+
const error = useEditor("error");
6571
const versions = useEditor("versions");
6672
const gitVersions = useEditor("git_versions");
6773
const hasFullHistory = useEditor("has_full_history");
@@ -263,8 +269,10 @@ export function TimeTravel(props: Props) {
263269
};
264270

265271
const renderLoadFullHistory = () => {
266-
if (hasFullHistory) return;
267-
return <LoadFullHistory actions={props.actions} />;
272+
if (hasFullHistory || gitMode) {
273+
return;
274+
}
275+
return <LoadFullHistory id={props.id} actions={props.actions} />;
268276
};
269277

270278
const renderOpenFile = () => {
@@ -278,11 +286,12 @@ export function TimeTravel(props: Props) {
278286
};
279287

280288
const renderRevertFile = () => {
281-
if (changesMode || doc == null) {
289+
if (doc == null) {
282290
return;
283291
}
284292
return (
285293
<RevertFile
294+
changesMode={changesMode}
286295
actions={props.actions}
287296
version={getVersion()}
288297
id={props.id}
@@ -304,7 +313,7 @@ export function TimeTravel(props: Props) {
304313
};
305314

306315
const renderExport = () => {
307-
if (redux.getStore("page").get("fullscreen") == "kiosk") {
316+
if (gitMode || redux.getStore("page").get("fullscreen") == "kiosk") {
308317
// doesn't make sense in kiosk mode.
309318
return;
310319
}
@@ -447,6 +456,11 @@ export function TimeTravel(props: Props) {
447456
{renderControls()}
448457
{renderTimeSelect()}
449458
{gitMode && !changesMode && renderGitSubject()}
459+
<ShowError
460+
style={{ margin: "5px 15px" }}
461+
error={error}
462+
setError={props.actions.set_error}
463+
/>
450464
{body}
451465
</div>
452466
);

src/packages/frontend/frame-editors/time-travel-editor/viewer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { HistoryViewer as JupyterHistoryViewer } from "../../jupyter/history-vie
1010
import { SagewsCodemirror } from "./sagews-codemirror";
1111
import Whiteboard from "@cocalc/frontend/frame-editors/whiteboard-editor/time-travel";
1212
import { isObjectDoc } from "./view-document";
13+
import { getScale } from "@cocalc/frontend/frame-editors/frame-tree/hooks";
1314

1415
export function Viewer({
1516
ext,
@@ -58,9 +59,13 @@ export function Viewer({
5859
case "sagews":
5960
return <SagewsCodemirror {...opts} />;
6061
case "md":
62+
const scale = getScale(font_size);
6163
return (
6264
<div style={{ overflow: "auto", padding: "50px 70px" }}>
63-
<StaticMarkdown value={doc.to_str()} />
65+
<StaticMarkdown
66+
value={doc.to_str()}
67+
style={{ fontSize: `${100 * scale}%` }}
68+
/>
6469
</div>
6570
);
6671
case "board":

src/packages/frontend/jupyter/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export function commands(actions: AllActions): {
630630

631631
"nbconvert latex pdf": {
632632
i: "tex",
633-
m: "PDF via LaTeX (.pdf)",
633+
m: "PDF via LaTeX and nbconvert (minimal image support) (.pdf)",
634634
f: () => actions.jupyter_actions?.show_nbconvert_dialog("pdf"),
635635
r: true,
636636
},

0 commit comments

Comments
 (0)