@@ -20,6 +20,7 @@ import Modal from 'cuix/dist/components/Modal';
2020import Table from 'cuix/dist/components/Table' ;
2121import Input from 'cuix/dist/components/Input' ;
2222import Select from 'cuix/dist/components/Select' ;
23+ import { SQL_TYPE_MAPPING_API_URL } from '../../../admin/Components/utils' ;
2324
2425export interface Column {
2526 title : string ;
@@ -53,14 +54,40 @@ const EditColumnsModal = ({
5354} : EditColumnsModalProps ) : JSX . Element => {
5455 const { t } = i18nReact . useTranslation ( ) ;
5556 const [ editRows , setEditRows ] = useState < EditRow [ ] > ( [ ] ) ;
57+ const [ sqlTypes , setSqlTypes ] = useState < string [ ] > ( [ ] ) ;
58+ const [ typeError , setTypeError ] = useState < string | null > ( null ) ;
59+
60+ useEffect ( ( ) => {
61+ // Fetch SQL types on mount
62+ const fetchSqlTypes = async ( ) => {
63+ try {
64+ const res = await fetch ( `${ SQL_TYPE_MAPPING_API_URL } ?sql_dialect=hive` ) ;
65+ const data = await res . json ( ) ;
66+ if ( Array . isArray ( data ) && data . length > 0 ) {
67+ setSqlTypes ( data ) ;
68+ setTypeError ( null ) ;
69+ } else {
70+ setSqlTypes ( [ ] ) ;
71+ setTypeError ( t ( 'No SQL types returned from server.' ) ) ;
72+ }
73+ } catch ( err ) {
74+ setSqlTypes ( [ ] ) ;
75+ setTypeError ( t ( 'Failed to fetch SQL types.' ) ) ;
76+ }
77+ } ;
78+ fetchSqlTypes ( ) ;
79+ } , [ t ] ) ;
5680
5781 useEffect ( ( ) => {
5882 setEditRows (
5983 columns . map ( ( col , idx ) => ( {
6084 key : idx ,
6185 name : col . title ,
6286 type : col . type || 'string' ,
63- sample : sample && sample . length > 0 ? ( sample [ 0 ] [ col . dataIndex ] ?? '' ) : '' ,
87+ sample :
88+ sample && sample . length > 0 && sample [ 0 ] [ col . dataIndex ] !== undefined
89+ ? String ( sample [ 0 ] [ col . dataIndex ] )
90+ : '' ,
6491 comment : col . comment || ''
6592 } ) )
6693 ) ;
@@ -106,11 +133,13 @@ const EditColumnsModal = ({
106133 onChange = { ( val : string ) => handleChange ( idx , 'type' , val ) }
107134 getPopupContainer = { triggerNode => triggerNode . parentNode }
108135 style = { { border : '1px solid #838b92' , borderRadius : '3px' , width : '150px' } }
136+ disabled = { sqlTypes . length === 0 }
109137 >
110- < Select . Option value = "string" > { t ( 'String' ) } </ Select . Option >
111- < Select . Option value = "int" > { t ( 'Integer' ) } </ Select . Option >
112- < Select . Option value = "float" > { t ( 'Float' ) } </ Select . Option >
113- < Select . Option value = "bool" > { t ( 'Boolean' ) } </ Select . Option >
138+ { sqlTypes . map ( type => (
139+ < Select . Option key = { type } value = { type } >
140+ { type }
141+ </ Select . Option >
142+ ) ) }
114143 </ Select >
115144 )
116145 } ,
@@ -140,7 +169,7 @@ const EditColumnsModal = ({
140169 )
141170 }
142171 ] ,
143- [ t ]
172+ [ t , sqlTypes ]
144173 ) ;
145174
146175 return (
@@ -153,6 +182,9 @@ const EditColumnsModal = ({
153182 onOk = { handleDone }
154183 width = { 800 }
155184 >
185+ { typeError && (
186+ < div style = { { color : 'red' , marginBottom : 16 } } > { typeError } </ div >
187+ ) }
156188 < Table columns = { modalColumns } dataSource = { editRows } pagination = { false } />
157189 </ Modal >
158190 ) ;
0 commit comments