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-1618: Fixes IP Address Form, FK Col Rendering, JM Table Perf #2960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c582967
fixes learn more link to remove warning
nickzelei Nov 13, 2024
602390f
fixes ip address form error
nickzelei Nov 13, 2024
ee8ccc2
fixes ip address form
nickzelei Nov 13, 2024
d94cc7d
gets table and form working/rendering
nickzelei Nov 13, 2024
31be6be
smooth out transformer select close
nickzelei Nov 13, 2024
4bc3920
make column nicer
nickzelei Nov 13, 2024
3d9bf21
reduce amount of times that table model rerenders
nickzelei Nov 13, 2024
b6eed1e
fixes laggy searching
nickzelei Nov 13, 2024
12ce035
moves form out of job mappings table
nickzelei Nov 19, 2024
24b8d7c
gets datasyncconncard working
nickzelei Nov 19, 2024
517412a
optimizes table rendering speed
nickzelei Nov 19, 2024
bf28fe4
updating nosql table, data sync conn card compiling
nickzelei Nov 19, 2024
c781421
new job schema page compiling
nickzelei Nov 19, 2024
0b30c6d
gets single schema page compiling
nickzelei Nov 19, 2024
b05d8f9
gets nosql table working again
nickzelei Nov 19, 2024
c31ff19
more cleanup
nickzelei Nov 19, 2024
06c9845
minor cleanp
nickzelei Nov 19, 2024
be78865
Getting closer to finished
nickzelei Nov 20, 2024
0fd7896
memoizes rows
nickzelei Nov 20, 2024
837c69d
memoizes rows
nickzelei Nov 20, 2024
955db50
fixes foreign key rendering
nickzelei Nov 20, 2024
fadaca4
compiles data gen connection card
nickzelei Nov 20, 2024
9d3fd3d
consolelog
nickzelei Nov 20, 2024
c8d8750
fixes knip and build errors
nickzelei Nov 20, 2024
b3c8272
fixes more build errors
nickzelei Nov 20, 2024
e078c0f
fixes remainder of errors
nickzelei Nov 20, 2024
10f4fa1
pulls out on apply default click into hook
nickzelei Nov 20, 2024
4238b56
fixes hook to not be applied conditionally
nickzelei Nov 20, 2024
2b17e51
fixes another conditional hook
nickzelei Nov 20, 2024
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 @@ -5,6 +5,8 @@ import {
getAllFormErrors,
} 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 { Alert, AlertTitle } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';
Expand All @@ -25,8 +27,10 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { getErrorMessage } from '@/util/util';
import { useGetTransformersHandler } from '@/libs/hooks/useGetTransformersHandler';
import { getErrorMessage, getTransformerFromField } from '@/util/util';
import {
JobMappingTransformerForm,
convertJobMappingTransformerFormToJobMappingTransformer,
convertJobMappingTransformerToForm,
} from '@/yup-validations/jobs';
Expand Down Expand Up @@ -64,8 +68,12 @@ import {
validateJobMapping,
} from '../../../util';
import SchemaPageSkeleton from './SchemaPageSkeleton';
import { useOnApplyDefaultClick } from './useOnApplyDefaultClick';
import { useOnImportMappings } from './useOnImportMappings';
import { getOnSelectedTableToggle } from './util';
import {
getFilteredTransformersForBulkSet,
getOnSelectedTableToggle,
} from './util';

