Skip to content

Commit

Permalink
new job schema page compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Nov 19, 2024
1 parent bf28fe4 commit c781421
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,6 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
index: number,
transformer: JobMappingTransformerForm
): void {
// form.setValue(`mappings.${index}.transformer`, transformer, {
// shouldDirty: true,
// shouldTouch: true,
// shouldValidate: false, // this is intentional!
// });
const val = form.getValues(`mappings.${index}`);
update(index, {
schema: val.schema,
Expand Down
135 changes: 134 additions & 1 deletion frontend/apps/web/app/(mgmt)/[account]/new/job/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import {
SchemaTable,
} from '@/components/jobs/SchemaTable/SchemaTable';
import { getSchemaConstraintHandler } from '@/components/jobs/SchemaTable/schema-constraint-handler';
import { TransformerResult } from '@/components/jobs/SchemaTable/transformer-handler';
import { getTransformerFilter } from '@/components/jobs/SchemaTable/util';
import { useAccount } from '@/components/providers/account-provider';
import SkeletonForm from '@/components/skeleton/SkeletonForm';
import { PageProps } from '@/components/types';
import { Button } from '@/components/ui/button';
import { Form } from '@/components/ui/form';
import { useGetTransformersHandler } from '@/libs/hooks/useGetTransformersHandler';
import { getSingleOrUndefined } from '@/libs/utils';
import { getErrorMessage } from '@/util/util';
import { getErrorMessage, getTransformerFromField } from '@/util/util';
import {
convertJobMappingTransformerToForm,
JobMappingTransformerForm,
SchemaFormValues,
SchemaFormValuesDestinationOptions,
VirtualForeignConstraintFormValues,
Expand All @@ -29,9 +34,13 @@ import {
Connection,
DatabaseColumn,
ForeignConstraintTables,
GenerateDefault,
GetConnectionSchemaMapRequest,
GetConnectionSchemaMapsResponse,
JobMappingTransformer,
Passthrough,
PrimaryConstraint,
TransformerConfig,
ValidateJobMappingsResponse,
VirtualForeignConstraint,
VirtualForeignKey,
Expand All @@ -54,6 +63,7 @@ import { useSessionStorage } from 'usehooks-ts';
import { useOnImportMappings } from '../../../jobs/[id]/source/components/useOnImportMappings';
import {
getDestinationDetailsRecord,
getFilteredTransformersForBulkSet,
getOnSelectedTableToggle,
isConnectionSubsettable,
isDynamoDBConnection,
Expand Down Expand Up @@ -406,6 +416,10 @@ export default function Page({ searchParams }: PageProps): ReactElement {
setSelectedTables: setSelectedTables,
});

const { handler, isLoading, isValidating } = useGetTransformersHandler(
account?.id ?? ''
);

if (isConnectionLoading || isSchemaMapLoading) {
return <SkeletonForm />;
}
Expand All @@ -427,6 +441,86 @@ export default function Page({ searchParams }: PageProps): ReactElement {
}))
: [];

function getAvailableTransformers(idx: number): TransformerResult {
const row = formMappings[idx];
return handler.getFilteredTransformers(
getTransformerFilter(
schemaConstraintHandler,
{
schema: row.schema,
table: row.table,
column: row.column,
},
'sync'
)
);
}

function onTransformerUpdate(
index: number,
transformer: JobMappingTransformerForm
): void {
const val = form.getValues(`mappings.${index}`);
update(index, {
schema: val.schema,
table: val.table,
column: val.column,
transformer,
});
}

function onApplyDefaultClick(override: boolean): void {
const formMappings = form.getValues('mappings');
formMappings.forEach((fm, idx) => {
// skips setting the default transformer if the user has already set the transformer
if (fm.transformer.config.case && !override) {
return;
} else {
const colkey = {
schema: fm.schema,
table: fm.table,
column: fm.column,
};
const isGenerated = schemaConstraintHandler.getIsGenerated(colkey);
const identityType = schemaConstraintHandler.getIdentityType(colkey);
const newJm =
isGenerated && !identityType
? new JobMappingTransformer({
config: new TransformerConfig({
config: {
case: 'generateDefaultConfig',
value: new GenerateDefault(),
},
}),
})
: new JobMappingTransformer({
config: new TransformerConfig({
config: {
case: 'passthroughConfig',
value: new Passthrough(),
},
}),
});
onTransformerUpdate(idx, convertJobMappingTransformerToForm(newJm));
}
});
setTimeout(() => {
form.trigger('mappings');
}, 0);
}

function onTransformerBulkUpdate(
indices: number[],
config: JobMappingTransformerForm
): void {
indices.forEach((idx) => {
onTransformerUpdate(idx, config);
});
setTimeout(() => {
form.trigger('mappings');
}, 0);
}

return (
<div className="flex flex-col gap-5">
<FormPersist formKey={schemaFormKey} form={form} />
Expand Down Expand Up @@ -595,6 +689,24 @@ export default function Page({ searchParams }: PageProps): ReactElement {
)}
destinationOptions={form.watch('destinationOptions')}
onImportMappingsClick={onImportMappingsClick}
getAvailableTransformers={getAvailableTransformers}
getTransformerFromField={(idx) => {
const row = formMappings[idx];
return getTransformerFromField(handler, row.transformer);
}}
getAvailableTransformersForBulk={(rows) => {
return getFilteredTransformersForBulkSet(
rows,
handler,
schemaConstraintHandler,
'sync'
);
}}
getTransformerFromFieldValue={(fvalue) => {
return getTransformerFromField(handler, fvalue);
}}
onApplyDefaultClick={onApplyDefaultClick}
onTransformerBulkUpdate={onTransformerBulkUpdate}
/>
)}

Expand All @@ -618,6 +730,27 @@ export default function Page({ searchParams }: PageProps): ReactElement {
addVirtualForeignKey={addVirtualForeignKey}
removeVirtualForeignKey={removeVirtualForeignKey}
onImportMappingsClick={onImportMappingsClick}
onTransformerUpdate={(idx, cfg) => {
onTransformerUpdate(idx, cfg);
}}
getAvailableTransformers={getAvailableTransformers}
getTransformerFromField={(idx) => {
const row = formMappings[idx];
return getTransformerFromField(handler, row.transformer);
}}
getAvailableTransformersForBulk={(rows) => {
return getFilteredTransformersForBulkSet(
rows,
handler,
schemaConstraintHandler,
'sync'
);
}}
getTransformerFromFieldValue={(fvalue) => {
return getTransformerFromField(handler, fvalue);
}}
onApplyDefaultClick={onApplyDefaultClick}
onTransformerBulkUpdate={onTransformerBulkUpdate}
/>
)}
<div className="flex flex-row gap-1 justify-between">
Expand Down

0 comments on commit c781421

Please sign in to comment.