Skip to content
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

Feat: [M3-6473] - Add helper text to the Add SSHKey Drawer Form #9290

Merged
merged 6 commits into from
Jun 26, 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
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-9290-added-1687466679796.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

Helper Text for the Add SHHKey Drawer form ([#9290](https://github.com/linode/manager/pull/9290))
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -219,7 +219,7 @@ const UserSSHKeyPanel = (props: Props) => {
>
Add an SSH Key
</Button>
<SSHKeyCreationDrawer
<CreateSSHKeyDrawer
open={isCreateDrawerOpen}
onClose={() => setIsCreateDrawerOpen(false)}
/>
Expand Down
13 changes: 6 additions & 7 deletions packages/manager/src/components/Code/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ interface Props {
children: string;
}

const Code = (props: Props) => {
export const Code = (props: Props) => {
const { children } = props;

return <StyledSpan>{children}</StyledSpan>;
};

export default Code;

const StyledSpan = styled('span')(({ theme }) => ({
backgroundColor: theme.color.grey8,
fontWeight: 'bold',
fontFamily: 'Courier',
color: theme.name === 'dark' ? theme.color.white : theme.color.black,
color: theme.color.black,
fontFamily: '"Ubuntu Mono", monospace, sans-serif',
margin: '0 2px',
backgroundColor: theme.color.grey5,
padding: '0 4px',
}));
2 changes: 0 additions & 2 deletions packages/manager/src/components/Code/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useFormik } from 'formik';
import * as React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import Code from 'src/components/Code';
import { Code } from 'src/components/Code/Code';
import FormHelperText from 'src/components/core/FormHelperText';
import InputAdornment from 'src/components/core/InputAdornment';
import { makeStyles } from '@mui/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,7 +13,7 @@ const props = {

describe('SSHKeyCreationDrawer', () => {
it('should have an input field for label', () => {
const { getByText } = renderWithTheme(<SSHKeyCreationDrawer {...props} />);
const { getByText } = renderWithTheme(<CreateSSHKeyDrawer {...props} />);
// Check for inputs
getByText('Label');
getByText('SSH Public Key');
Expand All @@ -25,7 +25,7 @@ describe('SSHKeyCreationDrawer', () => {

it('should be submittable and should show client side validation errors', async () => {
const { getAllByRole, getByTestId, getByText } = renderWithTheme(
<SSHKeyCreationDrawer {...props} />
<CreateSSHKeyDrawer {...props} />
);

const inputs = getAllByRole('textbox');
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('SSHKeyCreationDrawer', () => {
);

const { getAllByRole, getByTestId } = renderWithTheme(
<SSHKeyCreationDrawer {...props} />
<CreateSSHKeyDrawer {...props} />
);

const inputs = getAllByRole('textbox');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ 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 Typography from 'src/components/core/Typography';
import { Code } from 'src/components/Code/Code';
import { Notice } from 'src/components/Notice/Notice';
import { useCreateSSHKeyMutation } from 'src/queries/profile';
import { useFormik } from 'formik';
import { useSnackbar } from 'notistack';
Expand All @@ -14,7 +17,7 @@ interface Props {
onClose: () => void;
}

const CreateSSHKeyDrawer = ({ open, onClose }: Props) => {
export const CreateSSHKeyDrawer = React.memo(({ open, onClose }: Props) => {
const { enqueueSnackbar } = useSnackbar();
const {
mutateAsync: createSSHKey,
Expand Down Expand Up @@ -45,6 +48,17 @@ const CreateSSHKeyDrawer = ({ open, onClose }: Props) => {

const generalError = hasErrorFor('none');

const SSHTextAreaHelperText = () => (
<Typography component="span">
<Link to="https://www.linode.com/docs/guides/use-public-key-authentication-with-ssh/">
abailly-akamai marked this conversation as resolved.
Show resolved Hide resolved
Learn about
</Link>{' '}
uploading an SSH key or generating a new key pair. Note that the public
key begins with <Code>ssh-rsa</Code> and ends with{' '}
<Code>your_username@hostname</Code>.
</Typography>
);

return (
<Drawer open={open} title="Add SSH Key" onClose={onClose}>
{generalError && <Notice error text={generalError} />}
Expand All @@ -64,6 +78,12 @@ const CreateSSHKeyDrawer = ({ open, onClose }: Props) => {
value={formik.values.ssh_key}
multiline
rows={1.75}
helperText={<SSHTextAreaHelperText />}
onBlur={(e) => {
const trimmedValue = e.target.value.trim();
formik.setFieldValue('ssh_key', trimmedValue);
formik.handleBlur(e);
}}
/>
<ActionsPanel>
<Button buttonType="secondary" onClick={onClose}>
Expand All @@ -81,6 +101,4 @@ const CreateSSHKeyDrawer = ({ open, onClose }: Props) => {
</form>
</Drawer>
);
};

export default React.memo(CreateSSHKeyDrawer);
});
4 changes: 2 additions & 2 deletions packages/manager/src/features/Profile/SSHKeys/SSHKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -144,7 +144,7 @@ export const SSHKeys = () => {
onClose={() => setIsEditDrawerOpen(false)}
sshKey={selectedKey}
/>
<SSHKeyCreationDrawer
<CreateSSHKeyDrawer
open={isCreateDrawerOpen}
onClose={() => setIsCreateDrawerOpen(false)}
/>
Expand Down