Skip to content

Commit

Permalink
NEOS-404: Data gen warning (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
evisdrenova authored Dec 4, 2023
1 parent 3404bdd commit be21707
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion frontend/app/jobs/[id]/components/JobPauseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function JobPauseButton({
await pauseJob(jobId, isPaused);
toast({
title: `Successfully ${isPaused ? 'paused' : 'unpaused'} job!`,
variant: 'default',
variant: 'success',
});
mutate();
setIsTrying(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/jobs/[id]/components/ScheduleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function JobScheduleCard({ job, mutate }: Props): ReactElement {
await updateJobSchedule(job.id, values.cronSchedule);
toast({
title: 'Successfully updated job schedule!',
variant: 'default',
variant: 'success',
});
mutate();
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function DestinationConnectionCard({
mutate();
toast({
title: 'Successfully updated job destination!',
variant: 'default',
variant: 'success',
});
} catch (err) {
console.error(err);
Expand All @@ -87,7 +87,7 @@ export default function DestinationConnectionCard({
mutate();
toast({
title: 'Successfully deleted job destination!',
variant: 'default',
variant: 'success',
});
} catch (err) {
console.error(err);
Expand Down
1 change: 1 addition & 0 deletions frontend/app/jobs/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function JobIdLayout({ children, params }: LayoutProps) {
await triggerJobRun(id);
toast({
title: 'Job run triggered successfully!',
variant: 'success',
});
router.push(`/jobs/${id}`);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement {
await updateJobConnection(job, values);
toast({
title: 'Successfully updated job source connection!',
variant: 'default',
variant: 'success',
});
mutate();
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/jobs/[id]/subsets/components/SubsetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function SubsetCard(props: Props): ReactElement {
const updatedJobRes = await setJobSubsets(jobId, values);
toast({
title: 'Successfully updated database subsets',
variant: 'default',
variant: 'success',
});
mutateJob(
new GetJobResponse({
Expand Down
54 changes: 39 additions & 15 deletions frontend/app/new/job/generate/single/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ import { getErrorMessage } from '@/util/util';
import { toJobDestinationOptions } from '@/yup-validations/jobs';
import { yupResolver } from '@hookform/resolvers/yup';
import { useRouter } from 'next/navigation';
import { ReactElement, useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { ReactElement, useEffect, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import useFormPersist from 'react-hook-form-persist';
import { useSessionStorage } from 'usehooks-ts';
import JobsProgressSteps, { DATA_GEN_STEPS } from '../../../JobsProgressSteps';
Expand All @@ -79,14 +79,6 @@ export default function Page({ searchParams }: PageProps): ReactElement {
const { data: connectionsData } = useGetConnections(account?.id ?? '');
const connections = connectionsData?.connections ?? [];

// const { data: st } = useGetSystemTransformers();
// const { data: udt } = useGetUserDefinedTransformers(account?.id ?? '');

// const udts = udt?.transformers ?? [];
// const sts = st?.transformers ?? [];

// const merged = MergeSystemAndCustomTransformers(sts, udts);

const sessionPrefix = searchParams?.sessionId ?? '';

// Used to complete the whole form
Expand Down Expand Up @@ -171,7 +163,9 @@ export default function Page({ searchParams }: PageProps): ReactElement {
resolver: yupResolver<SingleTableSchemaFormValues>(
SINGLE_TABLE_SCHEMA_FORM_SCHEMA
),
defaultValues: async () => getSchema(),
defaultValues: async () => {
return getSchema();
},
});

useFormPersist(formKey, {
Expand Down Expand Up @@ -227,6 +221,19 @@ export default function Page({ searchParams }: PageProps): ReactElement {
const schemaTableMap = getSchemaTableMap(connSchemaData?.schemas ?? []);

const selectedSchemaTables = schemaTableMap.get(formValues.schema) ?? [];

/* turning the input field into a controlled component due to console warning a component going from uncontrolled to controlled. The input at first receives an undefined value because the async getSchema() call hasn't returned yet then once it returns it sets the value which throws the error. Ideally, react hook form should just handle this but for some reason it's throwing an error. Revist this in the future.
*/

const [rowNum, setRowNum] = useState<number>(
form.getValues('numRows')
? form.getValues('numRows')
: defaultValues.numRows
);
useEffect(() => {
form.setValue(`numRows`, rowNum);
}, [rowNum]);

return (
<div className="flex flex-col gap-20">
<OverviewContainer
Expand Down Expand Up @@ -314,17 +321,22 @@ export default function Page({ searchParams }: PageProps): ReactElement {
)}
/>

<FormField
<Controller
control={form.control}
name="numRows"
render={({ field }) => (
render={() => (
<FormItem>
<FormLabel>Number of Rows</FormLabel>
<FormDescription>
The number of rows to generate.
</FormDescription>
<FormControl>
<Input value={field.value} />
<Input
value={rowNum}
onChange={(e) => {
setRowNum(Number(e.target.value));
}}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand Down Expand Up @@ -364,11 +376,22 @@ async function createNewJob(
cronSchedule: define.cronSchedule,
initiateJobRun: define.initiateJobRun,
mappings: schema.mappings.map((m) => {
const jmt = new JobMappingTransformer({
name: m.transformer.name,
source: m.transformer.source,
config: new TransformerConfig({
config: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
case: m.transformer.config.config.case as any,
value: m.transformer.config.config.value,
},
}),
});
return new JobMapping({
schema: schema.schema,
table: schema.table,
column: m.column,
transformer: JobMappingTransformer.fromJson(m.transformer),
transformer: jmt,
});
}),
source: new JobSource({
Expand Down Expand Up @@ -402,6 +425,7 @@ async function createNewJob(
}),
],
});

const res = await fetch(`/api/jobs`, {
method: 'POST',
headers: {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/new/job/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function Page({ searchParams }: PageProps): ReactElement {
return getSchema();
},
});

const isBrowser = () => typeof window !== 'undefined';

useFormPersist(`${sessionPrefix}-new-job-schema`, {
Expand Down
1 change: 0 additions & 1 deletion frontend/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default function AccountSwitcher(_: Props): ReactElement {
mutate();
toast({
title: 'Successfully created team!',
variant: 'success',
});
} catch (err) {
console.error(err);
Expand Down
4 changes: 2 additions & 2 deletions worker/pkg/workflows/datasync/activities/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func computeMutationFunction(col *mgmtv1alpha1.JobMapping) (string, error) {
return "generate_bool()", nil
case "generate_card_number":
luhn := col.Transformer.Config.GetGenerateCardNumberConfig().ValidLuhn
return fmt.Sprintf(`generate_cardnumber(valid_luhn:%t)`, luhn), nil
return fmt.Sprintf(`generate_card_number(valid_luhn:%t)`, luhn), nil
case "generate_city":
return "generate_city()", nil
case "generate_e164_number":
Expand All @@ -648,7 +648,7 @@ func computeMutationFunction(col *mgmtv1alpha1.JobMapping) (string, error) {
sign := col.Transformer.Config.GetGenerateFloatConfig().Sign
bd := col.Transformer.Config.GetGenerateFloatConfig().DigitsBeforeDecimal
ad := col.Transformer.Config.GetGenerateFloatConfig().DigitsAfterDecimal
return fmt.Sprintf(`generate_float(sign:%q, digits_before__formdecimal:%d, digits_after_decimal:%d)`, sign, bd, ad), nil
return fmt.Sprintf(`generate_float(sign:%q, digits_before_decimal:%d, digits_after_decimal:%d)`, sign, bd, ad), nil
case "generate_full_address":
return "generate_full_address()", nil
case "generate_full_name":
Expand Down

0 comments on commit be21707

Please sign in to comment.