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

NEOS-406: fixed retianing data from page to page and updated transformer #729

Merged
merged 2 commits into from
Dec 4, 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
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