Skip to content

Commit

Permalink
fixing old var refs
Browse files Browse the repository at this point in the history
  • Loading branch information
malhotra5 committed Mar 3, 2025
1 parent 00c199d commit f1f7798
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 63 deletions.
40 changes: 20 additions & 20 deletions frontend/__tests__/routes/settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("Settings Screen", () => {
renderSettingsScreen();

await waitFor(() => {
screen.getByTestId("github-token-input");
screen.getByTestId("token-input");
screen.getByTestId("github-token-help-anchor");
screen.getByTestId("language-input");
screen.getByTestId("enable-analytics-switch");
Expand All @@ -82,13 +82,13 @@ describe("Settings Screen", () => {
it.skip("should render an indicator if the GitHub token is not set", async () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: false,
token_is_set: false,
});

renderSettingsScreen();

await waitFor(() => {
const input = screen.getByTestId("github-token-input");
const input = screen.getByTestId("token-input");
const inputParent = input.parentElement;

if (inputParent) {
Expand All @@ -103,26 +103,26 @@ describe("Settings Screen", () => {
it("should set asterik placeholder if the GitHub token is set", async () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: true,
token_is_set: true,
});

renderSettingsScreen();

await waitFor(() => {
const input = screen.getByTestId("github-token-input");
const input = screen.getByTestId("token-input");
expect(input).toHaveProperty("placeholder", "**********");
});
});

it("should render an indicator if the GitHub token is set", async () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: true,
token_is_set: true,
});

renderSettingsScreen();

const input = await screen.findByTestId("github-token-input");
const input = await screen.findByTestId("token-input");
const inputParent = input.parentElement;

if (inputParent) {
Expand All @@ -136,7 +136,7 @@ describe("Settings Screen", () => {
it("should render a disabled 'Disconnect from GitHub' button if the GitHub token is not set", async () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: false,
token_is_set: false,
});

renderSettingsScreen();
Expand All @@ -149,7 +149,7 @@ describe("Settings Screen", () => {
it("should render an enabled 'Disconnect from GitHub' button if the GitHub token is set", async () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: true,
token_is_set: true,
});

renderSettingsScreen();
Expand All @@ -158,7 +158,7 @@ describe("Settings Screen", () => {
expect(button).toBeEnabled();

// input should still be rendered
const input = await screen.findByTestId("github-token-input");
const input = await screen.findByTestId("token-input");
expect(input).toBeInTheDocument();
});

Expand All @@ -167,7 +167,7 @@ describe("Settings Screen", () => {

getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: true,
token_is_set: true,
});

renderSettingsScreen();
Expand Down Expand Up @@ -213,7 +213,7 @@ describe("Settings Screen", () => {
renderSettingsScreen();

await waitFor(() => {
const input = screen.queryByTestId("github-token-input");
const input = screen.queryByTestId("token-input");
const helpAnchor = screen.queryByTestId("github-token-help-anchor");

expect(input).not.toBeInTheDocument();
Expand All @@ -225,7 +225,7 @@ describe("Settings Screen", () => {
const user = userEvent.setup();
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
github_token_is_set: false,
token_is_set: false,
llm_model: "anthropic/claude-3-5-sonnet-20241022",
});
saveSettingsSpy.mockRejectedValueOnce(new Error("Invalid GitHub token"));
Expand All @@ -238,7 +238,7 @@ describe("Settings Screen", () => {
expect(llmProviderInput).toHaveValue("Anthropic");
expect(llmModelInput).toHaveValue("claude-3-5-sonnet-20241022");

const input = await screen.findByTestId("github-token-input");
const input = await screen.findByTestId("token-input");
await user.type(input, "invalid-token");

const saveButton = screen.getByText("Save Changes");
Expand Down Expand Up @@ -646,7 +646,7 @@ describe("Settings Screen", () => {
getSettingsSpy.mockResolvedValue({
...MOCK_DEFAULT_USER_SETTINGS,
language: "no",
github_token_is_set: true,
token_is_set: true,
user_consents_to_analytics: true,
llm_base_url: "https://test.com",
llm_model: "anthropic/claude-3-5-sonnet-20241022",
Expand Down Expand Up @@ -699,7 +699,7 @@ describe("Settings Screen", () => {
expect(saveSettingsSpy).toHaveBeenCalledWith(
expect.objectContaining({
llm_api_key: "", // empty because it's not set previously
github_token: undefined,
token: undefined,
language: "no",
}),
);
Expand Down Expand Up @@ -736,7 +736,7 @@ describe("Settings Screen", () => {

expect(saveSettingsSpy).toHaveBeenCalledWith(
expect.objectContaining({
github_token: undefined,
token: undefined,
llm_api_key: "", // empty because it's not set previously
llm_model: "openai/gpt-4o",
}),
Expand Down Expand Up @@ -773,13 +773,13 @@ describe("Settings Screen", () => {
const mockCopy: Partial<PostApiSettings> = {
...MOCK_DEFAULT_USER_SETTINGS,
};
delete mockCopy.github_token_is_set;
delete mockCopy.unset_github_token;
delete mockCopy.token_is_set;
delete mockCopy.unset_token;
delete mockCopy.user_consents_to_analytics;

expect(saveSettingsSpy).toHaveBeenCalledWith({
...mockCopy,
github_token: undefined, // not set
token: undefined, // not set
llm_api_key: "", // reset as well
});
expect(screen.queryByTestId("reset-modal")).not.toBeInTheDocument();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/features/chat/action-suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ActionSuggestionsProps {
export function ActionSuggestions({
onSuggestionsClick,
}: ActionSuggestionsProps) {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();
const { selectedRepository } = useSelector(
(state: RootState) => state.initialQuery,
);
Expand All @@ -32,7 +32,7 @@ export function ActionSuggestions({
onClose={handleDownloadClose}
isOpen={isDownloading}
/>
{githubTokenIsSet && selectedRepository ? (
{tokenIsSet && selectedRepository ? (
<div className="flex flex-row gap-2 justify-center w-full">
{!hasPullRequest ? (
<>
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/context/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ interface AuthContextProps extends React.PropsWithChildren {
const AuthContext = React.createContext<AuthContextType | undefined>(undefined);

function AuthProvider({ children, initialTokenIsSet }: AuthContextProps) {
const [tokenIsSet, setTokenIsSet] = React.useState(
!!initialTokenIsSet,
);
const [tokenIsSet, setTokenIsSet] = React.useState(!!initialTokenIsSet);

const value = React.useMemo(
() => ({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/mutation/use-logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";

export const useLogout = () => {
const { setGitHubTokenIsSet } = useAuth();
const { setTokenIsSet } = useAuth();
const queryClient = useQueryClient();

return useMutation({
mutationFn: OpenHands.logout,
onSuccess: async () => {
setGitHubTokenIsSet(false);
setTokenIsSet(false);
await queryClient.invalidateQueries();
},
});
Expand Down
1 change: 0 additions & 1 deletion frontend/src/hooks/mutation/use-save-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const saveSettingsMutationFn = async (settings: Partial<PostSettings>) => {
: settings.LLM_API_KEY?.trim() || undefined,
remote_runtime_resource_factor: settings.REMOTE_RUNTIME_RESOURCE_FACTOR,
token: settings.token,
token_type: settings.token_type,
unset_token: settings.unset_token,
enable_default_condenser: settings.ENABLE_DEFAULT_CONDENSER,
enable_sound_notifications: settings.ENABLE_SOUND_NOTIFICATIONS,
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/hooks/query/use-app-installations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { useAuth } from "#/context/auth-context";

export const useAppInstallations = () => {
const { data: config } = useConfig();
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();

return useQuery({
queryKey: ["installations", githubTokenIsSet, config?.GITHUB_CLIENT_ID],
queryKey: ["installations", tokenIsSet, config?.GITHUB_CLIENT_ID],
queryFn: OpenHands.getGitHubUserInstallationIds,
enabled:
githubTokenIsSet &&
!!config?.GITHUB_CLIENT_ID &&
config?.APP_MODE === "saas",
tokenIsSet && !!config?.GITHUB_CLIENT_ID && config?.APP_MODE === "saas",
});
};
6 changes: 3 additions & 3 deletions frontend/src/hooks/query/use-app-repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useConfig } from "./use-config";
import { useAuth } from "#/context/auth-context";

export const useAppRepositories = () => {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();
const { data: config } = useConfig();
const { data: installations } = useAppInstallations();

const repos = useInfiniteQuery({
queryKey: ["repositories", githubTokenIsSet, installations],
queryKey: ["repositories", tokenIsSet, installations],
queryFn: async ({
pageParam,
}: {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const useAppRepositories = () => {
return null;
},
enabled:
githubTokenIsSet &&
tokenIsSet &&
Array.isArray(installations) &&
installations.length > 0 &&
config?.APP_MODE === "saas",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/query/use-is-authed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useConfig } from "./use-config";
import { useAuth } from "#/context/auth-context";

export const useIsAuthed = () => {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();
const { data: config } = useConfig();

const appMode = React.useMemo(() => config?.APP_MODE, [config]);

return useQuery({
queryKey: ["user", "authenticated", githubTokenIsSet, appMode],
queryKey: ["user", "authenticated", tokenIsSet, appMode],
queryFn: () => OpenHands.authenticate(appMode!),
enabled: !!appMode,
staleTime: 1000 * 60 * 5, // 5 minutes
Expand Down
1 change: 0 additions & 1 deletion frontend/src/hooks/query/use-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const getSettingsQueryFn = async () => {
LLM_API_KEY: apiSettings.llm_api_key,
REMOTE_RUNTIME_RESOURCE_FACTOR: apiSettings.remote_runtime_resource_factor,
TOKEN_IS_SET: apiSettings.token_is_set,
TOKEN_TYPE: apiSettings.token_type,
ENABLE_DEFAULT_CONDENSER: apiSettings.enable_default_condenser,
ENABLE_SOUND_NOTIFICATIONS: apiSettings.enable_sound_notifications,
USER_CONSENTS_TO_ANALYTICS: apiSettings.user_consents_to_analytics,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/hooks/query/use-user-repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { useConfig } from "./use-config";
import { useAuth } from "#/context/auth-context";

export const useUserRepositories = () => {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();
const { data: config } = useConfig();

const repos = useInfiniteQuery({
queryKey: ["repositories", githubTokenIsSet],
queryKey: ["repositories", tokenIsSet],
queryFn: async ({ pageParam }) =>
retrieveGitHubUserRepositories(pageParam, 100),
initialPageParam: 1,
getNextPageParam: (lastPage) => lastPage.nextPage,
enabled: githubTokenIsSet && config?.APP_MODE === "oss",
enabled: tokenIsSet && config?.APP_MODE === "oss",
});

// TODO: Once we create our custom dropdown component, we should fetch data onEndReached
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/hooks/use-github-auth-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ interface UseGitHubAuthUrlConfig {
}

export const useGitHubAuthUrl = (config: UseGitHubAuthUrlConfig) => {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();

return React.useMemo(() => {
if (config.appMode === "saas" && !githubTokenIsSet)
if (config.appMode === "saas" && !tokenIsSet)
return generateGitHubAuthUrl(
config.gitHubClientId || "",
new URL(window.location.href),
);

return null;
}, [githubTokenIsSet, config.appMode, config.gitHubClientId]);
}, [tokenIsSet, config.appMode, config.gitHubClientId]);
};
2 changes: 0 additions & 2 deletions frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const MOCK_DEFAULT_USER_SETTINGS: ApiSettings | PostApiSettings = {
remote_runtime_resource_factor:
DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
token_is_set: DEFAULT_SETTINGS.TOKEN_IS_SET,
token_type: DEFAULT_SETTINGS.TOKEN_TYPE,
enable_default_condenser: DEFAULT_SETTINGS.ENABLE_DEFAULT_CONDENSER,
enable_sound_notifications: DEFAULT_SETTINGS.ENABLE_SOUND_NOTIFICATIONS,
user_consents_to_analytics: DEFAULT_SETTINGS.USER_CONSENTS_TO_ANALYTICS,
Expand Down Expand Up @@ -204,7 +203,6 @@ export const handlers = [
if (newSettings.unset_token) {
newSettings.token = undefined;
newSettings.token_is_set = false;
newSettings.token_type = undefined;
delete newSettings.unset_token;
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/_oh/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function ErrorBoundary() {
}

export default function MainApp() {
const { githubTokenIsSet } = useAuth();
const { tokenIsSet } = useAuth();
const { data: settings } = useSettings();
const { migrateUserConsent } = useMigrateUserConsent();

Expand Down Expand Up @@ -104,7 +104,7 @@ export default function MainApp() {

{renderWaitlistModal && (
<WaitlistModal
ghTokenIsSet={githubTokenIsSet}
ghTokenIsSet={tokenIsSet}
githubAuthUrl={gitHubAuthUrl}
/>
)}
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/routes/account-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ function AccountSettings() {

saveSettings(
{
token:
formData.get("token-input")?.toString() || undefined,
token: formData.get("token-input")?.toString() || undefined,
LANGUAGE: languageValue,
user_consents_to_analytics: userConsentsToAnalytics,
ENABLE_DEFAULT_CONDENSER: enableMemoryCondenser,
Expand Down Expand Up @@ -347,13 +346,11 @@ function AccountSettings() {
<SettingsInput
testId="token-input"
name="token-input"
label={`${settings.TOKEN_TYPE === 'gitlab' ? 'GitLab' : 'GitHub'} Token`}
label="GitHub Token"
type="password"
className="w-[680px]"
startContent={
isTokenSet && (
<KeyStatusIcon isSet={!!isTokenSet} />
)
isTokenSet && <KeyStatusIcon isSet={!!isTokenSet} />
}
placeholder={isTokenSet ? "**********" : ""}
/>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const DEFAULT_SETTINGS: Settings = {
SECURITY_ANALYZER: "",
REMOTE_RUNTIME_RESOURCE_FACTOR: 1,
TOKEN_IS_SET: false,
TOKEN_TYPE: null,
ENABLE_DEFAULT_CONDENSER: true,
ENABLE_SOUND_NOTIFICATIONS: false,
USER_CONSENTS_TO_ANALYTICS: false,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/types/core/variances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface InitConfig {
LLM_MODEL: string;
};
token?: string;
token_type?: 'github' | 'gitlab';
latest_event_id?: unknown; // Not sure what this is
}

Expand Down
Loading

0 comments on commit f1f7798

Please sign in to comment.