@@ -289,8 +289,11 @@ function HighlightedAttributeExpressionsFormRow({
289289
290290/** Component for configuring one or more materialized views */
291291function MaterializedViewsFormSection ( { control, setValue } : TableModelProps ) {
292- const databaseName =
293- useWatch ( { control, name : `from.databaseName` } ) || DEFAULT_DATABASE ;
292+ const databaseName = useWatch ( {
293+ control,
294+ name : `from.databaseName` ,
295+ defaultValue : DEFAULT_DATABASE ,
296+ } ) ;
294297
295298 const {
296299 fields : materializedViews ,
@@ -357,13 +360,21 @@ function MaterializedViewFormSection({
357360 setValue,
358361} : { mvIndex : number ; onRemove : ( ) => void } & TableModelProps ) {
359362 const connection = useWatch ( { control, name : `connection` } ) ;
360- const sourceDatabaseName =
361- useWatch ( { control, name : `from.databaseName` } ) || DEFAULT_DATABASE ;
362- const mvDatabaseName =
363- useWatch ( { control, name : `materializedViews.${ mvIndex } .databaseName` } ) ||
364- sourceDatabaseName ;
365- const mvTableName =
366- useWatch ( { control, name : `materializedViews.${ mvIndex } .tableName` } ) || '' ;
363+ const sourceDatabaseName = useWatch ( {
364+ control,
365+ name : `from.databaseName` ,
366+ defaultValue : DEFAULT_DATABASE ,
367+ } ) ;
368+ const mvDatabaseName = useWatch ( {
369+ control,
370+ name : `materializedViews.${ mvIndex } .databaseName` ,
371+ defaultValue : sourceDatabaseName ,
372+ } ) ;
373+ const mvTableName = useWatch ( {
374+ control,
375+ name : `materializedViews.${ mvIndex } .tableName` ,
376+ defaultValue : '' ,
377+ } ) ;
367378
368379 return (
369380 < Stack gap = "sm" >
@@ -615,12 +626,17 @@ function AggregatedColumnRow({
615626 onRemove : ( ) => void ;
616627} ) {
617628 const connectionId = useWatch ( { control, name : `connection` } ) ;
618- const sourceDatabaseName =
619- useWatch ( { control, name : `from.databaseName` } ) || DEFAULT_DATABASE ;
629+ const sourceDatabaseName = useWatch ( {
630+ control,
631+ name : `from.databaseName` ,
632+ defaultValue : DEFAULT_DATABASE ,
633+ } ) ;
620634 const sourceTableName = useWatch ( { control, name : `from.tableName` } ) ;
621- const mvDatabaseName =
622- useWatch ( { control, name : `materializedViews.${ mvIndex } .databaseName` } ) ||
623- sourceDatabaseName ;
635+ const mvDatabaseName = useWatch ( {
636+ control,
637+ name : `materializedViews.${ mvIndex } .databaseName` ,
638+ defaultValue : sourceDatabaseName ,
639+ } ) ;
624640 const mvTableName = useWatch ( {
625641 control,
626642 name : `materializedViews.${ mvIndex } .tableName` ,
@@ -1226,7 +1242,7 @@ export function TraceTableModelForm(props: TableModelProps) {
12261242 ) ;
12271243}
12281244
1229- export function SessionTableModelForm ( { control, setValue } : TableModelProps ) {
1245+ export function SessionTableModelForm ( { control } : TableModelProps ) {
12301246 const databaseName = useWatch ( {
12311247 control,
12321248 name : 'from.databaseName' ,
@@ -1411,36 +1427,45 @@ export function TableSourceForm({
14111427 const { data : source } = useSource ( { id : sourceId } ) ;
14121428 const { data : connections } = useConnections ( ) ;
14131429
1414- const {
1415- control,
1416- setValue,
1417- formState,
1418- handleSubmit,
1419- resetField,
1420- setError,
1421- clearErrors,
1422- } = useForm < TSourceUnion > ( {
1423- defaultValues : {
1424- kind : SourceKind . Log ,
1425- name : defaultName ,
1426- connection : connections ?. [ 0 ] ?. id ,
1427- from : {
1428- databaseName : 'default' ,
1429- tableName : '' ,
1430+ const { control, setValue, handleSubmit, resetField, setError, clearErrors } =
1431+ useForm < TSourceUnion > ( {
1432+ defaultValues : {
1433+ kind : SourceKind . Log ,
1434+ name : defaultName ,
1435+ connection : connections ?. [ 0 ] ?. id ,
1436+ from : {
1437+ databaseName : 'default' ,
1438+ tableName : '' ,
1439+ } ,
14301440 } ,
1431- } ,
1432- // TODO: HDX-1768 remove type assertion
1433- values : source as TSourceUnion ,
1434- resetOptions : {
1435- keepDirtyValues : true ,
1436- keepErrors : true ,
1437- } ,
1438- } ) ;
1441+ // TODO: HDX-1768 remove type assertion
1442+ values : source as TSourceUnion ,
1443+ resetOptions : {
1444+ keepDirtyValues : true ,
1445+ keepErrors : true ,
1446+ } ,
1447+ } ) ;
14391448
1440- const watchedConnection = useWatch ( { control, name : 'connection' } ) ;
1441- const watchedDatabaseName = useWatch ( { control, name : 'from.databaseName' } ) ;
1442- const watchedTableName = useWatch ( { control, name : 'from.tableName' } ) ;
1443- const watchedKind = useWatch ( { control, name : 'kind' } ) ;
1449+ const watchedConnection = useWatch ( {
1450+ control,
1451+ name : 'connection' ,
1452+ defaultValue : source ?. connection ,
1453+ } ) ;
1454+ const watchedDatabaseName = useWatch ( {
1455+ control,
1456+ name : 'from.databaseName' ,
1457+ defaultValue : source ?. from ?. databaseName || DEFAULT_DATABASE ,
1458+ } ) ;
1459+ const watchedTableName = useWatch ( {
1460+ control,
1461+ name : 'from.tableName' ,
1462+ defaultValue : source ?. from ?. tableName ,
1463+ } ) ;
1464+ const watchedKind = useWatch ( {
1465+ control,
1466+ name : 'kind' ,
1467+ defaultValue : source ?. kind || SourceKind . Log ,
1468+ } ) ;
14441469 const prevTableNameRef = useRef ( watchedTableName ) ;
14451470
14461471 useEffect ( ( ) => {
@@ -1493,7 +1518,11 @@ export function TableSourceForm({
14931518 resetField ( 'connection' , { defaultValue : connections ?. [ 0 ] ?. id } ) ;
14941519 } , [ connections , resetField ] ) ;
14951520
1496- const kind : SourceKind = useWatch ( { control, name : 'kind' } ) ;
1521+ const kind = useWatch ( {
1522+ control,
1523+ name : 'kind' ,
1524+ defaultValue : source ?. kind || SourceKind . Log ,
1525+ } ) ;
14971526
14981527 const createSource = useCreateSource ( ) ;
14991528 const updateSource = useUpdateSource ( ) ;
@@ -1751,9 +1780,13 @@ export function TableSourceForm({
17511780 const databaseName = useWatch ( {
17521781 control,
17531782 name : 'from.databaseName' ,
1754- defaultValue : DEFAULT_DATABASE ,
1783+ defaultValue : source ?. from ?. databaseName || DEFAULT_DATABASE ,
1784+ } ) ;
1785+ const connectionId = useWatch ( {
1786+ control,
1787+ name : 'connection' ,
1788+ defaultValue : source ?. connection ,
17551789 } ) ;
1756- const connectionId = useWatch ( { control, name : 'connection' } ) ;
17571790
17581791 return (
17591792 < div
0 commit comments