Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/user-settings/SelectIDE.tsx
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { ReactNode, useCallback, useContext, useState } from "react";
8
import { UserContext } from "../user-context";
9
import { CheckboxInputField } from "../components/forms/CheckboxInputField";
10
import SelectIDEComponent, { isJetbrains } from "../components/SelectIDEComponent";
11
import PillLabel from "../components/PillLabel";
12
import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutation";
13
import { converter } from "../service/public-api";
14
import { isOrganizationOwned } from "@gitpod/public-api-common/lib/user-utils";
15
import Alert from "../components/Alert";
16
import { useFeatureFlag } from "../data/featureflag-query";
17
import { IDESettingsVersion } from "@gitpod/gitpod-protocol/lib/ide-protocol";
18
19
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
20
interface SelectIDEProps {
21
location: IDEChangedTrackLocation;
22
}
23
24
export default function SelectIDE(props: SelectIDEProps) {
25
const { user, setUser } = useContext(UserContext);
26
const updateUser = useUpdateCurrentUserMutation();
27
28
const [defaultIde, setDefaultIde] = useState<string>(user?.editorSettings?.name || "code");
29
const [useLatestVersion, setUseLatestVersion] = useState<boolean>(user?.editorSettings?.version === "latest");
30
const [preferToolbox, setPreferToolbox] = useState<boolean>(user?.editorSettings?.preferToolbox || false);
31
const [ideWarning, setIdeWarning] = useState<ReactNode | undefined>(undefined);
32
const enableExperimentalJBTB = useFeatureFlag("enable_experimental_jbtb");
33
34
const isOrgOwnedUser = user && isOrganizationOwned(user);
35
36
const actualUpdateUserIDEInfo = useCallback(
37
async (selectedIde: string, useLatestVersion: boolean, preferToolbox: boolean) => {
38
// update stored autostart options to match useLatestVersion value set here
39
const workspaceAutostartOptions = user?.workspaceAutostartOptions?.map((o) => {
40
const option = converter.fromWorkspaceAutostartOption(o);
41
42
if (option.ideSettings) {
43
option.ideSettings.useLatestVersion = useLatestVersion;
44
option.ideSettings.preferToolbox = preferToolbox;
45
}
46
47
return option;
48
});
49
50
const updatedUser = await updateUser.mutateAsync({
51
additionalData: {
52
workspaceAutostartOptions,
53
ideSettings: {
54
settingVersion: IDESettingsVersion,
55
defaultIde: selectedIde,
56
useLatestVersion: useLatestVersion,
57
preferToolbox: preferToolbox,
58
},
59
},
60
});
61
setUser(updatedUser);
62
},
63
[setUser, updateUser, user?.workspaceAutostartOptions],
64
);
65
66
const actuallySetDefaultIde = useCallback(
67
async (value: string) => {
68
await actualUpdateUserIDEInfo(value, useLatestVersion, preferToolbox);
69
setDefaultIde(value);
70
},
71
[actualUpdateUserIDEInfo, useLatestVersion, preferToolbox],
72
);
73
74
const actuallySetUseLatestVersion = useCallback(
75
async (value: boolean) => {
76
await actualUpdateUserIDEInfo(defaultIde, value, preferToolbox);
77
setUseLatestVersion(value);
78
},
79
[actualUpdateUserIDEInfo, defaultIde, preferToolbox],
80
);
81
82
const actuallySetPreferToolbox = useCallback(
83
async (value: boolean) => {
84
await actualUpdateUserIDEInfo(defaultIde, useLatestVersion, value);
85
setPreferToolbox(value);
86
},
87
[actualUpdateUserIDEInfo, defaultIde, useLatestVersion],
88
);
89
90
const shouldShowJetbrainsNotice = isJetbrains(defaultIde);
91
92
return (
93
<>
94
{ideWarning && (
95
<Alert type="warning" className="my-2 max-w-md">
96
<span className="text-sm">{ideWarning}</span>
97
</Alert>
98
)}
99
100
<div className="w-112 max-w-full my-4">
101
<SelectIDEComponent
102
onSelectionChange={actuallySetDefaultIde}
103
selectedIdeOption={defaultIde}
104
useLatest={useLatestVersion}
105
setWarning={setIdeWarning}
106
ignoreRestrictionScopes={isOrgOwnedUser ? ["configuration"] : ["configuration", "organization"]}
107
hideVersions
108
/>
109
</div>
110
111
{shouldShowJetbrainsNotice && (
112
<p className="text-left w-full text-gray-400 dark:text-gray-500">
113
<strong>JetBrains </strong> integration is currently in{" "}
114
<PillLabel type="warn" className="font-semibold mt-2 ml-0 py-0.5 px-1 self-center">
115
<a href="https://www.gitpod.io/docs/references/gitpod-releases">
116
<span className="text-xs">Beta</span>
117
</a>
118
</PillLabel>
119
&nbsp;&middot;&nbsp;
120
<a
121
href="https://github.com/gitpod-io/gitpod/issues/6576"
122
target="_blank"
123
rel="noopener noreferrer"
124
className="gp-link"
125
>
126
Send feedback
127
</a>
128
</p>
129
)}
130
131
<CheckboxInputField
132
label="Latest Release (Unstable)"
133
hint={
134
<span>
135
Use the latest version for each editor.{" "}
136
<a
137
className="gp-link"
138
target="_blank"
139
href="https://code.visualstudio.com/blogs/2016/02/01/introducing_insiders_build"
140
rel="noreferrer"
141
>
142
Insiders
143
</a>{" "}
144
for VS Code,{" "}
145
<a
146
className="gp-link"
147
target="_blank"
148
href="https://www.jetbrains.com/resources/eap/"
149
rel="noreferrer"
150
>
151
EAP
152
</a>{" "}
153
for JetBrains IDEs.
154
</span>
155
}
156
checked={useLatestVersion}
157
onChange={(checked) => actuallySetUseLatestVersion(checked)}
158
/>
159
160
{enableExperimentalJBTB && (
161
<CheckboxInputField
162
label={
163
<span className="flex items-center gap-2">
164
Launch in JetBrains Toolbox{" "}
165
<PillLabel type="warn">
166
<a href="https://www.gitpod.io/docs/references/gitpod-releases">
167
<span className="text-xs">BETA</span>
168
</a>
169
</PillLabel>
170
</span>
171
}
172
hint={<span>Launch JetBrains IDEs in the JetBrains Toolbox.</span>}
173
checked={preferToolbox}
174
onChange={(checked) => actuallySetPreferToolbox(checked)}
175
/>
176
)}
177
</>
178
);
179
}
180
181