-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathSelectIDE.tsx
179 lines (161 loc) · 7.44 KB
/
SelectIDE.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
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/
import { ReactNode, useCallback, useContext, useState } from "react";
import { UserContext } from "../user-context";
import { CheckboxInputField } from "../components/forms/CheckboxInputField";
import SelectIDEComponent, { isJetbrains } from "../components/SelectIDEComponent";
import PillLabel from "../components/PillLabel";
import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutation";
import { converter } from "../service/public-api";
import { isOrganizationOwned } from "@gitpod/public-api-common/lib/user-utils";
import Alert from "../components/Alert";
import { useFeatureFlag } from "../data/featureflag-query";
import { IDESettingsVersion } from "@gitpod/gitpod-protocol/lib/ide-protocol";
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
interface SelectIDEProps {
location: IDEChangedTrackLocation;
}
export default function SelectIDE(props: SelectIDEProps) {
const { user, setUser } = useContext(UserContext);
const updateUser = useUpdateCurrentUserMutation();
const [defaultIde, setDefaultIde] = useState<string>(user?.editorSettings?.name || "code");
const [useLatestVersion, setUseLatestVersion] = useState<boolean>(user?.editorSettings?.version === "latest");
const [preferToolbox, setPreferToolbox] = useState<boolean>(user?.editorSettings?.preferToolbox || false);
const [ideWarning, setIdeWarning] = useState<ReactNode | undefined>(undefined);
const enableExperimentalJBTB = useFeatureFlag("enable_experimental_jbtb");
const isOrgOwnedUser = user && isOrganizationOwned(user);
const actualUpdateUserIDEInfo = useCallback(
async (selectedIde: string, useLatestVersion: boolean, preferToolbox: boolean) => {
// update stored autostart options to match useLatestVersion value set here
const workspaceAutostartOptions = user?.workspaceAutostartOptions?.map((o) => {
const option = converter.fromWorkspaceAutostartOption(o);
if (option.ideSettings) {
option.ideSettings.useLatestVersion = useLatestVersion;
option.ideSettings.preferToolbox = preferToolbox;
}
return option;
});
const updatedUser = await updateUser.mutateAsync({
additionalData: {
workspaceAutostartOptions,
ideSettings: {
settingVersion: IDESettingsVersion,
defaultIde: selectedIde,
useLatestVersion: useLatestVersion,
preferToolbox: preferToolbox,
},
},
});
setUser(updatedUser);
},
[setUser, updateUser, user?.workspaceAutostartOptions],
);
const actuallySetDefaultIde = useCallback(
async (value: string) => {
await actualUpdateUserIDEInfo(value, useLatestVersion, preferToolbox);
setDefaultIde(value);
},
[actualUpdateUserIDEInfo, useLatestVersion, preferToolbox],
);
const actuallySetUseLatestVersion = useCallback(
async (value: boolean) => {
await actualUpdateUserIDEInfo(defaultIde, value, preferToolbox);
setUseLatestVersion(value);
},
[actualUpdateUserIDEInfo, defaultIde, preferToolbox],
);
const actuallySetPreferToolbox = useCallback(
async (value: boolean) => {
await actualUpdateUserIDEInfo(defaultIde, useLatestVersion, value);
setPreferToolbox(value);
},
[actualUpdateUserIDEInfo, defaultIde, useLatestVersion],
);
const shouldShowJetbrainsNotice = isJetbrains(defaultIde);
return (
<>
{ideWarning && (
<Alert type="warning" className="my-2 max-w-md">
<span className="text-sm">{ideWarning}</span>
</Alert>
)}
<div className="w-112 max-w-full my-4">
<SelectIDEComponent
onSelectionChange={actuallySetDefaultIde}
selectedIdeOption={defaultIde}
useLatest={useLatestVersion}
setWarning={setIdeWarning}
ignoreRestrictionScopes={isOrgOwnedUser ? ["configuration"] : ["configuration", "organization"]}
hideVersions
/>
</div>
{shouldShowJetbrainsNotice && (
<p className="text-left w-full text-gray-400 dark:text-gray-500">
<strong>JetBrains </strong> integration is currently in{" "}
<PillLabel type="warn" className="font-semibold mt-2 ml-0 py-0.5 px-1 self-center">
<a href="https://www.gitpod.io/docs/references/gitpod-releases">
<span className="text-xs">Beta</span>
</a>
</PillLabel>
·
<a
href="https://github.com/gitpod-io/gitpod/issues/6576"
target="_blank"
rel="noopener noreferrer"
className="gp-link"
>
Send feedback
</a>
</p>
)}
<CheckboxInputField
label="Latest Release (Unstable)"
hint={
<span>
Use the latest version for each editor.{" "}
<a
className="gp-link"
target="_blank"
href="https://code.visualstudio.com/blogs/2016/02/01/introducing_insiders_build"
rel="noreferrer"
>
Insiders
</a>{" "}
for VS Code,{" "}
<a
className="gp-link"
target="_blank"
href="https://www.jetbrains.com/resources/eap/"
rel="noreferrer"
>
EAP
</a>{" "}
for JetBrains IDEs.
</span>
}
checked={useLatestVersion}
onChange={(checked) => actuallySetUseLatestVersion(checked)}
/>
{enableExperimentalJBTB && (
<CheckboxInputField
label={
<span className="flex items-center gap-2">
Launch in JetBrains Toolbox{" "}
<PillLabel type="warn">
<a href="https://www.gitpod.io/docs/references/gitpod-releases">
<span className="text-xs">BETA</span>
</a>
</PillLabel>
</span>
}
hint={<span>Launch JetBrains IDEs in the JetBrains Toolbox.</span>}
checked={preferToolbox}
onChange={(checked) => actuallySetPreferToolbox(checked)}
/>
)}
</>
);
}