Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(site): move ssh keys management to react-query#9625

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 5 commits intomainfrombq/refactor-ssh-key-service
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
24 changes: 24 additions & 0 deletionssite/src/api/queries/sshKeys.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
import { QueryClient } from "@tanstack/react-query";
import * as API from "api/api";
import { GitSSHKey } from "api/typesGenerated";

const getUserSSHKeyQueryKey = (userId: string) => [userId, "sshKey"];

export const userSSHKey = (userId: string) => {
return {
queryKey: getUserSSHKeyQueryKey(userId),
queryFn: () => API.getUserSSHKey(userId),
};
};

export const regenerateUserSSHKey = (
userId: string,
queryClient: QueryClient,
) => {
return {
mutationFn: () => API.regenerateUserSSHKey(userId),
onSuccess: (newKey: GitSSHKey) => {
queryClient.setQueryData(getUserSSHKeyQueryKey(userId), newKey);
},
};
};
54 changes: 31 additions & 23 deletionssite/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
import { useMachine } from "@xstate/react";
import { PropsWithChildren, FC } from "react";
import { sshKeyMachine } from "xServices/sshKey/sshKeyXService";
import { PropsWithChildren, FC, useState } from "react";
import { ConfirmDialog } from "../../../components/Dialogs/ConfirmDialog/ConfirmDialog";
import { Section } from "../../../components/SettingsLayout/Section";
import { SSHKeysPageView } from "./SSHKeysPageView";
import { regenerateUserSSHKey, userSSHKey } from "api/queries/sshKeys";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

export const Language = {
title: "SSH keys",
Expand All@@ -15,40 +16,47 @@ export const Language = {
};

export const SSHKeysPage: FC<PropsWithChildren<unknown>> = () => {
const [sshState, sshSend] = useMachine(sshKeyMachine);
const isLoading = sshState.matches("gettingSSHKey");
const hasLoaded = sshState.matches("loaded");
const { getSSHKeyError, regenerateSSHKeyError, sshKey } = sshState.context;

const onRegenerateClick = () => {
sshSend({ type: "REGENERATE_SSH_KEY" });
};
const [isConfirmingRegeneration, setIsConfirmingRegeneration] =
useState(false);
const queryClient = useQueryClient();
const userSSHKeyQuery = useQuery(userSSHKey("me"));
const regenerateSSHKeyMutationOptions = regenerateUserSSHKey(
"me",
queryClient,
);
const regenerateSSHKeyMutation = useMutation({
...regenerateSSHKeyMutationOptions,
onSuccess: (newKey) => {
regenerateSSHKeyMutationOptions.onSuccess(newKey);
displaySuccess("SSH Key regenerated successfully.");
setIsConfirmingRegeneration(false);
},
});

return (
<>
<Section title={Language.title}>
<SSHKeysPageView
isLoading={isLoading}
hasLoaded={hasLoaded}
getSSHKeyError={getSSHKeyError}
regenerateSSHKeyError={regenerateSSHKeyError}
sshKey={sshKey}
onRegenerateClick={onRegenerateClick}
isLoading={userSSHKeyQuery.isLoading}
getSSHKeyError={userSSHKeyQuery.error}
regenerateSSHKeyError={regenerateSSHKeyMutation.error}
sshKey={userSSHKeyQuery.data}
onRegenerateClick={() => {
setIsConfirmingRegeneration(true);
}}
/>
</Section>

<ConfirmDialog
type="delete"
hideCancel={false}
open={sshState.matches("confirmSSHKeyRegenerate")}
confirmLoading={sshState.matches("regeneratingSSHKey")}
open={isConfirmingRegeneration}
confirmLoading={regenerateSSHKeyMutation.isLoading}
title={Language.regenerateDialogTitle}
confirmText={Language.confirmLabel}
onConfirm={() => {
sshSend({ type: "CONFIRM_REGENERATE_SSH_KEY" });
}}
onConfirm={regenerateSSHKeyMutation.mutate}
onClose={() => {
sshSend({ type: "CANCEL_REGENERATE_SSH_KEY" });
setIsConfirmingRegeneration(false);
}}
description={<>{Language.regenerateDialogMessage}</>}
/>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,6 @@ const meta: Meta<typeof SSHKeysPageView> = {
component: SSHKeysPageView,
args: {
isLoading: false,
hasLoaded: true,
sshKey: {
user_id: "test-user-id",
created_at: "2022-07-28T07:45:50.795918897Z",
Expand All@@ -30,7 +29,7 @@ export const Loading: Story = {

export const WithGetSSHKeyError: Story = {
args: {
hasLoaded: false,
sshKey: undefined,
getSSHKeyError: mockApiError({
message: "Failed to get SSH key",
}),
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,6 @@ export const Language = {

export interface SSHKeysPageViewProps {
isLoading: boolean;
hasLoaded: boolean;
getSSHKeyError?: unknown;
regenerateSSHKeyError?: unknown;
sshKey?: GitSSHKey;
Expand All@@ -25,7 +24,6 @@ export const SSHKeysPageView: FC<
React.PropsWithChildren<SSHKeysPageViewProps>
> = ({
isLoading,
hasLoaded,
getSSHKeyError,
regenerateSSHKeyError,
sshKey,
Expand All@@ -49,7 +47,7 @@ export const SSHKeysPageView: FC<
{Boolean(regenerateSSHKeyError) && (
<ErrorAlert error={regenerateSSHKeyError} dismissible />
)}
{hasLoaded &&sshKey && (
{sshKey && (
<>
<p className={styles.description}>
The following public key is used to authenticate Git in workspaces.
Expand Down
120 changes: 0 additions & 120 deletionssite/src/xServices/sshKey/sshKeyXService.ts
View file
Open in desktop

This file was deleted.


[8]ページ先頭

©2009-2025 Movatter.jp