Skip to content

Commit

Permalink
fix generate schema table (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi authored Dec 6, 2023
1 parent d7a5cd7 commit cca8ed4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions frontend/app/new/job/generate/single/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ export default function Page({ searchParams }: PageProps): ReactElement {
}
);

const [allMappings, setAllMappings] = useState<DatabaseColumn[]>([]);
async function getSchema(): Promise<SingleTableSchemaFormValues> {
try {
const res = await getConnectionSchema(connectFormValues.connectionId);
if (!res) {
return { mappings: [], numRows: 10, schema: '', table: '' };
}

const allJobMappings = res.schemas.map((r) => {
return {
...r,
transformer: new JobMappingTransformer({}) as TransformerFormValues,
};
});
setAllMappings(res.schemas);
if (schemaFormData.mappings.length > 0) {
//pull values from default values for transformers if already set
return {
Expand All @@ -135,17 +143,9 @@ export default function Page({ searchParams }: PageProps): ReactElement {
}),
};
} else {
//return empty transformers because they haven't been set yet
return {
...schemaFormData,
mappings: res.schemas.map((r) => {
return {
...r,
transformer: new JobMappingTransformer(
{}
) as TransformerFormValues,
};
}),
mappings: allJobMappings,
};
}
} catch (err) {
Expand Down Expand Up @@ -308,6 +308,23 @@ export default function Page({ searchParams }: PageProps): ReactElement {
onValueChange={(value: string) => {
if (value) {
field.onChange(value);
form.setValue(
'mappings',
allMappings
.filter(
(m) =>
m.schema == formValues.schema &&
m.table == value
)
.map((r) => {
return {
...r,
transformer: new JobMappingTransformer(
{}
) as TransformerFormValues,
};
})
);
}
}}
value={field.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function VirtualizedSchemaList({
width={width}
itemKey={(index: number) => {
const r = rows[index];
return `${r.schema}-${r.table}-${r.column}`;
return `${r.schema}-${r.table}-${r.column}-${index}`;
}}
>
{Row}
Expand Down

0 comments on commit cca8ed4

Please sign in to comment.