Skip to content

Commit

Permalink
fixing destination form
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Jul 29, 2024
1 parent 4480c6a commit 26a1f24
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export default function DestinationConnectionCard({
);

const form = useForm({
resolver: yupResolver<DestinationFormValues>(NewDestinationFormValues),
resolver: yupResolver<NewDestinationFormValues>(NewDestinationFormValues),
values: getDefaultDestinationFormValues(destination),
});

async function onSubmit(values: DestinationFormValues) {
async function onSubmit(values: NewDestinationFormValues) {
try {
const connection = connections.find((c) => c.id === values.connectionId);
await setJobDestConnection({
Expand Down Expand Up @@ -124,6 +124,7 @@ export default function DestinationConnectionCard({
form.control,
jobSourceId
);
console.log(form.formState.errors, form.formState.isValid);
return (
<Card>
<Form {...form}>
Expand All @@ -141,12 +142,7 @@ export default function DestinationConnectionCard({
field.onChange(value);
form.setValue(
`destinationOptions`,
{
truncateBeforeInsert: false,
truncateCascade: false,
initTableSchema: false,
onConflictDoNothing: false,
},
{},
{
shouldDirty: true,
shouldTouch: true,
Expand Down Expand Up @@ -183,27 +179,13 @@ export default function DestinationConnectionCard({
connection={connections.find(
(c) => c.id === form.getValues().connectionId
)}
value={{
initTableSchema: destOpts.initTableSchema ?? false,
onConflictDoNothing: destOpts.onConflictDoNothing ?? false,
truncateBeforeInsert: destOpts.truncateBeforeInsert ?? false,
truncateCascade: destOpts.truncateCascade ?? false,
}}
value={destOpts}
setValue={(newOpts) => {
form.setValue(
'destinationOptions',
{
initTableSchema: newOpts.initTableSchema,
onConflictDoNothing: newOpts.onConflictDoNothing,
truncateBeforeInsert: newOpts.truncateBeforeInsert,
truncateCascade: newOpts.truncateCascade,
},
{
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
}
);
form.setValue('destinationOptions', newOpts, {
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
});
}}
hideInitTableSchema={shouldHideInitTableSchema}
/>
Expand Down Expand Up @@ -231,7 +213,7 @@ export default function DestinationConnectionCard({
}

function useShouldHideInitConnectionSchema(
control: Control<DestinationFormValues>,
control: Control<NewDestinationFormValues>,
sourceId: string
): boolean {
const [destinationConnectionid] = useWatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,7 @@ export default function Page({ params }: PageProps): ReactElement {
);
form.setValue(
`destinations.${index}.destinationOptions`,
{
truncateBeforeInsert: false,
truncateCascade: false,
initTableSchema: false,
onConflictDoNothing: false,
}
{}
);
}}
value={field.value}
Expand Down Expand Up @@ -205,23 +200,11 @@ export default function Page({ params }: PageProps): ReactElement {

<DestinationOptionsForm
connection={currConnection}
value={{
initTableSchema: destOpts.initTableSchema ?? false,
onConflictDoNothing:
destOpts.onConflictDoNothing ?? false,
truncateBeforeInsert:
destOpts.truncateBeforeInsert ?? false,
truncateCascade: destOpts.truncateCascade ?? false,
}}
value={destOpts}
setValue={(newOpts) => {
form.setValue(
`destinations.${index}.destinationOptions`,
{
initTableSchema: newOpts.initTableSchema,
onConflictDoNothing: newOpts.onConflictDoNothing,
truncateBeforeInsert: newOpts.truncateBeforeInsert,
truncateCascade: newOpts.truncateCascade,
},
newOpts,
{
shouldDirty: true,
shouldTouch: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,7 @@ export default function Page({ searchParams }: PageProps): ReactElement {
return;
}
field.onChange(value);
form.setValue('destination.destinationOptions', {
initTableSchema: false,
truncateBeforeInsert: false,
truncateCascade: false,
onConflictDoNothing: false,
});
form.setValue('destination.destinationOptions', {});
}}
value={field.value}
>
Expand All @@ -377,27 +372,13 @@ export default function Page({ searchParams }: PageProps): ReactElement {
(c) => c.id === form.getValues().destination.connectionId
)}
hideInitTableSchema={shouldHideInitTableSchema}
value={{
initTableSchema: destOpts.initTableSchema ?? false,
onConflictDoNothing: destOpts.onConflictDoNothing ?? false,
truncateBeforeInsert: destOpts.truncateBeforeInsert ?? false,
truncateCascade: destOpts.truncateCascade ?? false,
}}
value={destOpts}
setValue={(newOpts) => {
form.setValue(
'destination.destinationOptions',
{
initTableSchema: newOpts.initTableSchema,
onConflictDoNothing: newOpts.onConflictDoNothing,
truncateBeforeInsert: newOpts.truncateBeforeInsert,
truncateCascade: newOpts.truncateCascade,
},
{
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
}
);
form.setValue('destination.destinationOptions', newOpts, {
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
});
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,7 @@ export default function Page({ searchParams }: PageProps): ReactElement {
return;
}
field.onChange(value);
form.setValue('destination.destinationOptions', {
initTableSchema: false,
truncateBeforeInsert: false,
truncateCascade: false,
onConflictDoNothing: false,
});
form.setValue('destination.destinationOptions', {});
}}
value={field.value}
>
Expand All @@ -282,27 +277,13 @@ export default function Page({ searchParams }: PageProps): ReactElement {
(c) => c.id === form.getValues().destination.connectionId
)}
hideInitTableSchema={shouldHideInitTableSchema}
value={{
initTableSchema: destOpts.initTableSchema ?? false,
onConflictDoNothing: destOpts.onConflictDoNothing ?? false,
truncateBeforeInsert: destOpts.truncateBeforeInsert ?? false,
truncateCascade: destOpts.truncateCascade ?? false,
}}
value={destOpts}
setValue={(newOpts) => {
form.setValue(
'destination.destinationOptions',
{
initTableSchema: newOpts.initTableSchema,
onConflictDoNothing: newOpts.onConflictDoNothing,
truncateBeforeInsert: newOpts.truncateBeforeInsert,
truncateCascade: newOpts.truncateCascade,
},
{
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
}
);
form.setValue('destination.destinationOptions', newOpts, {
shouldDirty: true,
shouldTouch: true,
shouldValidate: true,
});
}}
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/apps/web/yup-validations/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const DynamoDbDestinationOptionsFormValues = Yup.object({
destinationTable: Yup.string().required(),
}).required()
)
.required(),
.required()
.default([]),
});
type DynamoDbDestinationOptionsFormValues = Yup.InferType<
typeof DynamoDbDestinationOptionsFormValues
Expand Down

0 comments on commit 26a1f24

Please sign in to comment.