Skip to content

Commit

Permalink
move buttons to client component
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jun 22, 2024
1 parent 49efb11 commit 17bbc12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
23 changes: 2 additions & 21 deletions ui/app/mirrors/[mirrorId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { GetFlowHttpAddressFromEnv } from '@/rpc/http';
import { CDCMirror } from './cdc';
import NoMirror from './nomirror';
import QrepGraph from './qrepGraph';
import QRepStatusButtons from './qrepStatusButtons';
import QRepStatusTable, { QRepPartitionStatus } from './qrepStatusTable';
import SyncStatus from './syncStatus';

Expand All @@ -31,17 +32,6 @@ async function getMirrorStatus(mirrorId: string) {
return json;
}

function setFlowState(flowJobName: string, requestedFlowState: FlowStatus) {
return fetch(`/api/mirrors/state_change`, {
method: 'POST',
body: JSON.stringify({
flowJobName,
requestedFlowState,
}),
cache: 'no-store',
});
}

export default async function ViewMirror({
params: { mirrorId },
}: EditMirrorProps) {
Expand Down Expand Up @@ -182,16 +172,7 @@ export default async function ViewMirror({
}}
>
<Header variant='title2'>{mirrorId}</Header>
<input
type='button'
value='Pause'
onClick={() => setFlowState(mirrorId, FlowStatus.STATUS_PAUSED)}
/>
<input
type='button'
value='Resume'
onClick={() => setFlowState(mirrorId, FlowStatus.STATUS_RUNNING)}
/>
<QRepStatusButtons mirrorId={mirrorId} />
</div>
<div>Status: {mirrorStatus.currentFlowState}</div>
<QrepGraph
Expand Down
34 changes: 34 additions & 0 deletions ui/app/mirrors/[mirrorId]/qrepStatusButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client';
import { FlowStatus } from '@/grpc_generated/flow';

async function setFlowState(
flowJobName: string,
requestedFlowState: FlowStatus
) {
await fetch(`/api/mirrors/state_change`, {
method: 'POST',
body: JSON.stringify({
flowJobName,
requestedFlowState,
}),
cache: 'no-store',
});
window.location.reload();
}

export default function qrepStatusButtons(props: { mirrorId: string }) {
return (
<>
<input
type='button'
value='Pause'
onClick={() => setFlowState(props.mirrorId, FlowStatus.STATUS_PAUSED)}
/>
<input
type='button'
value='Resume'
onClick={() => setFlowState(props.mirrorId, FlowStatus.STATUS_RUNNING)}
/>
</>
);
}

0 comments on commit 17bbc12

Please sign in to comment.