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

UI: Advanced section with pull batch size #822

Merged
merged 2 commits into from
Dec 14, 2023
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
116 changes: 48 additions & 68 deletions ui/app/mirrors/create/cdc/cdc.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use client';
import { RequiredIndicator } from '@/components/RequiredIndicator';
import { QRepSyncMode } from '@/grpc_generated/flow';
import { DBType } from '@/grpc_generated/peers';
import { Label } from '@/lib/Label';
import { RowWithSwitch, RowWithTextField } from '@/lib/Layout';
import { Switch } from '@/lib/Switch';
import { TextField } from '@/lib/TextField';
import { Dispatch, SetStateAction } from 'react';
import { InfoPopover } from '../../../../components/InfoPopover';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Dispatch, SetStateAction, useMemo, useState } from 'react';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../../dto/MirrorsDTO';
import { MirrorSetting } from '../helpers/common';
import CDCFields from './fields';
import TableMapping from './tablemapping';

interface MirrorConfigProps {
Expand Down Expand Up @@ -40,11 +37,20 @@ export default function CDCConfigForm({
rows,
setRows,
}: MirrorConfigProps) {
const [show, setShow] = useState(false);
const handleChange = (val: string | boolean, setting: MirrorSetting) => {
let stateVal: string | boolean | QRepSyncMode = val;
setting.stateHandler(stateVal, setter);
};

const normalSettings = useMemo(() => {
return settings.filter((setting) => setting.advanced != true);
}, [settings]);

const advancedSettings = useMemo(() => {
return settings.filter((setting) => setting.advanced == true);
}, [settings]);

const paramDisplayCondition = (setting: MirrorSetting) => {
const label = setting.label.toLowerCase();
if (
Expand All @@ -66,72 +72,46 @@ export default function CDCConfigForm({
setRows={setRows}
peerType={mirrorConfig.destination?.type}
/>
{settings.map((setting, id) => {
{normalSettings.map((setting, id) => {
return (
paramDisplayCondition(setting) &&
(setting.type === 'switch' ? (
<RowWithSwitch
key={id}
label={<Label>{setting.label}</Label>}
action={
<div
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<Switch
onCheckedChange={(state: boolean) =>
handleChange(state, setting)
}
/>
{setting.tips && (
<InfoPopover
tips={setting.tips}
link={setting.helpfulLink}
/>
)}
</div>
}
/>
) : (
<RowWithTextField
paramDisplayCondition(setting) && (
<CDCFields
key={id}
label={
<Label>
{setting.label}
{RequiredIndicator(setting.required)}
</Label>
}
action={
<div
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<TextField
variant='simple'
type={setting.type}
defaultValue={setting.default}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleChange(e.target.value, setting)
}
/>
{setting.tips && (
<InfoPopover
tips={setting.tips}
link={setting.helpfulLink}
/>
)}
</div>
}
handleChange={handleChange}
setting={setting}
/>
))
)
);
})}
<Button
className='IconButton'
aria-label='collapse'
onClick={() => {
setShow((prev) => !prev);
}}
style={{
width: '13em',
height: '2.5em',
marginTop: '2rem',
marginBottom: '1rem',
}}
>
<div style={{ display: 'flex', alignItems: 'center' }}>
<h3 style={{ marginRight: '10px' }}>Advanced Settings</h3>
<Icon name={`keyboard_double_arrow_${show ? 'up' : 'down'}`} />
</div>
</Button>

{show &&
advancedSettings.map((setting, id) => {
return (
<CDCFields
key={id}
handleChange={handleChange}
setting={setting}
/>
);
})}
</>
);
}
69 changes: 69 additions & 0 deletions ui/app/mirrors/create/cdc/fields.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use client';
import { RequiredIndicator } from '@/components/RequiredIndicator';
import { Label } from '@/lib/Label';
import { RowWithSwitch, RowWithTextField } from '@/lib/Layout';
import { Switch } from '@/lib/Switch';
import { TextField } from '@/lib/TextField';
import { InfoPopover } from '../../../../components/InfoPopover';
import { MirrorSetting } from '../helpers/common';

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

const CDCFields = ({ setting, handleChange }: FieldProps) => {
return setting.type === 'switch' ? (
<RowWithSwitch
label={<Label>{setting.label}</Label>}
action={
<div
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<Switch
onCheckedChange={(state: boolean) => handleChange(state, setting)}
/>
{setting.tips && (
<InfoPopover tips={setting.tips} link={setting.helpfulLink} />
)}
</div>
}
/>
) : (
<RowWithTextField
label={
<Label>
{setting.label}
{RequiredIndicator(setting.required)}
</Label>
}
action={
<div
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<TextField
variant='simple'
type={setting.type}
defaultValue={setting.default}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleChange(e.target.value, setting)
}
/>
{setting.tips && (
<InfoPopover tips={setting.tips} link={setting.helpfulLink} />
)}
</div>
}
/>
);
};

export default CDCFields;
12 changes: 12 additions & 0 deletions ui/app/mirrors/create/helpers/cdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ export const cdcSettings: MirrorSetting[] = [
tips: 'Specify if you want initial load to happen for your tables.',
type: 'switch',
},
{
label: 'Pull Batch Size',
stateHandler: (value, setter) =>
setter((curr: CDCConfig) => ({
...curr,
maxBatchSize: (value as boolean) || false,
})),
tips: 'The number of rows PeerDB will pull from source at a time. If left empty, the default value is 100,000 rows.',
type: 'number',
default: '100000',
advanced: true,
},
{
label: 'Publication Name',
stateHandler: (value, setter) =>
Expand Down
3 changes: 2 additions & 1 deletion ui/app/mirrors/create/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface MirrorSetting {
tips?: string;
helpfulLink?: string;
default?: string | number;
advanced?: boolean; // whether it should come under an 'Advanced' section
}

export const blankCDCSetting: FlowConnectionConfigs = {
Expand All @@ -27,7 +28,7 @@ export const blankCDCSetting: FlowConnectionConfigs = {
srcTableIdNameMapping: {},
tableNameSchemaMapping: {},
metadataPeer: undefined,
maxBatchSize: 0,
maxBatchSize: 100000,
doInitialCopy: false,
publicationName: '',
snapshotNumRowsPerPartition: 500000,
Expand Down
Loading