Skip to content

Commit e58b098

Browse files
committed
fix #7740 - markdown load button
1 parent f771318 commit e58b098

File tree

5 files changed

+93
-36
lines changed

5 files changed

+93
-36
lines changed

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

Lines changed: 21 additions & 3 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")) {

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
);

0 commit comments

Comments
 (0)