-
Notifications
You must be signed in to change notification settings - Fork 82
/
CliInstallModal.tsx
185 lines (169 loc) · 5.01 KB
/
CliInstallModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { Trans } from "@lingui/macro";
import { i18nMark } from "@lingui/react";
import classNames from "classnames";
import { Modal } from "reactjs-components";
import * as React from "react";
import { Icon } from "@dcos/ui-kit";
import { SystemIcons } from "@dcos/ui-kit/dist/packages/icons/dist/system-icons-enum";
import { iconSizeXs } from "@dcos/ui-kit/dist/packages/design-tokens/build/js/designTokens";
import ClickToSelect from "../ClickToSelect";
import MetadataStore from "../../stores/MetadataStore";
import ModalHeading from "../modals/ModalHeading";
const osTypes = {
Windows: "windows",
"OS X": "darwin",
Linux: "linux",
};
class CliInstallModal extends React.Component<
{
title: string;
showFooter: boolean;
footer?: React.ReactNode;
onClose: () => void;
open?: boolean;
},
{ selectedOS: string }
> {
constructor(props) {
super(props);
const platform = navigator.userAgent || "linux";
this.state = {
selectedOS: platform.match("Win")
? "Windows"
: platform.match("Mac")
? "OS X"
: "Linux",
};
}
onClose = () => {
this.props.onClose();
};
getCliInstructions() {
const hostname = window.location.hostname;
const protocol = window.location.protocol.replace(/[^\w]/g, "");
let port = "";
if (window.location.port) {
port = ":" + window.location.port;
}
const clusterUrl = `${protocol}://${hostname}${port}`;
const { selectedOS } = this.state;
// Starting from DC/OS >=2.0, users can stick to the "latest" CLI.
// However on DC/OS 1.x we must use the correct CLI for the given version of DC/OS.
const dcosVersion = MetadataStore.parsedVersion;
const cliVersion =
dcosVersion.substring(0, 2) === "1." ? `dcos-${dcosVersion}` : "latest";
const downloadUrl = `https://downloads.dcos.io/binaries/cli/${osTypes[selectedOS]}/x86-64/${cliVersion}/dcos`;
if (selectedOS === "Windows") {
return this.getWindowsInstallInstruction(clusterUrl, downloadUrl);
}
const instructions = [
`curl ${downloadUrl} -o dcos`,
`chmod +x ./dcos`,
`sudo mv dcos /usr/local/bin`,
`dcos cluster setup ${clusterUrl}`,
`dcos`,
].join(" && \n");
return (
<div>
<Trans render="p" className="short-bottom">
Copy and paste the code snippet into the terminal:
</Trans>
<div className="flush-top snippet-wrapper">
<ClickToSelect>
<pre className="prettyprint flush-bottom">{instructions}</pre>
</ClickToSelect>
</div>
</div>
);
}
getWindowsInstallInstruction(clusterUrl: string, downloadUrl: string) {
const steps = [
`cd path/to/download/directory`,
`dcos cluster setup ${clusterUrl}`,
`dcos`,
].map((instruction, index) => {
const helpText =
index === 0 ? i18nMark("In Command Prompt, enter") : i18nMark("Enter");
return (
<li key={index}>
<Trans render="p" className="short-bottom" id={helpText} />
<div className="flush-top snippet-wrapper">
<ClickToSelect>
<pre className="prettyprint flush-bottom prettyprinted">
{instruction}
</pre>
</ClickToSelect>
</div>
</li>
);
});
return (
<ol>
<Trans render="li">
Download and install:{" "}
<a href={downloadUrl + ".exe"}>
<Icon
shape={SystemIcons.Download}
size={iconSizeXs}
color="currentColor"
/>
Download dcos.exe
</a>
.
</Trans>
{steps}
</ol>
);
}
getOSButtons() {
const onClick = () =>
this.setState({ selectedOS: name as keyof typeof osTypes });
return Object.keys(osTypes).map((name) => (
<button
key={name}
className={classNames("button button-outline", {
active: name === this.state.selectedOS,
})}
onClick={onClick}
>
{name}
</button>
));
}
render() {
const { footer, open, showFooter, title } = this.props;
const header = (
<ModalHeading>
<Trans id={title} render="span" />
</ModalHeading>
);
return (
<Modal
header={header}
footer={footer}
modalClass="modal"
onClose={this.onClose}
open={open}
showHeader={true}
showFooter={showFooter}
>
<div className="install-cli-modal-content">
<Trans render="p">
Choose your operating system and follow the instructions. For any
issues or questions, please refer to our{" "}
<a
href={MetadataStore.buildDocsURI("/cli/install")}
target="_blank"
>
documentation
</a>
.
</Trans>
<div className="button-group">{this.getOSButtons()}</div>
{this.getCliInstructions()}
</div>
</Modal>
);
}
}
export default CliInstallModal;