From 4aa75c5bc224f2da8259f43c317b3fc307ee0c36 Mon Sep 17 00:00:00 2001 From: Alban Bailly Date: Wed, 21 Jun 2023 12:58:52 -0400 Subject: [PATCH 1/6] Feat: [M3-6473] initial commit - replace default export --- .../src/components/AccessPanel/UserSSHKeyPanel.tsx | 4 ++-- .../features/Profile/SSHKeys/CreateSSHKeyDrawer.test.tsx | 8 ++++---- .../src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx | 6 ++---- packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/manager/src/components/AccessPanel/UserSSHKeyPanel.tsx b/packages/manager/src/components/AccessPanel/UserSSHKeyPanel.tsx index a5ba0508b85..6bafbfbeadd 100644 --- a/packages/manager/src/components/AccessPanel/UserSSHKeyPanel.tsx +++ b/packages/manager/src/components/AccessPanel/UserSSHKeyPanel.tsx @@ -10,7 +10,7 @@ import { TableCell } from 'src/components/TableCell'; import { TableRow } from 'src/components/TableRow'; import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty'; import { TableRowError } from 'src/components/TableRowError/TableRowError'; -import SSHKeyCreationDrawer from 'src/features/Profile/SSHKeys/CreateSSHKeyDrawer'; +import { CreateSSHKeyDrawer } from 'src/features/Profile/SSHKeys/CreateSSHKeyDrawer'; import { usePagination } from 'src/hooks/usePagination'; import { useAccountUsers } from 'src/queries/accountUsers'; import { useProfile, useSSHKeysQuery } from 'src/queries/profile'; @@ -219,7 +219,7 @@ const UserSSHKeyPanel = (props: Props) => { > Add an SSH Key - setIsCreateDrawerOpen(false)} /> diff --git a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.test.tsx b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.test.tsx index c948e2eebb2..f6c1eb65f4a 100644 --- a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.test.tsx +++ b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.test.tsx @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event'; import { sshKeyFactory } from 'src/factories'; import { rest, server } from 'src/mocks/testServer'; import { renderWithTheme } from 'src/utilities/testHelpers'; -import SSHKeyCreationDrawer from './CreateSSHKeyDrawer'; +import { CreateSSHKeyDrawer } from './CreateSSHKeyDrawer'; const props = { open: true, @@ -13,7 +13,7 @@ const props = { describe('SSHKeyCreationDrawer', () => { it('should have an input field for label', () => { - const { getByText } = renderWithTheme(); + const { getByText } = renderWithTheme(); // Check for inputs getByText('Label'); getByText('SSH Public Key'); @@ -25,7 +25,7 @@ describe('SSHKeyCreationDrawer', () => { it('should be submittable and should show client side validation errors', async () => { const { getAllByRole, getByTestId, getByText } = renderWithTheme( - + ); const inputs = getAllByRole('textbox'); @@ -53,7 +53,7 @@ describe('SSHKeyCreationDrawer', () => { ); const { getAllByRole, getByTestId } = renderWithTheme( - + ); const inputs = getAllByRole('textbox'); diff --git a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx index bae6261d462..6809eaa5792 100644 --- a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx +++ b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx @@ -14,7 +14,7 @@ interface Props { onClose: () => void; } -const CreateSSHKeyDrawer = ({ open, onClose }: Props) => { +export const CreateSSHKeyDrawer = React.memo(({ open, onClose }: Props) => { const { enqueueSnackbar } = useSnackbar(); const { mutateAsync: createSSHKey, @@ -81,6 +81,4 @@ const CreateSSHKeyDrawer = ({ open, onClose }: Props) => { ); -}; - -export default React.memo(CreateSSHKeyDrawer); +}); diff --git a/packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx b/packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx index cfbaa6691ca..c29d0fdeaf1 100644 --- a/packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx +++ b/packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx @@ -5,7 +5,7 @@ import EditSSHKeyDrawer from './EditSSHKeyDrawer'; import Grid from '@mui/material/Unstable_Grid2'; import Hidden from 'src/components/core/Hidden'; import SSHKeyActionMenu from 'src/features/Profile/SSHKeys/SSHKeyActionMenu'; -import SSHKeyCreationDrawer from './CreateSSHKeyDrawer'; +import { CreateSSHKeyDrawer } from './CreateSSHKeyDrawer'; import Typography from 'src/components/core/Typography'; import { DocumentTitleSegment } from 'src/components/DocumentTitle'; import { getSSHKeyFingerprint } from 'src/utilities/ssh-fingerprint'; @@ -144,7 +144,7 @@ export const SSHKeys = () => { onClose={() => setIsEditDrawerOpen(false)} sshKey={selectedKey} /> - setIsCreateDrawerOpen(false)} /> From 43a7398af1ddd1b59dfcab0033b832e5bfb83ac9 Mon Sep 17 00:00:00 2001 From: Alban Bailly Date: Thu, 22 Jun 2023 14:52:06 -0400 Subject: [PATCH 2/6] Feat: [M3-6473] Helper text and trim on blur --- .../Profile/SSHKeys/CreateSSHKeyDrawer.tsx | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx index 6809eaa5792..860eaa46a60 100644 --- a/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx +++ b/packages/manager/src/features/Profile/SSHKeys/CreateSSHKeyDrawer.tsx @@ -2,9 +2,11 @@ import * as React from 'react'; import ActionsPanel from 'src/components/ActionsPanel'; import Button from 'src/components/Button'; import Drawer from 'src/components/Drawer'; -import { Notice } from 'src/components/Notice/Notice'; -import TextField from 'src/components/TextField'; import getAPIErrorFor from 'src/utilities/getAPIErrorFor'; +import Link from 'src/components/Link'; +import TextField from 'src/components/TextField'; +import { Notice } from 'src/components/Notice/Notice'; +import { styled } from '@mui/material/styles'; import { useCreateSSHKeyMutation } from 'src/queries/profile'; import { useFormik } from 'formik'; import { useSnackbar } from 'notistack'; @@ -45,6 +47,17 @@ export const CreateSSHKeyDrawer = React.memo(({ open, onClose }: Props) => { const generalError = hasErrorFor('none'); + const sshTextArea = ( + <> + + Learn about + {' '} + uploading an SSH key or generating a new key pair. Note that the public + key begins with ssh-rsa and ends with{' '} + your_username@hostname + + ); + return ( {generalError && } @@ -64,6 +77,12 @@ export const CreateSSHKeyDrawer = React.memo(({ open, onClose }: Props) => { value={formik.values.ssh_key} multiline rows={1.75} + helperText={sshTextArea} + onBlur={(e) => { + const trimmedValue = e.target.value.trim(); + formik.setFieldValue('ssh_key', trimmedValue); + formik.handleBlur(e); + }} />