Merge pull request #2054 from guardicore/2036-use-new-reset-endpoints

2036 use new reset endpoints
This commit is contained in:
Mike Salvatore 2022-07-01 09:29:54 -04:00 committed by GitHub
commit e14101998f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 12 deletions

View File

@ -54,8 +54,7 @@ const IslandResetModal = (props: Props) => {
<button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}} <button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}}
onClick={() => { onClick={() => {
setDeleteStatus(Loading); setDeleteStatus(Loading);
resetIsland('/api?action=delete-agent-data', clearSimulationData(() => {
() => {
setDeleteStatus(Done) setDeleteStatus(Done)
}) })
}}> }}>
@ -75,11 +74,14 @@ const IslandResetModal = (props: Props) => {
<button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}} <button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}}
onClick={() => { onClick={() => {
setResetAll(Loading); setResetAll(Loading);
resetIsland('/api?action=reset', try {
() => { resetAll();
setResetAll(Done); setResetAll(Done);
props.onClose(); props.onClose();
}) } catch (err) {
// TODO: Display error message to user
console.error(err)
}
}}> }}>
Reset the Island Reset the Island
</button> </button>
@ -91,15 +93,30 @@ const IslandResetModal = (props: Props) => {
} }
} }
function resetIsland(url: string, callback: () => void) { function clearSimulationData(callback: () => void) {
auth.authFetch(url) auth.authFetch('/api/clear-simulation-data', {method: 'POST'})
.then(res => res.json())
.then(res => { .then(res => {
if (res['status'] === 'OK') { if (res.status === 200) {
callback() callback();
} }
}) })
} }
function resetAll() {
auth.authFetch('/api/reset-agent-configuration', {method: 'POST'})
.then(res => {
if (res.status === 200) {
return auth.authFetch('/api/clear-simulation-data', {method: 'POST'})
})
.then(res => {
if (res.status === 200) {
return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'})
})
.then(res => {
if (res.status !== 200) {
throw 'Error resetting the simulation'
}
})
}
function showModalButtons() { function showModalButtons() {
return (<Container className={`text-left island-reset-modal`}> return (<Container className={`text-left island-reset-modal`}>