|
|
|
|
@ -1,11 +1,15 @@ |
|
|
|
|
import React, { ChangeEvent, FC, FormEvent, useEffect, useState } from 'react'; |
|
|
|
|
import { EventsWithValidation, InlineFormLabel, LegacyForms, ValidationEvents, Button } from '@grafana/ui'; |
|
|
|
|
import { EventsWithValidation, LegacyForms, ValidationEvents, Button, Select, InlineField } from '@grafana/ui'; |
|
|
|
|
import { NewApiKey, OrgRole } from '../../types'; |
|
|
|
|
import { rangeUtil } from '@grafana/data'; |
|
|
|
|
import { rangeUtil, SelectableValue } from '@grafana/data'; |
|
|
|
|
import { SlideDown } from '../../core/components/Animations/SlideDown'; |
|
|
|
|
import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; |
|
|
|
|
|
|
|
|
|
const { Input } = LegacyForms; |
|
|
|
|
const ROLE_OPTIONS: Array<SelectableValue<OrgRole>> = Object.keys(OrgRole).map((role) => ({ |
|
|
|
|
label: role, |
|
|
|
|
value: role as OrgRole, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
show: boolean; |
|
|
|
|
@ -56,8 +60,8 @@ export const ApiKeysForm: FC<Props> = ({ show, onClose, onKeyAdded }) => { |
|
|
|
|
const onNameChange = (event: ChangeEvent<HTMLInputElement>) => { |
|
|
|
|
setName(event.currentTarget.value); |
|
|
|
|
}; |
|
|
|
|
const onRoleChange = (event: ChangeEvent<HTMLSelectElement>) => { |
|
|
|
|
setRole(event.currentTarget.value as OrgRole); |
|
|
|
|
const onRoleChange = (role: SelectableValue<OrgRole>) => { |
|
|
|
|
setRole(role.value!); |
|
|
|
|
}; |
|
|
|
|
const onSecondsToLiveChange = (event: ChangeEvent<HTMLInputElement>) => { |
|
|
|
|
setSecondsToLive(event.currentTarget.value); |
|
|
|
|
@ -75,29 +79,27 @@ export const ApiKeysForm: FC<Props> = ({ show, onClose, onKeyAdded }) => { |
|
|
|
|
<Input type="text" className="gf-form-input" value={name} placeholder="Name" onChange={onNameChange} /> |
|
|
|
|
</div> |
|
|
|
|
<div className="gf-form"> |
|
|
|
|
<span className="gf-form-label">Role</span> |
|
|
|
|
<span className="gf-form-select-wrapper"> |
|
|
|
|
<select className="gf-form-input gf-size-auto" value={role} onChange={onRoleChange}> |
|
|
|
|
{Object.keys(OrgRole).map((role) => { |
|
|
|
|
return ( |
|
|
|
|
<option key={role} label={role} value={role}> |
|
|
|
|
{role} |
|
|
|
|
</option> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</select> |
|
|
|
|
</span> |
|
|
|
|
<InlineField label="Role"> |
|
|
|
|
<Select |
|
|
|
|
inputId="role-select" |
|
|
|
|
value={role} |
|
|
|
|
onChange={onRoleChange} |
|
|
|
|
options={ROLE_OPTIONS} |
|
|
|
|
menuShouldPortal |
|
|
|
|
/> |
|
|
|
|
</InlineField> |
|
|
|
|
</div> |
|
|
|
|
<div className="gf-form max-width-21"> |
|
|
|
|
<InlineFormLabel tooltip={tooltipText}>Time to live</InlineFormLabel> |
|
|
|
|
<Input |
|
|
|
|
type="text" |
|
|
|
|
className="gf-form-input" |
|
|
|
|
placeholder="1d" |
|
|
|
|
validationEvents={timeRangeValidationEvents} |
|
|
|
|
value={secondsToLive} |
|
|
|
|
onChange={onSecondsToLiveChange} |
|
|
|
|
/> |
|
|
|
|
<InlineField tooltip={tooltipText} label="Time to live"> |
|
|
|
|
<Input |
|
|
|
|
id="time-to-live-input" |
|
|
|
|
type="text" |
|
|
|
|
placeholder="1d" |
|
|
|
|
validationEvents={timeRangeValidationEvents} |
|
|
|
|
value={secondsToLive} |
|
|
|
|
onChange={onSecondsToLiveChange} |
|
|
|
|
/> |
|
|
|
|
</InlineField> |
|
|
|
|
</div> |
|
|
|
|
<div className="gf-form"> |
|
|
|
|
<Button>Add</Button> |
|
|
|
|
|