Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/history-viewer.tsx
1691 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
History viewer for Tasks notebooks --- very similar to same file in jupyter/ directory. Refactor!
8
*/
9
10
import { Checkbox } from "antd";
11
import { fromJS, Map } from "immutable";
12
import TaskList from "./list";
13
import { useState } from "../../app-framework";
14
import { cmp } from "@cocalc/util/misc";
15
import { Tasks } from "./types";
16
17
const SHOW_DONE_STYLE = {
18
fontSize: "12pt",
19
color: "#666",
20
padding: "5px 15px",
21
borderBottom: "1px solid lightgrey",
22
} as const;
23
24
export function TasksHistoryViewer({ doc, project_id, path, font_size }) {
25
const [show_done, set_show_done] = useState(false);
26
27
function render_task_list(doc) {
28
let tasks: Tasks = Map();
29
const v: [number | undefined, string][] = [];
30
doc.get().forEach((task) => {
31
const task_id = task.get("task_id");
32
tasks = tasks.set(task_id, task);
33
if ((show_done || !task.get("done")) && !task.get("deleted")) {
34
v.push([task.get("last_edited"), task_id]);
35
}
36
});
37
v.sort((a, b) => -cmp(a[0], b[0]));
38
const visible = fromJS(v.map((x) => x[1]));
39
40
return (
41
<TaskList
42
path={path}
43
project_id={project_id}
44
tasks={tasks}
45
visible={visible}
46
read_only={true}
47
font_size={font_size}
48
/>
49
);
50
}
51
52
return (
53
<div
54
style={{
55
display: "flex",
56
flexDirection: "column",
57
height: "100%",
58
overflowY: "hidden",
59
}}
60
>
61
<div style={SHOW_DONE_STYLE}>
62
<Checkbox
63
checked={show_done}
64
onChange={() => set_show_done(!show_done)}
65
>
66
Show finished tasks
67
</Checkbox>
68
</div>
69
{doc == null ? <span>Unknown version</span> : render_task_list(doc)}
70
</div>
71
);
72
}
73
74