From a70174a3821e521e2a940400dc248fa926fc7fc9 Mon Sep 17 00:00:00 2001 From: Evis Drenova Date: Mon, 4 Dec 2023 13:46:21 -0800 Subject: [PATCH 1/2] fixed retianing data from page to page and updated transformer --- .../components/DataGenConnectionCard.tsx | 2 +- .../new/job/generate/single/schema/page.tsx | 70 +++++++++++-------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/frontend/app/jobs/[id]/source/components/DataGenConnectionCard.tsx b/frontend/app/jobs/[id]/source/components/DataGenConnectionCard.tsx index e8bea6245d..8394a0bd66 100644 --- a/frontend/app/jobs/[id]/source/components/DataGenConnectionCard.tsx +++ b/frontend/app/jobs/[id]/source/components/DataGenConnectionCard.tsx @@ -106,7 +106,7 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement { } } - // changed to getValues() from watch because watch would listen for a change and then trigger a render which would overwrite the values that were changed (which we wanted to keep) + // changed to getValues() from watch() because watch would listen for a change and then trigger a render which would overwrite the values that were changed (which we wanted to keep) const formValues = form.getValues(); const schemaTableData = formValues.mappings?.map((mapping) => ({ diff --git a/frontend/app/new/job/generate/single/schema/page.tsx b/frontend/app/new/job/generate/single/schema/page.tsx index 87c0f55147..18a0b23298 100644 --- a/frontend/app/new/job/generate/single/schema/page.tsx +++ b/frontend/app/new/job/generate/single/schema/page.tsx @@ -45,10 +45,7 @@ import { JobSource, JobSourceOptions, } from '@/neosync-api-client/mgmt/v1alpha1/job_pb'; -import { - Passthrough, - TransformerConfig, -} from '@/neosync-api-client/mgmt/v1alpha1/transformer_pb'; +import { TransformerConfig } from '@/neosync-api-client/mgmt/v1alpha1/transformer_pb'; import { getErrorMessage } from '@/util/util'; import { toJobDestinationOptions } from '@/yup-validations/jobs'; import { yupResolver } from '@hookform/resolvers/yup'; @@ -120,34 +117,47 @@ export default function Page({ searchParams }: PageProps): ReactElement { return defaultValues; } - return { - ...defaultValues, - mappings: res.schemas.map((r) => { - var pt = new JobMappingTransformer({ - source: 'passthrough', - name: 'passthrough', - config: new TransformerConfig({ - config: { - case: 'passthroughConfig', - value: new Passthrough({}), - }, - }), - }) as { - source: string; - name: string; - config: { + if (defaultValues.mappings.length > 0) { + //pull values from default values for transformers if already set + return { + ...defaultValues, + mappings: res.schemas.map((r) => { + const mappingTransformer = defaultValues.mappings.find( + (item) => item.column == r.column + ); + + var pt = mappingTransformer?.transformer as { + source: string; + name: string; config: { - case?: string; - value: {}; + config: { + case?: string; + value: {}; + }; }; }; - }; - return { - ...r, - transformer: pt, - }; - }), - }; + return { + ...r, + transformer: pt, + }; + }), + }; + } else { + //return empty transformers because they haven't been set yet + return { + ...defaultValues, + mappings: res.schemas.map((r) => { + return { + ...r, + transformer: { + name: '', + source: '', + config: { config: { case: '', value: {} } }, + }, + }; + }), + }; + } } catch (err) { console.error(err); toast({ @@ -208,6 +218,8 @@ export default function Page({ searchParams }: PageProps): ReactElement { } } + console.log('errors', form.formState.errors); + const formValues = form.watch(); const schemaTableData = formValues.mappings?.map((mapping) => ({ ...mapping, From 61a3c07c75d0b355637c58149610b04e07fc3f7a Mon Sep 17 00:00:00 2001 From: Evis Drenova Date: Mon, 4 Dec 2023 14:14:32 -0800 Subject: [PATCH 2/2] updated transformer name --- frontend/app/new/job/generate/single/schema/page.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/app/new/job/generate/single/schema/page.tsx b/frontend/app/new/job/generate/single/schema/page.tsx index 18a0b23298..d9d5aa494b 100644 --- a/frontend/app/new/job/generate/single/schema/page.tsx +++ b/frontend/app/new/job/generate/single/schema/page.tsx @@ -150,7 +150,7 @@ export default function Page({ searchParams }: PageProps): ReactElement { return { ...r, transformer: { - name: '', + name: 'Select a Transformer', // revisit this in the future, we should be rendering the form errors instead, since a user can't set passthrough as an option here source: '', config: { config: { case: '', value: {} } }, }, @@ -218,8 +218,6 @@ export default function Page({ searchParams }: PageProps): ReactElement { } } - console.log('errors', form.formState.errors); - const formValues = form.watch(); const schemaTableData = formValues.mappings?.map((mapping) => ({ ...mapping,