@@ -22,13 +22,15 @@ import {
2222 Dispatch ,
2323 SetStateAction ,
2424 useCallback ,
25+ useEffect ,
2526 useMemo ,
27+ useRef ,
2628 useState ,
2729 useTransition ,
2830} from 'react' ;
2931import ReactSelect from 'react-select' ;
3032import { useTheme as useStyledTheme } from 'styled-components' ;
31- import { fetchColumns , fetchTables } from '../handlers' ;
33+ import { fetchColumns , fetchTables , getDefaultDestinationTable } from '../handlers' ;
3234import ColumnBox from './columnbox' ;
3335import CustomColumnType from './customColumnType' ;
3436import SchemaSettings from './schemasettings' ;
@@ -75,6 +77,27 @@ export default function SchemaBox({
7577 const [ tableQuery , setTableQuery ] = useState < string > ( '' ) ;
7678 const [ defaultTargetSchema , setDefaultTargetSchema ] =
7779 useState < string > ( schema ) ;
80+ const prevTargetSchema = useRef < string > ( schema ) ;
81+
82+ useEffect ( ( ) => {
83+ if ( prevTargetSchema . current !== defaultTargetSchema && peerType ) {
84+ prevTargetSchema . current = defaultTargetSchema ;
85+ setRows ( ( oldRows ) =>
86+ oldRows . map ( ( row ) => {
87+ if ( row . schema !== schema || row . editingDisabled ) return row ;
88+ const tableName = row . source . split ( '.' ) . slice ( 1 ) . join ( '.' ) ;
89+ return {
90+ ...row ,
91+ destination : getDefaultDestinationTable (
92+ peerType ,
93+ defaultTargetSchema ,
94+ tableName
95+ ) ,
96+ } ;
97+ } )
98+ ) ;
99+ }
100+ } , [ defaultTargetSchema , peerType , schema , setRows ] ) ;
78101 const searchedTables = useMemo ( ( ) => {
79102 const tableQueryLower = tableQuery . toLowerCase ( ) ;
80103 return rows
0 commit comments