Skip to content

User Pref Editor change cleanup #17025

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 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/dashboard/src/user-settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Preferences() {
Learn more
</a>
</Subheading>
<SelectIDE updateUserContext={false} location="preferences" />
<SelectIDE location="preferences" />

<ThemeSelector className="mt-12" />

Expand Down
59 changes: 36 additions & 23 deletions components/dashboard/src/user-settings/SelectIDE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useContext, useEffect, useState } from "react";
import { useCallback, useContext, useEffect, useState } from "react";
import { UserContext } from "../user-context";
import CheckBox from "../components/CheckBox";
import { User } from "@gitpod/gitpod-protocol";
Expand All @@ -14,7 +14,6 @@ import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutati

export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
interface SelectIDEProps {
updateUserContext?: boolean;
location: IDEChangedTrackLocation;
}

Expand All @@ -33,27 +32,43 @@ export default function SelectIDE(props: SelectIDEProps) {
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 actualUpdateUserIDEInfo = useCallback(
async (selectedIde: string, useLatestVersion: boolean) => {
const additionalData = user?.additionalData || {};
const ideSettings = additionalData.ideSettings || {};

const newUserData = await updateUser.mutateAsync({ additionalData });
props.updateUserContext && setUser({ ...newUserData });
};
const updates = {
additionalData: {
...additionalData,
ideSettings: {
...ideSettings,
settingVersion: "2.0",
defaultIde: selectedIde,
useLatestVersion: useLatestVersion,
},
},
};
const newUserData = await updateUser.mutateAsync(updates);
setUser(newUserData);
},
[setUser, updateUser, user?.additionalData],
);

const actuallySetDefaultIde = async (value: string) => {
await actualUpdateUserIDEInfo(value, useLatestVersion);
setDefaultIde(value);
};
const actuallySetDefaultIde = useCallback(
async (value: string) => {
await actualUpdateUserIDEInfo(value, useLatestVersion);
setDefaultIde(value);
},
[actualUpdateUserIDEInfo, useLatestVersion],
);

const actuallySetUseLatestVersion = async (value: boolean) => {
await actualUpdateUserIDEInfo(defaultIde, value);
setUseLatestVersion(value);
};
const actuallySetUseLatestVersion = useCallback(
async (value: boolean) => {
await actualUpdateUserIDEInfo(defaultIde, value);
setUseLatestVersion(value);
},
[actualUpdateUserIDEInfo, defaultIde],
);

//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
Expand All @@ -62,9 +77,7 @@ export default function SelectIDE(props: SelectIDEProps) {
<>
<div className="w-112 my-4">
<SelectIDEComponent
onSelectionChange={async (ide) => {
await actuallySetDefaultIde(ide);
}}
onSelectionChange={actuallySetDefaultIde}
selectedIdeOption={defaultIde}
useLatest={useLatestVersion}
/>
Expand Down