ServiceAccount: New service account modal to follow design system (#52373)

* ServiceAccount: New service account modal to follow design system

* Fixing spacing and removing double Field label

* Fixing imports

* Update comment
pull/52419/head
Torkel Ödegaard 3 years ago committed by GitHub
parent b3b64e24c2
commit 1bedf33e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      public/app/features/serviceaccounts/components/CreateTokenModal.tsx

@ -8,11 +8,7 @@ import {
ClipboardButton, ClipboardButton,
DatePickerWithInput, DatePickerWithInput,
Field, Field,
FieldSet,
HorizontalGroup,
Icon,
Input, Input,
Label,
Modal, Modal,
RadioButtonGroup, RadioButtonGroup,
useStyles2, useStyles2,
@ -76,12 +72,7 @@ export const CreateTokenModal = ({ isOpen, token, serviceAccountLogin, onCreateT
onClose(); onClose();
}; };
const modalTitle = ( const modalTitle = !token ? 'Add service account token' : 'Service account token created';
<div className={styles.modalHeaderTitle}>
<Icon className={styles.modalHeaderIcon} name="key-skeleton-alt" size="lg" />
<span>{!token ? 'Add service account token' : 'Service account token created'}</span>
</div>
);
return ( return (
<Modal <Modal
@ -93,11 +84,9 @@ export const CreateTokenModal = ({ isOpen, token, serviceAccountLogin, onCreateT
> >
{!token ? ( {!token ? (
<div> <div>
<FieldSet>
<Field <Field
label="Display name" label="Display name"
description="Name to easily identify the token" description="Name to easily identify the token"
className={styles.modalRow}
// for now this is required // for now this is required
// need to make this optional in backend as well // need to make this optional in backend as well
required={true} required={true}
@ -111,15 +100,16 @@ export const CreateTokenModal = ({ isOpen, token, serviceAccountLogin, onCreateT
}} }}
/> />
</Field> </Field>
<Field label="Expiration">
<RadioButtonGroup <RadioButtonGroup
className={styles.modalRow}
options={EXPIRATION_OPTIONS} options={EXPIRATION_OPTIONS}
value={isWithExpirationDate} value={isWithExpirationDate}
onChange={setIsWithExpirationDate} onChange={setIsWithExpirationDate}
size="md" size="md"
/> />
</Field>
{isWithExpirationDate && ( {isWithExpirationDate && (
<Field label="Expiration date" className={styles.modalRow}> <Field label="Expiration date">
<DatePickerWithInput <DatePickerWithInput
onChange={onExpirationDateChange} onChange={onExpirationDateChange}
value={newTokenExpirationDate} value={newTokenExpirationDate}
@ -128,42 +118,39 @@ export const CreateTokenModal = ({ isOpen, token, serviceAccountLogin, onCreateT
/> />
</Field> </Field>
)} )}
</FieldSet> <Modal.ButtonRow>
<Button onClick={onGenerateToken} disabled={isWithExpirationDate && !isExpirationDateValid}> <Button onClick={onGenerateToken} disabled={isWithExpirationDate && !isExpirationDateValid}>
Generate token Generate token
</Button> </Button>
</Modal.ButtonRow>
</div> </div>
) : ( ) : (
<> <>
<FieldSet> <Field
<Label label="Token"
description="You will not be able to see or generate it again. Loosing a token requires creating new one." description="Copy the token now as you will not be able to see it again. Loosing a token requires creating a new one."
className={styles.modalRow}
> >
Copy the token. It will be showed only once.
</Label>
<Field label="Token" className={styles.modalRow}>
<div className={styles.modalTokenRow}> <div className={styles.modalTokenRow}>
<Input name="tokenValue" value={token} readOnly /> <Input name="tokenValue" value={token} readOnly />
<ClipboardButton <ClipboardButton
className={styles.modalCopyToClipboardButton} className={styles.modalCopyToClipboardButton}
variant="secondary" variant="secondary"
size="md" size="md"
icon="copy"
getText={() => token} getText={() => token}
> >
<Icon name="copy" /> Copy to clipboard Copy clipboard
</ClipboardButton> </ClipboardButton>
</div> </div>
</Field> </Field>
</FieldSet> <Modal.ButtonRow>
<HorizontalGroup>
<ClipboardButton variant="primary" getText={() => token} onClipboardCopy={onCloseInternal}> <ClipboardButton variant="primary" getText={() => token} onClipboardCopy={onCloseInternal}>
Copy to clipboard and close Copy to clipboard and close
</ClipboardButton> </ClipboardButton>
<Button variant="secondary" onClick={onCloseInternal}> <Button variant="secondary" onClick={onCloseInternal}>
Close Close
</Button> </Button>
</HorizontalGroup> </Modal.ButtonRow>
</> </>
)} )}
</Modal> </Modal>
@ -185,29 +172,11 @@ const getStyles = (theme: GrafanaTheme2) => {
modalContent: css` modalContent: css`
overflow: visible; overflow: visible;
`, `,
modalRow: css`
margin-bottom: ${theme.spacing(4)};
`,
modalTokenRow: css` modalTokenRow: css`
display: flex; display: flex;
`, `,
modalCopyToClipboardButton: css` modalCopyToClipboardButton: css`
margin-left: ${theme.spacing(0.5)}; margin-left: ${theme.spacing(0.5)};
`, `,
modalHeaderTitle: css`
font-size: ${theme.typography.size.lg};
margin: ${theme.spacing(0, 4, 0, 1)};
display: flex;
align-items: center;
position: relative;
top: 2px;
`,
modalHeaderIcon: css`
margin-right: ${theme.spacing(2)};
font-size: inherit;
&:before {
vertical-align: baseline;
}
`,
}; };
}; };

Loading…
Cancel
Save