Skip to content

Commit

Permalink
use enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed May 6, 2024
1 parent fca9652 commit 857626d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
10 changes: 5 additions & 5 deletions ui/app/mirrors/create/cdc/cdc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Icon } from '@/lib/Icon';
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../../dto/MirrorsDTO';
import { IsQueuePeer, fetchPublications } from '../handlers';
import { MirrorSetting } from '../helpers/common';
import { AdvancedSettingType, MirrorSetting } from '../helpers/common';
import CDCField from './fields';
import TableMapping from './tablemapping';

Expand Down Expand Up @@ -50,8 +50,8 @@ export default function CDCConfigForm({
(setting) =>
!(
(IsQueuePeer(mirrorConfig.destination?.type) &&
setting.advanced === 'queue') ||
setting.advanced === true
setting.advanced === AdvancedSettingType.QUEUE) ||
setting.advanced === AdvancedSettingType.ALL
)
);
}, [settings, mirrorConfig.destination?.type]);
Expand All @@ -61,12 +61,12 @@ export default function CDCConfigForm({
.map((setting) => {
if (
IsQueuePeer(mirrorConfig.destination?.type) &&
setting.advanced === 'queue'
setting.advanced === AdvancedSettingType.QUEUE
) {
setting.stateHandler(600, setter);
return { ...setting, default: 600 };
}
if (setting.advanced === true) {
if (setting.advanced === AdvancedSettingType.ALL) {
return setting;
}
})
Expand Down
24 changes: 12 additions & 12 deletions ui/app/mirrors/create/helpers/cdc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TypeSystem } from '@/grpc_generated/flow';
import { CDCConfig } from '../../../dto/MirrorsDTO';
import { MirrorSetting } from './common';
import { AdvancedSettingType, MirrorSetting } from './common';
export const cdcSettings: MirrorSetting[] = [
{
label: 'Initial Copy',
Expand All @@ -24,7 +24,7 @@ export const cdcSettings: MirrorSetting[] = [
tips: 'The number of rows PeerDB will pull from source at a time. If left empty, the default value is 1,000,000 rows.',
type: 'number',
default: '1000000',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Sync Interval (Seconds)',
Expand All @@ -38,7 +38,7 @@ export const cdcSettings: MirrorSetting[] = [
type: 'number',
default: '60',
required: true,
advanced: 'queue',
advanced: AdvancedSettingType.QUEUE,
},
{
label: 'Publication Name',
Expand Down Expand Up @@ -72,7 +72,7 @@ export const cdcSettings: MirrorSetting[] = [
tips: 'PeerDB splits up table data into partitions for increased performance. This setting controls the number of rows per partition. The default value is 1000000.',
default: '1000000',
type: 'number',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Parallelism for Initial Load',
Expand All @@ -96,7 +96,7 @@ export const cdcSettings: MirrorSetting[] = [
tips: 'Specify the number of tables to sync perform initial load for, in parallel. The default value is 1.',
default: '1',
type: 'number',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Snapshot Staging Path',
Expand All @@ -106,7 +106,7 @@ export const cdcSettings: MirrorSetting[] = [
snapshotStagingPath: value as string | '',
})),
tips: 'You can specify staging path for Snapshot sync mode AVRO. For Snowflake as destination peer, this must be either empty or an S3 bucket URL. For BigQuery, this must be either empty or an existing GCS bucket name. In both cases, if empty, the local filesystem will be used.',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'CDC Staging Path',
Expand All @@ -116,7 +116,7 @@ export const cdcSettings: MirrorSetting[] = [
cdcStagingPath: (value as string) || '',
})),
tips: 'You can specify staging path for CDC sync mode AVRO. For Snowflake as destination peer, this must be either empty or an S3 bucket URL. For BigQuery, this must be either empty or an existing GCS bucket name. In both cases, if empty, the local filesystem will be used.',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Soft Delete',
Expand All @@ -139,7 +139,7 @@ export const cdcSettings: MirrorSetting[] = [
})),
tips: 'If set, PeerDB will only perform initial load and will not perform CDC sync.',
type: 'switch',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Script',
Expand All @@ -149,7 +149,7 @@ export const cdcSettings: MirrorSetting[] = [
script: (value as string) || '',
})),
tips: 'Associate PeerDB script with this mirror.',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Use Postgres type system',
Expand All @@ -161,7 +161,7 @@ export const cdcSettings: MirrorSetting[] = [
type: 'switch',
default: false,
tips: 'Decide if PeerDB should use native Postgres types directly',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Synced-At Column Name',
Expand All @@ -171,7 +171,7 @@ export const cdcSettings: MirrorSetting[] = [
syncedAtColName: value as string | '',
})),
tips: 'A field to set the name of PeerDBs synced_at column. If not set, a default name will be set',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
{
label: 'Soft Delete Column Name',
Expand All @@ -181,6 +181,6 @@ export const cdcSettings: MirrorSetting[] = [
softDeleteColName: value as string | '',
})),
tips: 'A field to set the name of PeerDBs soft delete column.',
advanced: true,
advanced: AdvancedSettingType.ALL,
},
];
7 changes: 6 additions & 1 deletion ui/app/mirrors/create/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { FlowConnectionConfigs, TypeSystem } from '@/grpc_generated/flow';

export type AdvancedSettingType = boolean | 'queue';
export enum AdvancedSettingType {
QUEUE = 'queue',
ALL = 'all',
NONE = 'none',
}

export interface MirrorSetting {
label: string;
stateHandler: (value: any, setter: any) => void;
Expand Down

0 comments on commit 857626d

Please sign in to comment.