-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Replace <SelectIDE />
with <SelectIDEComponent />
#16847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b90fff3
Replace `<SelectIDE />` with `<SelectIDEComponent />`
filiptronicek 189af1c
The latest checkbox
filiptronicek 0b71102
Don't show stable IDEs when latest is selected
filiptronicek 93745c1
Limit width
filiptronicek 05b945a
Enlarge
filiptronicek 7c232aa
Remove `<SelectIDE />`
filiptronicek 94741e0
Back, back to school again
filiptronicek 83c805d
Dead code
filiptronicek f7035e6
Fix width
filiptronicek 2d63a05
Use `width` instead of `max-width`
filiptronicek c10b8a0
Remove unused import
filiptronicek 3ba2dad
Show JB beta notice
filiptronicek 3ede620
Add a margin to the selector
filiptronicek 381770b
Remove custom modal width
filiptronicek 6d19d41
Finish off the age-old todo :)
filiptronicek 203e3bd
Remove `<SelectIDEModal />`
filiptronicek 4e5b0fe
retest
easyCZ b5668a6
Remove unused code
filiptronicek 896ff38
use `useUpdateCurrentUserMutation`
filiptronicek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,222 +1,123 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* 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 { IDEOption, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import InfoBox from "../components/InfoBox"; | ||
import SelectableCardSolid from "../components/SelectableCardSolid"; | ||
import Tooltip from "../components/Tooltip"; | ||
import { getGitpodService } from "../service/service"; | ||
import { UserContext } from "../user-context"; | ||
import CheckBox from "../components/CheckBox"; | ||
import { User } from "@gitpod/gitpod-protocol"; | ||
import SelectIDEComponent from "../components/SelectIDEComponent"; | ||
import PillLabel from "../components/PillLabel"; | ||
import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutation"; | ||
|
||
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences"; | ||
interface SelectIDEProps { | ||
updateUserContext?: boolean; | ||
location: IDEChangedTrackLocation; | ||
} | ||
|
||
export const updateUserIDEInfo = async ( | ||
user: User, | ||
selectedIde: string, | ||
useLatestVersion: boolean, | ||
location: IDEChangedTrackLocation, | ||
) => { | ||
const additionalData = user?.additionalData ?? {}; | ||
const settings = additionalData.ideSettings ?? {}; | ||
settings.settingVersion = "2.0"; | ||
settings.defaultIde = selectedIde; | ||
settings.useLatestVersion = useLatestVersion; | ||
additionalData.ideSettings = settings; | ||
getGitpodService() | ||
.server.trackEvent({ | ||
event: "ide_configuration_changed", | ||
properties: { | ||
...settings, | ||
location, | ||
}, | ||
}) | ||
.then() | ||
.catch(console.error); | ||
return getGitpodService().server.updateLoggedInUser({ additionalData }); | ||
}; | ||
|
||
export default function SelectIDE(props: SelectIDEProps) { | ||
const { user, setUser } = useContext(UserContext); | ||
const updateUser = useUpdateCurrentUserMutation(); | ||
|
||
// Only exec once when we access this component | ||
useEffect(() => { | ||
user && User.migrationIDESettings(user); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const actualUpdateUserIDEInfo = async (user: User, selectedIde: string, useLatestVersion: boolean) => { | ||
const newUserData = await updateUserIDEInfo(user, selectedIde, useLatestVersion, props.location); | ||
const [defaultIde, setDefaultIde] = useState<string>(user?.additionalData?.ideSettings?.defaultIde || "code"); | ||
const [useLatestVersion, setUseLatestVersion] = useState<boolean>( | ||
user?.additionalData?.ideSettings?.useLatestVersion ?? false, | ||
); | ||
|
||
const actualUpdateUserIDEInfo = async (selectedIde: string, useLatestVersion: boolean) => { | ||
const additionalData = user?.additionalData ?? {}; | ||
const settings = additionalData.ideSettings ?? {}; | ||
settings.settingVersion = "2.0"; | ||
settings.defaultIde = selectedIde; | ||
settings.useLatestVersion = useLatestVersion; | ||
additionalData.ideSettings = settings; | ||
|
||
const newUserData = await updateUser.mutateAsync({ additionalData }); | ||
props.updateUserContext && setUser({ ...newUserData }); | ||
}; | ||
|
||
const [defaultIde, setDefaultIde] = useState<string>(user?.additionalData?.ideSettings?.defaultIde || "code"); | ||
const actuallySetDefaultIde = async (value: string) => { | ||
await actualUpdateUserIDEInfo(user!, value, useLatestVersion); | ||
await actualUpdateUserIDEInfo(value, useLatestVersion); | ||
setDefaultIde(value); | ||
}; | ||
|
||
const [useLatestVersion, setUseLatestVersion] = useState<boolean>( | ||
user?.additionalData?.ideSettings?.useLatestVersion ?? false, | ||
); | ||
const actuallySetUseLatestVersion = async (value: boolean) => { | ||
await actualUpdateUserIDEInfo(user!, defaultIde, value); | ||
await actualUpdateUserIDEInfo(defaultIde, value); | ||
setUseLatestVersion(value); | ||
}; | ||
|
||
const [ideOptions, setIdeOptions] = useState<IDEOptions | undefined>(undefined); | ||
useEffect(() => { | ||
(async () => { | ||
setIdeOptions(await getGitpodService().server.getIDEOptions()); | ||
})(); | ||
}, []); | ||
|
||
const allIdeOptions = ideOptions && orderedIdeOptions(ideOptions); | ||
//todo(ft): find a better way to group IDEs by vendor | ||
const shouldShowJetbrainsNotice = !["code", "code-desktop"].includes(defaultIde); // a really hacky way to get just JetBrains IDEs | ||
|
||
return ( | ||
<> | ||
{ideOptions && ( | ||
<> | ||
{allIdeOptions && ( | ||
<> | ||
<div className={`my-4 gap-3 flex flex-wrap max-w-3xl`}> | ||
{allIdeOptions.map(([id, option]) => { | ||
const selected = defaultIde === id; | ||
const version = useLatestVersion ? option.latestImageVersion : option.imageVersion; | ||
const onSelect = () => actuallySetDefaultIde(id); | ||
return renderIdeOption(option, selected, version, onSelect); | ||
})} | ||
</div> | ||
{ideOptions.options[defaultIde]?.notes && ( | ||
<InfoBox className="my-5 max-w-2xl"> | ||
<ul> | ||
{ideOptions.options[defaultIde].notes?.map((x, idx) => ( | ||
<li className={idx > 0 ? "mt-2" : ""}>{x}</li> | ||
))} | ||
</ul> | ||
</InfoBox> | ||
)} | ||
|
||
<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> | ||
</> | ||
)} | ||
<CheckBox | ||
title="Latest Release (Unstable)" | ||
desc={ | ||
<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={(e) => actuallySetUseLatestVersion(e.target.checked)} | ||
/> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
function orderedIdeOptions(ideOptions: IDEOptions) { | ||
// TODO: Maybe convert orderKey to number before sort? | ||
return Object.entries(ideOptions.options) | ||
.filter(([_, x]) => !x.hidden) | ||
.sort((a, b) => { | ||
const keyA = a[1].orderKey || a[0]; | ||
const keyB = b[1].orderKey || b[0]; | ||
return keyA.localeCompare(keyB); | ||
}); | ||
} | ||
|
||
function renderIdeOption( | ||
option: IDEOption, | ||
selected: boolean, | ||
version: IDEOption["imageVersion"], | ||
onSelect: () => void, | ||
): JSX.Element { | ||
const shouldShowOptionType = option.type !== "desktop" || option.title === "VS Code"; // Force show of "Desktop" in the list for VS Code Desktop | ||
const card = ( | ||
<SelectableCardSolid className="w-36 h-44" title={option.title} selected={selected} onClick={onSelect}> | ||
{version ? ( | ||
<span | ||
className={`font-normal font-mono text-xs ${ | ||
selected | ||
? "text-gray-100 dark:text-gray-600" | ||
: "text-gray-400 contrast-more:text-gray-600 dark:text-gray-500" | ||
} pl-1 self-start`} | ||
title="The IDE's current version on Gitpod" | ||
> | ||
{version} | ||
</span> | ||
) : ( | ||
<span | ||
style={{ | ||
minHeight: "1rem", | ||
<div className="w-112 my-4"> | ||
<SelectIDEComponent | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onSelectionChange={async (ide) => { | ||
await actuallySetDefaultIde(ide); | ||
}} | ||
></span> | ||
)} | ||
<div className="flex justify-center mt-3 mb-2"> | ||
<img className="w-16 filter-grayscale self-center" src={option.logo} alt="logo" /> | ||
selectedIdeOption={defaultIde} | ||
useLatest={useLatestVersion} | ||
/> | ||
</div> | ||
{shouldShowOptionType ? ( | ||
<PillLabel type="warn" className="place-self-start py-0.5 my-2 flex"> | ||
<span className="text-xs capitalize">{option.type}</span> | ||
</PillLabel> | ||
) : ( | ||
option.label && ( | ||
<PillLabel type="neutral" className="place-self-start py-0.5 my-2 flex"> | ||
<span className="text-xs normal-case font-medium">{option.label}</span> | ||
|
||
{shouldShowJetbrainsNotice && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: ✨ |
||
<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> | ||
)} | ||
</SelectableCardSolid> | ||
); | ||
|
||
if (option.tooltip) { | ||
return <Tooltip content={option.tooltip}>{card}</Tooltip>; | ||
} | ||
return card; | ||
<CheckBox | ||
title="Latest Release (Unstable)" | ||
desc={ | ||
<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={(e) => actuallySetUseLatestVersion(e.target.checked)} | ||
/> | ||
</> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Flawless!