CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/custom-software/reset-bar.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Button as AntdButton, Card } from "antd";
7
import React from "react";
8
import { FormattedMessage, useIntl } from "react-intl";
9
10
import { A, Icon } from "@cocalc/frontend/components";
11
import { labels } from "@cocalc/frontend/i18n";
12
import { ProjectMap } from "@cocalc/frontend/todo-types";
13
import { COLORS, SITE_NAME } from "@cocalc/util/theme";
14
15
import { Available as AvailableFeatures } from "../project_configuration";
16
import { ComputeImages } from "./init";
17
import { props2img, RESET_ICON } from "./util";
18
19
const doc_snap = "https://doc.cocalc.com/project-files.html#snapshots";
20
const doc_tt = "https://doc.cocalc.com/time-travel.html";
21
22
const title_style: React.CSSProperties = {
23
fontWeight: "bold" as "bold",
24
fontSize: "15pt",
25
} as const;
26
27
const button_bar_style: React.CSSProperties = {
28
whiteSpace: "nowrap" as "nowrap",
29
} as const;
30
31
const info_style: React.CSSProperties = {
32
paddingBottom: "20px",
33
} as const;
34
35
interface Props {
36
project_id: string;
37
images: ComputeImages;
38
project_map?: ProjectMap;
39
actions: any;
40
available_features?: AvailableFeatures;
41
site_name?: string;
42
}
43
44
export const CustomSoftwareReset: React.FC<Props> = (props: Props) => {
45
const { actions, site_name } = props;
46
47
const intl = useIntl();
48
49
function reset() {
50
actions.custom_software_reset();
51
}
52
53
function cancel() {
54
actions.toggle_custom_software_reset(false);
55
}
56
57
function title() {
58
return (
59
<div style={title_style}>
60
<Icon name={RESET_ICON} /> Reset {img.get("display", "")}
61
</div>
62
);
63
}
64
65
const img = props2img(props);
66
if (img == null) return null;
67
const NAME = site_name || SITE_NAME;
68
69
return (
70
<Card style={{ background: COLORS.GRAY_LLL }} title={title()}>
71
<div style={info_style}>
72
<FormattedMessage
73
id="custom-software.reset-bar.info"
74
defaultMessage={`
75
<p>
76
Clicking on "Reset" copies all accompanying files of this custom
77
software environment into your home directory. This was done once when
78
this project was created and you can repeat this action right now. If
79
these accompanying files hosted on {NAME} did update in the meantime,
80
you'll recieve the newer versions.
81
</p>
82
<p>
83
Note, that this will overwrite any changes you did to these
84
accompanying files, but does not modify or delete any other files.
85
However, nothing is lost: you can still access the previous version
86
via <A1>Snapshot Backups</A1> or <A2>TimeTravel</A2>.
87
</p>
88
<p>This action will also restart your project!</p>`}
89
values={{
90
NAME,
91
A1: (c) => <A href={doc_snap}>{c}</A>,
92
A2: (c) => <A href={doc_tt}>{c}</A>,
93
}}
94
/>
95
</div>
96
<div style={button_bar_style}>
97
<AntdButton onClick={reset} danger type="primary">
98
<Icon name={RESET_ICON} />{" "}
99
{intl.formatMessage({
100
id: "custom-software.reset-bar.reset-and-restart",
101
defaultMessage: "Reset and Restart",
102
})}
103
</AntdButton>{" "}
104
<AntdButton onClick={cancel}>
105
<Icon name={"times-circle"} /> {intl.formatMessage(labels.cancel)}
106
</AntdButton>
107
</div>
108
</Card>
109
);
110
};
111
112