-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a resync button in the specific mirror page which when clicked opens a confirmation dialog box. The resync when done via UI: - first calls drop mirror and drops the mirror - kicks off a cdc mirror with the same config as the current mirror, with `resync:true` added 
- Loading branch information
1 parent
9871d73
commit cfab700
Showing
4 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use client'; | ||
import { CDCConfig } from '@/app/dto/MirrorsDTO'; | ||
import { Button } from '@/lib/Button'; | ||
import { Dialog, DialogClose } from '@/lib/Dialog'; | ||
import { Label } from '@/lib/Label'; | ||
import { Divider } from '@tremor/react'; | ||
import { useState } from 'react'; | ||
import { BarLoader, DotLoader } from 'react-spinners'; | ||
import { handleDropMirror } from './DropDialog'; | ||
|
||
export const ResyncDialog = ({ | ||
mirrorConfig, | ||
workflowId, | ||
}: { | ||
mirrorConfig: CDCConfig; | ||
workflowId: string; | ||
}) => { | ||
const [syncing, setSyncing] = useState(false); | ||
const [dropping, setDropping] = useState(false); | ||
const [msg, setMsg] = useState(''); | ||
|
||
const handleResync = async () => { | ||
setMsg('Dropping existing mirror'); | ||
const dropStatus = await handleDropMirror( | ||
{ | ||
workflowId: workflowId, | ||
flowJobName: mirrorConfig.flowJobName, | ||
sourcePeer: mirrorConfig.source!, | ||
destinationPeer: mirrorConfig.destination!, | ||
forResync: true, | ||
}, | ||
setDropping, | ||
setMsg | ||
); | ||
|
||
if (!dropStatus) { | ||
return; | ||
} | ||
|
||
setSyncing(true); | ||
setMsg('Resyncing...'); | ||
mirrorConfig.resync = true; | ||
const createStatus = await fetch('/api/mirrors/cdc', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
config: mirrorConfig, | ||
}), | ||
}).then((res) => res.json()); | ||
setSyncing(false); | ||
if (!createStatus.created) { | ||
setMsg('Resyncing of existing mirror failed'); | ||
return; | ||
} | ||
|
||
setMsg('Mirror resynced successfully'); | ||
window.location.reload(); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
noInteract={true} | ||
size='xLarge' | ||
triggerButton={ | ||
<Button variant='normalSolid' style={{ height: '2em', width: '8em' }}> | ||
Resync | ||
</Button> | ||
} | ||
> | ||
<div> | ||
<Label as='label' variant='action'> | ||
Resync {mirrorConfig.flowJobName} | ||
</Label> | ||
<Divider style={{ margin: 0 }} /> | ||
<Label as='label' variant='body' style={{ marginTop: '0.3rem' }}> | ||
Are you sure you want to resync this mirror? | ||
<br></br> | ||
This involves <b>dropping the existing mirror</b> and recreating it. | ||
</Label> | ||
<div style={{ display: 'flex', alignItems: 'center' }}> | ||
{syncing || (dropping && <DotLoader size={15} />)} | ||
<Label as='label' style={{ marginTop: '0.3rem' }}> | ||
{msg} | ||
</Label> | ||
</div> | ||
<div style={{ display: 'flex', marginTop: '1rem' }}> | ||
<DialogClose> | ||
<Button style={{ backgroundColor: '#6c757d', color: 'white' }}> | ||
Cancel | ||
</Button> | ||
</DialogClose> | ||
<Button | ||
onClick={handleResync} | ||
variant='normalSolid' | ||
style={{ | ||
marginLeft: '1rem', | ||
}} | ||
> | ||
{syncing || dropping ? <BarLoader /> : 'Resync'} | ||
</Button> | ||
</div> | ||
</div> | ||
</Dialog> | ||
); | ||
}; |