interface Props {
jobId: string;
Expand Down Expand Up @@ -138,7 +146,7 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement {
[isSchemaMapValidating, isTableConstraintsValidating]
);
const [selectedTables, setSelectedTables] = useState<Set<string>>(new Set());
const { append, remove, fields } =
const { append, remove, fields, update } =
useFieldArray<SingleTableEditSourceFormValues>({
control: form.control,
name: 'mappings',
Expand Down Expand Up @@ -220,6 +228,22 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement {
const { mutateAsync: validateJobMappingsAsync } =
useMutation(validateJobMappings);

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

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,
});
}

const { onClick: onImportMappingsClick } = useOnImportMappings({
setMappings(mappings) {
form.setValue('mappings', mappings, {
Expand Down Expand Up @@ -247,7 +271,45 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement {
setSelectedTables: setSelectedTables,
});

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

const { onClick: onApplyDefaultClick } = useOnApplyDefaultClick({
getMappings() {
return form.getValues('mappings');
},
setTransformer: onTransformerUpdate,
constraintHandler: schemaConstraintHandler,
triggerUpdate() {
form.trigger('mappings');
},
});

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

if (isJobLoading || isSchemaDataMapLoading || isGetTransformersLoading) {
return <SchemaPageSkeleton />;
}

Expand Down Expand Up @@ -466,6 +528,28 @@ export default function DataGenConnectionCard({ jobId }: Props): ReactElement {
isJobMappingsValidating={isValidatingMappings}
onValidate={validateMappings}
onImportMappingsClick={onImportMappingsClick}
onTransformerUpdate={(idx, cfg) => {
onTransformerUpdate(idx, cfg);
}}
getAvailableTransformers={getAvailableTransformers}
getTransformerFromField={(idx) => {
const row = fields[idx];
return getTransformerFromField(handler, row.transformer);
}}
getAvailableTransformersForBulk={(rows) => {
return getFilteredTransformersForBulkSet(
rows,
handler,
schemaConstraintHandler,
'generate',
'relational'
);
}}
getTransformerFromFieldValue={(fvalue) => {
return getTransformerFromField(handler, fvalue);
}}
onApplyDefaultClick={onApplyDefaultClick}
onTransformerBulkUpdate={onTransformerBulkUpdate}
/>

{form.formState.errors.mappings && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
getAllFormErrors,
} from '@/components/jobs/SchemaTable/SchemaTable';
import { getSchemaConstraintHandler } from '@/components/jobs/SchemaTable/schema-constraint-handler';
import { TransformerResult } from '@/components/jobs/SchemaTable/transformer-handler';
import {
getTransformerFilter,
splitCollection,
} from '@/components/jobs/SchemaTable/util';
import { useAccount } from '@/components/providers/account-provider';
import { Button } from '@/components/ui/button';
import {
Expand All @@ -25,12 +30,14 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { useGetTransformersHandler } from '@/libs/hooks/useGetTransformersHandler';
import { splitConnections } from '@/libs/utils';
import { getErrorMessage } from '@/util/util';
import { getErrorMessage, getTransformerFromField } from '@/util/util';
import {
DataSyncSourceFormValues,
EditDestinationOptionsFormValues,
JobMappingFormValues,
JobMappingTransformerForm,
VirtualForeignConstraintFormValues,
convertJobMappingTransformerFormToJobMappingTransformer,
convertJobMappingTransformerToForm,
Expand Down Expand Up @@ -87,11 +94,13 @@ import {
validateJobMapping,
} from '../../../util';
import SchemaPageSkeleton from './SchemaPageSkeleton';
import { useOnApplyDefaultClick } from './useOnApplyDefaultClick';
import { useOnImportMappings } from './useOnImportMappings';
import {
getConnectionIdFromSource,
getDestinationDetailsRecord,
getDynamoDbDestinations,
getFilteredTransformersForBulkSet,
getOnSelectedTableToggle,
isDynamoDBConnection,
isNosqlSource,
Expand Down Expand Up @@ -466,6 +475,22 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
[]
);

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

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,
});
}

const { onClick: onImportMappingsClick } = useOnImportMappings({
setMappings(mappings) {
form.setValue('mappings', mappings, {
Expand All @@ -480,13 +505,7 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
appendNewMappings(mappings) {
append(mappings);
},
setTransformer(idx, transformer) {
form.setValue(`mappings.${idx}.transformer`, transformer, {
shouldDirty: true,
shouldTouch: true,
shouldValidate: false,
});
},
setTransformer: onTransformerUpdate,
async triggerUpdate() {
await form.trigger('mappings');
setTimeout(() => {
Expand All @@ -497,7 +516,23 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
setSelectedTables: setSelectedTables,
});

if (isConnectionsLoading || isSchemaDataMapLoading || isJobDataLoading) {
const { onClick: onApplyDefaultClick } = useOnApplyDefaultClick({
getMappings() {
return form.getValues('mappings');
},
setTransformer: onTransformerUpdate,
constraintHandler: schemaConstraintHandler,
triggerUpdate() {
form.trigger('mappings');
},
});

if (
isConnectionsLoading ||
isSchemaDataMapLoading ||
isJobDataLoading ||
isGetTransformersLoading
) {
return <SchemaPageSkeleton />;
}

Expand All @@ -518,6 +553,34 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
c.connectionConfig?.config.case !== 'gcpCloudstorageConfig'
)
);

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 onTransformerBulkUpdate(
indices: number[],
config: JobMappingTransformerForm
): void {
indices.forEach((idx) => {
onTransformerUpdate(idx, config);
});
setTimeout(() => {
form.trigger('mappings');
}, 0);
}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
Expand Down Expand Up @@ -588,34 +651,20 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
validateMappingsResponse
)}
onValidate={validateMappings}
constraintHandler={schemaConstraintHandler}
onRemoveMappings={(values) => {
const valueSet = new Set(
values.map((v) => `${v.schema}.${v.table}.${v.column}`)
);
const toRemove: number[] = [];
formMappings.forEach((mapping, idx) => {
if (
valueSet.has(
`${mapping.schema}.${mapping.table}.${mapping.column}`
)
) {
toRemove.push(idx);
}
});
if (toRemove.length > 0) {
remove(toRemove);
onRemoveMappings={(indices) => {
const indexSet = new Set(indices);
const remainingTables = formMappings
.filter((_, idx) => !indexSet.has(idx))
.map((fm) => fm.table);

if (indices.length > 0) {
remove(indices);
}

if (!source || isDynamoDBConnection(source)) {
return;
}

const toRemoveSet = new Set(toRemove);
const remainingTables = formMappings
.filter((_, idx) => !toRemoveSet.has(idx))
.map((fm) => fm.table);

// Check and update destinationOptions if needed
const destOpts = form.getValues('destinationOptions');
const updatedDestOpts = destOpts
Expand Down Expand Up @@ -653,7 +702,7 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
onAddMappings={(values) => {
append(
values.map((v) => {
const [schema, table] = v.collection.split('.');
const [schema, table] = splitCollection(v.collection);
return {
schema,
table,
Expand Down Expand Up @@ -734,6 +783,25 @@ export default function DataSyncConnectionCard({ jobId }: Props): ReactElement {
dynamoDBDestinations.length > 0
)}
onImportMappingsClick={onImportMappingsClick}
getAvailableTransformers={getAvailableTransformers}
getTransformerFromField={(idx) => {
const row = formMappings[idx];
return getTransformerFromField(handler, row.transformer);
}}
getAvailableTransformersForBulk={(rows) => {
return getFilteredTransformersForBulkSet(
rows,
handler,
schemaConstraintHandler,
'sync',
'nosql'
);
}}
getTransformerFromFieldValue={(fvalue) => {
return getTransformerFromField(handler, fvalue);
}}
onApplyDefaultClick={onApplyDefaultClick}
onTransformerBulkUpdate={onTransformerBulkUpdate}
/>
)}

Expand All @@ -757,6 +825,28 @@ export default function DataSyncConnectionCard({ jobId }: Props): 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',
'relational'
);
}}
getTransformerFromFieldValue={(fvalue) => {
return getTransformerFromField(handler, fvalue);
}}
onApplyDefaultClick={onApplyDefaultClick}
onTransformerBulkUpdate={onTransformerBulkUpdate}
/>
)}
<div className="flex flex-row items-center justify-end w-full mt-4">
Expand Down
Loading