Skip to content

Commit

Permalink
Don't divide xmin from rest of qrep. Don't send whole config down for…
Browse files Browse the repository at this point in the history
… listing mirrors. Fix drop mirror request & typing
  • Loading branch information
serprex committed Jun 21, 2024
1 parent 28207eb commit 4fd8453
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 71 deletions.
24 changes: 13 additions & 11 deletions ui/app/api/mirrors/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getTruePeer } from '@/app/api/peers/getTruePeer';
import { MirrorsListing } from '@/app/dto/MirrorsDTO';
import prisma from '@/app/utils/prisma';

export const dynamic = 'force-dynamic';

export async function GET(request: Request) {
export async function GET(_request: Request) {
const mirrors = await prisma.flows.findMany({
distinct: 'name',
include: {
Expand All @@ -12,14 +12,16 @@ export async function GET(request: Request) {
},
});

// using any as type because of the way prisma returns data
const flows = mirrors?.map((mirror: any) => {
let newMirror: any = {
...mirror,
sourcePeer: getTruePeer(mirror.sourcePeer),
destinationPeer: getTruePeer(mirror.destinationPeer),
};
return newMirror;
});
const flows: MirrorsListing[] = mirrors?.map((mirror) => ({
id: mirror.id,
workflow_id: mirror.workflow_id,
name: mirror.name,
sourceName: mirror.sourcePeer.name,
sourceType: mirror.sourcePeer.type,
destinationName: mirror.destinationPeer.name,
destinationType: mirror.destinationPeer.type,
createdAt: mirror.created_at,
isCdc: !!mirror.query_string,
}));
return new Response(JSON.stringify(flows));
}
12 changes: 12 additions & 0 deletions ui/app/dto/MirrorsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ export type MirrorLogsType = {
error_type: string;
error_timestamp: Date;
}[];

export type MirrorsListing = {
id: number;
workflow_id: string | null;
name: string;
sourceName: string;
sourceType: number;
destinationName: string;
destinationType: number;
createdAt: string | Date;
isCdc: boolean;
};
31 changes: 4 additions & 27 deletions ui/app/mirrors/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { MirrorsListing } from '@/app/dto/MirrorsDTO';
import NewButton from '@/components/NewButton';
import { QRepConfig } from '@/grpc_generated/flow';
import { Header } from '@/lib/Header';
import { Label } from '@/lib/Label';
import { LayoutMain } from '@/lib/Layout';
Expand All @@ -17,31 +17,13 @@ export default function Mirrors() {
data: flows,
error,
isLoading,
}: { data: [any]; error: any; isLoading: boolean } = useSWR(
}: { data: MirrorsListing[]; error: any; isLoading: boolean } = useSWR(
'/api/mirrors',
fetcher
);

let cdcFlows = flows?.filter((flow) => {
return !flow.query_string;
});

let qrepFlows = flows?.filter((flow) => {
if (flow.config_proto && flow.query_string) {
let config = QRepConfig.decode(flow.config_proto.data);
const watermarkCol = config.watermarkColumn.toLowerCase();
return watermarkCol !== 'xmin' && watermarkCol !== 'ctid';
}
return false;
});

let xminFlows = flows?.filter((flow) => {
if (flow.config_proto && flow.query_string) {
let config = QRepConfig.decode(flow.config_proto.data);
return config.watermarkColumn.toLowerCase() === 'xmin';
}
return false;
});
const cdcFlows = flows?.filter((flow) => flow.isCdc);
const qrepFlows = flows?.filter((flow) => !flow.isCdc);

return (
<LayoutMain alignSelf='flex-start' justifySelf='flex-start' width='full'>
Expand Down Expand Up @@ -90,11 +72,6 @@ export default function Mirrors() {
<QRepFlows title='Query Replication' qrepFlows={qrepFlows} />
</Panel>
)}
{!isLoading && (
<Panel className='mt-10'>
<QRepFlows title='XMIN Mirrors' qrepFlows={xminFlows} />
</Panel>
)}
</LayoutMain>
);
}
42 changes: 21 additions & 21 deletions ui/app/mirrors/tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { Icon } from '@/lib/Icon';
import { Label } from '@/lib/Label';
import { Table, TableCell, TableRow } from '@/lib/Table';
import Link from 'next/link';
import { MirrorType } from '../dto/MirrorsDTO';
import { MirrorType, MirrorsListing } from '../dto/MirrorsDTO';
import { tableStyle } from '../peers/[peerName]/style';

