Skip to content

Commit

Permalink
NEOS-406: fixed retianing data from page to page and updated transfor…
Browse files Browse the repository at this point in the history
…mer (#729)
  • Loading branch information
evisdrenova authored Dec 4, 2023
1 parent e71609d commit 89573a1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down
68 changes: 39 additions & 29 deletions frontend/app/new/job/generate/single/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: '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: {} } },
},
};
}),
};
}
} catch (err) {
console.error(err);
toast({
Expand Down

0 comments on commit 89573a1

Please sign in to comment.