Skip to content

Commit 3afd0f1

Browse files
fix(ui): fix schema prefixing
1 parent fa9c3c0 commit 3afd0f1

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

ui/app/mirrors/create/cdc/schemabox.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import {
2222
Dispatch,
2323
SetStateAction,
2424
useCallback,
25+
useEffect,
2526
useMemo,
27+
useRef,
2628
useState,
2729
useTransition,
2830
} from 'react';
2931
import ReactSelect from 'react-select';
3032
import { useTheme as useStyledTheme } from 'styled-components';
31-
import { fetchColumns, fetchTables } from '../handlers';
33+
import { fetchColumns, fetchTables, getDefaultDestinationTable } from '../handlers';
3234
import ColumnBox from './columnbox';
3335
import CustomColumnType from './customColumnType';
3436
import 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

ui/app/mirrors/create/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export async function fetchSchemas(peer_name: string) {
375375
return schemasRes.schemas;
376376
}
377377

378-
function getDefaultDestinationTable(
378+
export function getDefaultDestinationTable(
379379
peerType: DBType,
380380
schemaName: string,
381381
tableName: string

0 commit comments

Comments
 (0)