Skip to content

Commit

Permalink
fix: defaults for table map
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Nov 7, 2023
1 parent 3e074b8 commit f9db619
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions ui/app/mirrors/create/tablemapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ const TableMapping = ({
// find the row with source and update the destination
const newRows = [...rows];
const index = newRows.findIndex((row) => row.source === source);
let dstName = peerType == DBType.BIGQUERY ? dest : `${schema}.${dest}`;
newRows[index].destination = dstName;
newRows[index].destination = dest;
return newRows;
};

Expand All @@ -95,14 +94,22 @@ const TableMapping = ({
fetchTables(sourcePeerName, schemaName, setLoading).then((tableNames) =>
setRows((curr) => {
const newRows = [...curr];

tableNames.forEach((tableName) => {
const row = newRows.find(
(row) => row.source === `${schemaName}.${tableName}`
);
if (!row) {
const dstName =
peerType != undefined && dBTypeToJSON(peerType) == 'BIGQUERY'
? tableName
: `${schemaName}.${tableName}`;
newRows.push({
source: `${schemaName}.${tableName}`,
destination: `${schemaName}.${tableName}`,
destination:
peerType != undefined && dBTypeToJSON(peerType) == 'BIGQUERY'
? tableName
: `${schemaName}.${tableName}`,
partitionKey: '',
selected: false,
});
Expand All @@ -112,7 +119,7 @@ const TableMapping = ({
})
);
},
[sourcePeerName, setRows]
[sourcePeerName, setRows, peerType]
);

const [searchQuery, setSearchQuery] = useState('');
Expand All @@ -121,6 +128,36 @@ const TableMapping = ({
return row.source.toLowerCase().includes(searchQuery.toLowerCase());
});

useEffect(() => {
if (peerType != undefined && dBTypeToJSON(peerType) == 'BIGQUERY') {
setRows((rows) => {
const newRows = [...rows];
newRows.forEach((_, i) => {
const row = newRows[i];
newRows[i] = {
...row,
destination: row.destination.split('.')[1],
};
});
return newRows;
});
} else {
setRows((rows) => {
const newRows = [...rows];
newRows.forEach((_, i) => {
const row = newRows[i];
newRows[i] = {
...row,
destination: `${schema}.${
row.destination.split('.')[1] || row.destination
}`,
};
});
return newRows;
});
}
}, [peerType, setRows, schema]);

useEffect(() => {
fetchSchemas(sourcePeerName, setLoading).then((res) => setAllSchemas(res));
setSchema('public');
Expand Down

0 comments on commit f9db619

Please sign in to comment.