export function CDCFlows({ cdcFlows }: { cdcFlows: any }) {
export function CDCFlows({ cdcFlows }: { cdcFlows: MirrorsListing[] }) {
if (cdcFlows?.length === 0) {
return (
<div
Expand Down Expand Up @@ -56,25 +56,25 @@ export function CDCFlows({ cdcFlows }: { cdcFlows: any }) {
</TableRow>
}
>
{cdcFlows.map((flow: any) => (
{cdcFlows.map((flow) => (
<TableRow key={flow.id}>
<TableCell>
<MirrorLink flowName={flow?.name} />
</TableCell>
<TableCell>
<PeerButton
peerName={flow.sourcePeer.name}
peerType={flow.sourcePeer.type}
peerName={flow.sourceName}
peerType={flow.sourceType}
/>
</TableCell>
<TableCell>
<PeerButton
peerName={flow.destinationPeer.name}
peerType={flow.destinationPeer.type}
peerName={flow.destinationName}
peerType={flow.destinationType}
/>
</TableCell>
<TableCell>
<TimeLabel timeVal={flow.created_at} />
<TimeLabel timeVal={flow.createdAt} />
</TableCell>
<TableCell>
<Link href={`/mirrors/errors/${flow.name}`}>
Expand All @@ -87,8 +87,8 @@ export function CDCFlows({ cdcFlows }: { cdcFlows: any }) {
dropArgs={{
workflowId: flow.workflow_id,
flowJobName: flow.name,
sourcePeer: flow.sourcePeer,
destinationPeer: flow.destinationPeer,
sourcePeer: flow.sourceName,
destinationPeer: flow.destinationName,
}}
/>
</TableCell>
Expand All @@ -105,7 +105,7 @@ export function QRepFlows({
qrepFlows,
title,
}: {
qrepFlows: any;
qrepFlows: MirrorsListing[];
title: string;
}) {
if (qrepFlows?.length === 0) {
Expand All @@ -120,8 +120,8 @@ export function QRepFlows({
>
<Label variant='headline'>{title}</Label>
<NewButton
targetPage={`/mirrors/create?type=${title === 'XMIN Mirrors' ? MirrorType.XMin : MirrorType.QRep}`}
buttonText={`Create your first ${title === 'XMIN Mirrors' ? 'XMIN mirror' : 'query replication'}`}
targetPage={`/mirrors/create?type=${MirrorType.QRep}`}
buttonText='Create your first query replication'
/>
</div>
);
Expand All @@ -146,34 +146,34 @@ export function QRepFlows({
</TableRow>
}
>
{qrepFlows.map((flow: any) => (
{qrepFlows.map((flow) => (
<TableRow key={flow.id}>
<TableCell>
<MirrorLink flowName={flow?.name} />
</TableCell>
<TableCell>
<PeerButton
peerName={flow.sourcePeer.name}
peerType={flow.sourcePeer.type}
peerName={flow.sourceName}
peerType={flow.sourceType}
/>
</TableCell>
<TableCell>
<PeerButton
peerName={flow.destinationPeer.name}
peerType={flow.destinationPeer.type}
peerName={flow.destinationName}
peerType={flow.destinationType}
/>
</TableCell>
<TableCell>
<TimeLabel timeVal={flow.created_at} />
<TimeLabel timeVal={flow.createdAt} />
</TableCell>
<TableCell>
<DropDialog
mode='MIRROR'
dropArgs={{
workflowId: flow.workflow_id,
flowJobName: flow.name,
sourcePeer: flow.sourcePeer,
destinationPeer: flow.destinationPeer,
sourcePeer: flow.sourceName,
destinationPeer: flow.destinationName,
}}
/>
</TableCell>
Expand Down
17 changes: 5 additions & 12 deletions ui/components/DropDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export const DropDialog = ({
};

const getDeleteText = () => {
let deletePart = 'Are you sure you want to delete ';
let objectSpecificDeleteText = '';
switch (mode) {
case 'MIRROR':
Expand All @@ -137,25 +136,19 @@ export const DropDialog = ({
objectSpecificDeleteText = 'this script';
break;
}
return (
deletePart + objectSpecificDeleteText + '? This action cannot be reverted'
);
return `Are you sure you want to delete ${objectSpecificDeleteText}? This action cannot be reverted`;
};

const handleDelete = () => {
switch (mode) {
case 'MIRROR':
handleDropMirror(dropArgs as dropMirrorArgs, setLoading, setMsg);
break;
return handleDropMirror(dropArgs as dropMirrorArgs, setLoading, setMsg);
case 'PEER':
handleDropPeer(dropArgs as dropPeerArgs);
break;
return handleDropPeer(dropArgs as dropPeerArgs);
case 'ALERT':
handleDeleteAlert(dropArgs as deleteAlertArgs);
break;
return handleDeleteAlert(dropArgs as deleteAlertArgs);
case 'SCRIPT':
handleDeleteScript(dropArgs as deleteScriptArgs);
break;
return handleDeleteScript(dropArgs as deleteScriptArgs);
}
};

Expand Down

0 comments on commit 4fd8453

Please sign in to comment.