Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bunch of UI improvements" #1458

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (h *FlowRequestHandler) GetTablesInSchema(
CASE
WHEN con.contype = 'p' OR t.relreplident = 'i' OR t.relreplident = 'f' THEN true
ELSE false
END AS can_mirror,
pg_size_pretty(pg_total_relation_size(quote_ident(n.nspname) || '.' || quote_ident(t.relname))) :: text AS table_size
END AS can_mirror
FROM
pg_class t
LEFT JOIN
Expand All @@ -109,7 +108,6 @@ func (h *FlowRequestHandler) GetTablesInSchema(
can_mirror DESC;
`, req.SchemaName)
if err != nil {
slog.Info("failed to fetch publications", slog.Any("error", err))
return &protos.SchemaTablesResponse{Tables: nil}, err
}

Expand All @@ -118,15 +116,10 @@ func (h *FlowRequestHandler) GetTablesInSchema(
for rows.Next() {
var table pgtype.Text
var hasPkeyOrReplica pgtype.Bool
var tableSize pgtype.Text
err := rows.Scan(&table, &hasPkeyOrReplica, &tableSize)
err := rows.Scan(&table, &hasPkeyOrReplica)
if err != nil {
return &protos.SchemaTablesResponse{Tables: nil}, err
}
var sizeOfTable string
if tableSize.Valid {
sizeOfTable = tableSize.String
}
canMirror := false
if hasPkeyOrReplica.Valid && hasPkeyOrReplica.Bool {
canMirror = true
Expand All @@ -135,14 +128,8 @@ func (h *FlowRequestHandler) GetTablesInSchema(
tables = append(tables, &protos.TableResponse{
TableName: table.String,
CanMirror: canMirror,
TableSize: sizeOfTable,
})
}

if err := rows.Err(); err != nil {
slog.Info("failed to fetch publications", slog.Any("error", err))
return &protos.SchemaTablesResponse{Tables: nil}, err
}
return &protos.SchemaTablesResponse{Tables: tables}, nil
}

Expand Down Expand Up @@ -338,26 +325,3 @@ func (h *FlowRequestHandler) GetStatInfo(
StatData: statInfoRows,
}, nil
}

func (h *FlowRequestHandler) GetPublications(
ctx context.Context,
req *protos.PostgresPeerActivityInfoRequest,
) (*protos.PeerPublicationsResponse, error) {
tunnel, peerConn, err := h.getConnForPGPeer(ctx, req.PeerName)
if err != nil {
return &protos.PeerPublicationsResponse{PublicationNames: nil}, err
}
defer tunnel.Close()
defer peerConn.Close(ctx)

rows, err := peerConn.Query(ctx, "select pubname from pg_publication;")
if err != nil {
return &protos.PeerPublicationsResponse{PublicationNames: nil}, err
}

publications, err := pgx.CollectRows[string](rows, pgx.RowTo)
if err != nil {
return &protos.PeerPublicationsResponse{PublicationNames: nil}, err
}
return &protos.PeerPublicationsResponse{PublicationNames: publications}, nil
}
9 changes: 0 additions & 9 deletions protos/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ message PeerSchemasResponse {
repeated string schemas = 1;
}

message PeerPublicationsResponse {
repeated string publication_names = 1;
}

message SchemaTablesRequest {
string peer_name = 1;
string schema_name = 2;
Expand All @@ -125,7 +121,6 @@ message SchemaTablesResponse {
message TableResponse {
string table_name = 1;
bool can_mirror = 2;
string table_size = 3;
}

message AllTablesResponse {
Expand Down Expand Up @@ -270,10 +265,6 @@ service FlowService {
option (google.api.http) = { get: "/v1/peers/schemas" };
}

rpc GetPublications(PostgresPeerActivityInfoRequest) returns (PeerPublicationsResponse) {
option (google.api.http) = { get: "/v1/peers/publications" };
}

rpc GetTablesInSchema(SchemaTablesRequest) returns (SchemaTablesResponse) {
option (google.api.http) = { get: "/v1/peers/tables" };
}
Expand Down
22 changes: 0 additions & 22 deletions ui/app/api/peers/publications/route.ts

This file was deleted.

5 changes: 5 additions & 0 deletions ui/app/api/peers/schemas/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export async function POST(request: Request) {
let response: USchemasResponse = {
schemas: schemaList.schemas,
};
if (schemaList.message === 'no rows in result set') {
response = {
schemas: [],
};
}
return new Response(JSON.stringify(response));
} catch (e) {
console.log(e);
Expand Down
1 change: 0 additions & 1 deletion ui/app/dto/MirrorsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type TableMapRow = {
exclude: Set<string>;
selected: boolean;
canMirror: boolean;
tableSize: string;
};

export type SyncStatusRow = {
Expand Down
4 changes: 0 additions & 4 deletions ui/app/dto/PeersDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ export type SlotLagPoint = {
updatedAt: string;
slotSize?: string;
};

export type UPublicationsResponse = {
publicationNames: string[];
};
52 changes: 20 additions & 32 deletions ui/app/mirrors/[mirrorId]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import { Label } from '@/lib/Label';
import { RowWithTextField } from '@/lib/Layout';
import { ProgressCircle } from '@/lib/ProgressCircle';
import { TextField } from '@/lib/TextField';
import { Callout } from '@tremor/react';
import { useRouter } from 'next/navigation';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import TableMapping from '../../create/cdc/tablemapping';
import { reformattedTableMapping } from '../../create/handlers';
import { blankCDCSetting } from '../../create/helpers/common';
import * as styles from '../../create/styles';
type EditMirrorProps = {
params: { mirrorId: string };
};
Expand Down Expand Up @@ -122,6 +120,8 @@ const EditMirror = ({ params: { mirrorId } }: EditMirrorProps) => {

return (
<div>
<Label variant='title3'>Edit {mirrorId}</Label>

<RowWithTextField
key={1}
label={<Label>{'Pull Batch Size'} </Label>}
Expand Down Expand Up @@ -174,22 +174,6 @@ const EditMirror = ({ params: { mirrorId } }: EditMirrorProps) => {
}
/>

<Label variant='action' as='label' style={{ marginTop: '1rem' }}>
Adding Tables
</Label>
{!isNotPaused && rows.some((row) => row.selected === true) && (
<Callout
title='Note on adding tables'
color={'gray'}
style={{ marginTop: '1rem' }}
>
CDC will be put on hold until initial load for these added tables have
been completed.
<br></br>
The <b>replication slot will grow</b> during this period.
</Callout>
)}

<TableMapping
sourcePeerName={mirrorState.cdcStatus?.config?.source?.name || ''}
peerType={mirrorState.cdcStatus?.config?.destination?.type}
Expand All @@ -198,23 +182,19 @@ const EditMirror = ({ params: { mirrorId } }: EditMirrorProps) => {
omitAdditionalTablesMapping={omitAdditionalTablesMapping}
/>

{isNotPaused && (
<Callout title='' color={'rose'} style={{ marginTop: '1rem' }}>
Mirror can only be edited while paused.
</Callout>
{isNotPaused ? (
<Label>Mirror can only be edited while paused.</Label>
) : (
<Label>Editing mirror will automatically unpause it.</Label>
)}

<div style={styles.MirrorButtonContainer}>
<div style={{ display: 'flex' }}>
<Button
style={styles.MirrorButtonStyle}
onClick={() => {
push(`/mirrors/${mirrorId}`);
style={{
marginTop: '1rem',
marginRight: '1rem',
width: '8%',
height: '2.5rem',
}}
>
Back
</Button>
<Button
style={styles.MirrorButtonStyle}
variant='normalSolid'
disabled={loading || isNotPaused}
onClick={sendFlowStateChangeRequest}
Expand All @@ -225,6 +205,14 @@ const EditMirror = ({ params: { mirrorId } }: EditMirrorProps) => {
'Edit Mirror'
)}
</Button>
<Button
style={{ marginTop: '1rem', width: '8%', height: '2.5rem' }}
onClick={() => {
push(`/mirrors/${mirrorId}`);
}}
>
Back
</Button>
</div>
<ToastContainer />
</div>
Expand Down
29 changes: 3 additions & 26 deletions ui/app/mirrors/create/cdc/cdc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import { DBType } from '@/grpc_generated/peers';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
import { Dispatch, SetStateAction, useMemo, useState } from 'react';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../../dto/MirrorsDTO';
import { fetchPublications } from '../handlers';
import { MirrorSetting } from '../helpers/common';
import CDCField from './fields';
import TableMapping from './tablemapping';
Expand Down Expand Up @@ -37,7 +36,6 @@ export default function CDCConfigForm({
rows,
setRows,
}: MirrorConfigProps) {
const [publications, setPublications] = useState<string[]>();
const [show, setShow] = useState(false);
const handleChange = (val: string | boolean, setting: MirrorSetting) => {
let stateVal: string | boolean = val;
Expand Down Expand Up @@ -66,26 +64,7 @@ export default function CDCConfigForm({
return true;
};

const optionsForField = (setting: MirrorSetting) => {
switch (setting.label) {
case 'Publication Name':
return publications;
default:
return [];
}
};

useEffect(() => {
fetchPublications(mirrorConfig.source?.name || '').then((pubs) => {
setPublications(pubs);
});
}, [mirrorConfig.source?.name]);

if (
mirrorConfig.source != undefined &&
mirrorConfig.destination != undefined &&
publications != undefined
)
if (mirrorConfig.source != undefined && mirrorConfig.destination != undefined)
return (
<>
{normalSettings.map((setting, id) => {
Expand All @@ -95,7 +74,6 @@ export default function CDCConfigForm({
key={id}
handleChange={handleChange}
setting={setting}
options={optionsForField(setting)}
/>
)
);
Expand Down Expand Up @@ -123,10 +101,9 @@ export default function CDCConfigForm({
advancedSettings.map((setting, id) => {
return (
<CDCField
key={setting.label}
key={id}
handleChange={handleChange}
setting={setting}
options={optionsForField(setting)}
/>
);
})}
Expand Down
48 changes: 3 additions & 45 deletions ui/app/mirrors/create/cdc/fields.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
'use client';
import SelectTheme from '@/app/styles/select';
import { RequiredIndicator } from '@/components/RequiredIndicator';
import { Label } from '@/lib/Label';
import { RowWithSelect, RowWithSwitch, RowWithTextField } from '@/lib/Layout';
import { RowWithSwitch, RowWithTextField } from '@/lib/Layout';
import { Switch } from '@/lib/Switch';
import { TextField } from '@/lib/TextField';
import ReactSelect from 'react-select';
import { InfoPopover } from '../../../../components/InfoPopover';
import { MirrorSetting } from '../helpers/common';

interface FieldProps {
setting: MirrorSetting;
handleChange: (val: string | boolean, setting: MirrorSetting) => void;
options?: string[];
}

const CDCField = ({ setting, handleChange, options }: FieldProps) => {
const CDCField = ({ setting, handleChange }: FieldProps) => {
return setting.type === 'switch' ? (
<RowWithSwitch
label={
<Label>
{setting.label}
{RequiredIndicator(setting.required)}
</Label>
}
label={<Label>{setting.label}</Label>}
action={
<div
style={{
Expand All @@ -42,40 +34,6 @@ const CDCField = ({ setting, handleChange, options }: FieldProps) => {
</div>
}
/>
) : setting.type === 'select' ? (
<RowWithSelect
label={
<Label>
{setting.label}
{RequiredIndicator(setting.required)}
</Label>
}
action={
<div
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<div style={{ width: '100%' }}>
<ReactSelect
placeholder={`Select a publication`}
onChange={(val, action) =>
val && handleChange(val.option, setting)
}
options={options?.map((option) => ({ option, label: option }))}
getOptionLabel={(option) => option.label}
getOptionValue={(option) => option.option}
theme={SelectTheme}
/>
</div>
{setting.tips && (
<InfoPopover tips={setting.tips} link={setting.helpfulLink} />
)}
</div>
}
/>
) : (
<RowWithTextField
label={
Expand Down
Loading
Loading