|
|
|
@ -40,11 +40,17 @@ function convertScopeStringToTag(scopeString) { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function NewTokenModal(props) { |
|
|
|
interface Props { |
|
|
|
|
|
|
|
onCancel: () => void; |
|
|
|
|
|
|
|
onOk: any; // todo: make better type
|
|
|
|
|
|
|
|
visible: boolean; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function NewTokenModal(props: Props) { |
|
|
|
|
|
|
|
const { onOk, onCancel, visible } = props; |
|
|
|
const [selectedScopes, setSelectedScopes] = useState([]); |
|
|
|
const [selectedScopes, setSelectedScopes] = useState([]); |
|
|
|
const [name, setName] = useState(''); |
|
|
|
const [name, setName] = useState(''); |
|
|
|
|
|
|
|
|
|
|
|
const scopes = Object.keys(availableScopes).map(function (key) { |
|
|
|
const scopes = Object.keys(availableScopes).map(key => { |
|
|
|
return { value: key, label: availableScopes[key].description }; |
|
|
|
return { value: key, label: availableScopes[key].description }; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +59,7 @@ function NewTokenModal(props) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function saveToken() { |
|
|
|
function saveToken() { |
|
|
|
props.onOk(name, selectedScopes); |
|
|
|
onOk(name, selectedScopes); |
|
|
|
|
|
|
|
|
|
|
|
// Clear the modal
|
|
|
|
// Clear the modal
|
|
|
|
setSelectedScopes([]); |
|
|
|
setSelectedScopes([]); |
|
|
|
@ -71,9 +77,9 @@ function NewTokenModal(props) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Modal |
|
|
|
<Modal |
|
|
|
title="Create New Access token" |
|
|
|
title="Create New Access token" |
|
|
|
visible={props.visible} |
|
|
|
visible={visible} |
|
|
|
onOk={saveToken} |
|
|
|
onOk={saveToken} |
|
|
|
onCancel={props.onCancel} |
|
|
|
onCancel={onCancel} |
|
|
|
okButtonProps={okButtonProps} |
|
|
|
okButtonProps={okButtonProps} |
|
|
|
> |
|
|
|
> |
|
|
|
<p> |
|
|
|
<p> |
|
|
|
@ -85,7 +91,8 @@ function NewTokenModal(props) { |
|
|
|
</p> |
|
|
|
</p> |
|
|
|
|
|
|
|
|
|
|
|
<p> |
|
|
|
<p> |
|
|
|
Select the permissions this access token will have. It cannot be edited after it's created. |
|
|
|
Select the permissions this access token will have. It cannot be edited after it's |
|
|
|
|
|
|
|
created. |
|
|
|
</p> |
|
|
|
</p> |
|
|
|
<Checkbox.Group options={scopes} value={selectedScopes} onChange={onChange} /> |
|
|
|
<Checkbox.Group options={scopes} value={selectedScopes} onChange={onChange} /> |
|
|
|
|
|
|
|
|
|
|
|
@ -102,6 +109,47 @@ export default function AccessTokens() { |
|
|
|
const [tokens, setTokens] = useState([]); |
|
|
|
const [tokens, setTokens] = useState([]); |
|
|
|
const [isTokenModalVisible, setIsTokenModalVisible] = useState(false); |
|
|
|
const [isTokenModalVisible, setIsTokenModalVisible] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleError(error) { |
|
|
|
|
|
|
|
console.error('error', error); |
|
|
|
|
|
|
|
alert(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getAccessTokens() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const result = await fetchData(ACCESS_TOKENS); |
|
|
|
|
|
|
|
setTokens(result); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
getAccessTokens(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function handleDeleteToken(token) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await fetchData(DELETE_ACCESS_TOKEN, { |
|
|
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
|
|
data: { token }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
getAccessTokens(); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function handleSaveToken(name: string, scopes: string[]) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const newToken = await fetchData(CREATE_ACCESS_TOKEN, { |
|
|
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
|
|
data: { name, scopes }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
setTokens(tokens.concat(newToken)); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const columns = [ |
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: '', |
|
|
|
title: '', |
|
|
|
@ -121,7 +169,7 @@ export default function AccessTokens() { |
|
|
|
title: 'Token', |
|
|
|
title: 'Token', |
|
|
|
dataIndex: 'token', |
|
|
|
dataIndex: 'token', |
|
|
|
key: 'token', |
|
|
|
key: 'token', |
|
|
|
render: (text, record) => <Input.Password size="small" bordered={false} value={text} />, |
|
|
|
render: text => <Input.Password size="small" bordered={false} value={text} />, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: 'Scopes', |
|
|
|
title: 'Scopes', |
|
|
|
@ -149,48 +197,6 @@ export default function AccessTokens() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const getAccessTokens = async () => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const result = await fetchData(ACCESS_TOKENS); |
|
|
|
|
|
|
|
setTokens(result); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
getAccessTokens(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function handleDeleteToken(token) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const result = await fetchData(DELETE_ACCESS_TOKEN, { |
|
|
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
|
|
data: { token }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
getAccessTokens(); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function handleSaveToken(name: string, scopes: string[]) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const newToken = await fetchData(CREATE_ACCESS_TOKEN, { |
|
|
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
|
|
data: { name, scopes }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
setTokens(tokens.concat(newToken)); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
handleError(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleError(error) { |
|
|
|
|
|
|
|
console.error('error', error); |
|
|
|
|
|
|
|
alert(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const showCreateTokenModal = () => { |
|
|
|
const showCreateTokenModal = () => { |
|
|
|
setIsTokenModalVisible(true); |
|
|
|
setIsTokenModalVisible(true); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|