Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Jan 30, 2024
1 parent c1dbbd8 commit 89795c4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 40 deletions.
23 changes: 16 additions & 7 deletions ui/app/mirrors/edit/[mirrorId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SyncStatusRow } from '@/app/dto/MirrorsDTO';
import prisma from '@/app/utils/prisma';
import { ResyncDialog } from '@/components/ResyncDialog';
import { FlowConnectionConfigs } from '@/grpc_generated/flow';
import { MirrorStatusResponse } from '@/grpc_generated/route';
import { Header } from '@/lib/Header';
import { LayoutMain } from '@/lib/Layout';
Expand All @@ -8,9 +10,6 @@ import { redirect } from 'next/navigation';
import { CDCMirror } from './cdc';
import NoMirror from './nomirror';
import SyncStatus from './syncStatus';
import { FlowConnectionConfigs, FlowStatus } from '@/grpc_generated/flow';
import { Button } from '@/lib/Button';
import { ResyncDialog } from '@/components/ResyncDialog';

type EditMirrorProps = {
params: { mirrorId: string };
Expand Down Expand Up @@ -92,11 +91,21 @@ export default async function ViewMirror({

return (
<LayoutMain alignSelf='flex-start' justifySelf='flex-start' width='full'>
<div style={{ display: 'flex', alignItems: 'center', justifyContent:'space-between', paddingRight:'2rem' }}>
<div style={{ display: 'flex', alignItems: 'center'}}>
<Header variant='title2'>{mirrorId}</Header>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
paddingRight: '2rem',
}}
>
<div style={{ display: 'flex', alignItems: 'center' }}>
<Header variant='title2'>{mirrorId}</Header>
</div>
<ResyncDialog mirrorConfig={mirrorConfig} workflowId={mirrorInfo.workflow_id||''}/>
<ResyncDialog
mirrorConfig={mirrorConfig}
workflowId={mirrorInfo.workflow_id || ''}
/>
</div>
<CDCMirror
rows={rows}
Expand Down
22 changes: 13 additions & 9 deletions ui/components/DropDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ interface deleteAlertArgs {
id: number | bigint;
}

export const handleDropMirror = async (dropArgs: dropMirrorArgs,
setLoading:Dispatch<SetStateAction<boolean>>,
setMsg:Dispatch<SetStateAction<string>>
) => {
export const handleDropMirror = async (
dropArgs: dropMirrorArgs,
setLoading: Dispatch<SetStateAction<boolean>>,
setMsg: Dispatch<SetStateAction<string>>
) => {
if (!dropArgs.workflowId) {
setMsg('Workflow ID not found for this mirror.');
console.log('Workflow ID not found for this mirror.')
return false;
}
setLoading(true);
Expand All @@ -41,7 +41,7 @@ export const handleDropMirror = async (dropArgs: dropMirrorArgs,
body: JSON.stringify(dropArgs),
}).then((res) => res.json());
setLoading(false);
if (dropRes.dropped !== true){
if (dropRes.dropped !== true) {
setMsg(
`Unable to drop mirror ${dropArgs.flowJobName}. ${
dropRes.errorMessage ?? ''
Expand All @@ -51,10 +51,10 @@ export const handleDropMirror = async (dropArgs: dropMirrorArgs,
}

setMsg('Mirror dropped successfully.');
if(!dropArgs.forResync){
if (!dropArgs.forResync) {
window.location.reload();
}

return true;
};

Expand Down Expand Up @@ -147,7 +147,11 @@ export const DropDialog = ({
<Button
onClick={() =>
mode === 'MIRROR'
? handleDropMirror(dropArgs as dropMirrorArgs, setLoading, setMsg)
? handleDropMirror(
dropArgs as dropMirrorArgs,
setLoading,
setMsg
)
: mode === 'PEER'
? handleDropPeer(dropArgs as dropPeerArgs)
: handleDeleteAlert(dropArgs as deleteAlertArgs)
Expand Down
54 changes: 30 additions & 24 deletions ui/components/ResyncDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,56 @@ export const ResyncDialog = ({
mirrorConfig,
workflowId,
}: {
mirrorConfig:CDCConfig,
workflowId:string
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({
setMsg('Dropping existing mirror');
const dropStatus = await handleDropMirror(
{
workflowId: workflowId,
flowJobName: mirrorConfig.flowJobName,
sourcePeer: mirrorConfig.source!,
destinationPeer: mirrorConfig.destination!,
forResync: true,
}, setDropping, setMsg);
},
setDropping,
setMsg
);

if(!dropStatus){
return;
if (!dropStatus) {
return;
}

setSyncing(true)
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());
method: 'POST',
body: JSON.stringify({
config: mirrorConfig,
}),
}).then((res) => res.json());
setSyncing(false);
if(!createStatus.created){
setMsg('Resyncing of existing mirror failed');
return;
};
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'}}>
<Button variant='normalSolid' style={{ height: '2em', width: '8em' }}>
Resync
</Button>
}
Expand All @@ -70,12 +76,12 @@ export const ResyncDialog = ({
<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' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
{syncing || (dropping && <DotLoader size={15} />)}
<Label as='label' style={{ marginTop: '0.3rem' }}>
{msg}
</Label>
</div>
</Label>
</div>
<div style={{ display: 'flex', marginTop: '1rem' }}>
<DialogClose>
<Button style={{ backgroundColor: '#6c757d', color: 'white' }}>
Expand Down

0 comments on commit 89795c4

Please sign in to comment.