From 54ba60276c386e4e6459e11261598a15aa0f98ff Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Tue, 7 Nov 2023 03:44:10 -0500 Subject: [PATCH] fix: defaults for table map --- ui/app/mirrors/create/tablemapping.tsx | 42 ++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/ui/app/mirrors/create/tablemapping.tsx b/ui/app/mirrors/create/tablemapping.tsx index 248d0489c2..26d0dd1129 100644 --- a/ui/app/mirrors/create/tablemapping.tsx +++ b/ui/app/mirrors/create/tablemapping.tsx @@ -94,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, }); @@ -111,7 +119,7 @@ const TableMapping = ({ }) ); }, - [sourcePeerName, setRows] + [sourcePeerName, setRows, peerType] ); const [searchQuery, setSearchQuery] = useState(''); @@ -124,6 +132,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');