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

fix generate schema table #779

Merged
merged 3 commits into from
Dec 6, 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
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