@@ -20,6 +20,9 @@ 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' ;
24+
25+ import './EditColumnsModal.scss' ;
2326
2427export interface Column {
2528 title : string ;
@@ -53,14 +56,43 @@ const EditColumnsModal = ({
5356} : EditColumnsModalProps ) : JSX . Element => {
5457 const { t } = i18nReact . useTranslation ( ) ;
5558 const [ editRows , setEditRows ] = useState < EditRow [ ] > ( [ ] ) ;
59+ const [ sqlTypes , setSqlTypes ] = useState < string [ ] > ( [ ] ) ;
60+ const [ typeError , setTypeError ] = useState < string | null > ( null ) ;
61+
62+ useEffect ( ( ) => {
63+ const fetchSqlTypes = async ( ) => {
64+ try {
65+ const res = await fetch ( `${ SQL_TYPE_MAPPING_API_URL } ?sql_dialect=hive` ) ;
66+ const data = await res . json ( ) ;
67+ if ( Array . isArray ( data ) && data . length > 0 ) {
68+ setSqlTypes ( data ) ;
69+ setTypeError ( null ) ;
70+ } else if ( data && typeof data === 'object' && Object . keys ( data ) . length > 0 ) {
71+ const typesArray = Array . from ( new Set ( Object . values ( data ) ) ) ;
72+ setSqlTypes ( typesArray as string [ ] ) ;
73+ setTypeError ( null ) ;
74+ } else {
75+ setSqlTypes ( [ ] ) ;
76+ setTypeError ( t ( 'No SQL types returned from server.' ) ) ;
77+ }
78+ } catch ( err ) {
79+ setSqlTypes ( [ ] ) ;
80+ setTypeError ( t ( 'Failed to fetch SQL types.' ) ) ;
81+ }
82+ } ;
83+ fetchSqlTypes ( ) ;
84+ } , [ t ] ) ;
5685
5786 useEffect ( ( ) => {
5887 setEditRows (
5988 columns . map ( ( col , idx ) => ( {
6089 key : idx ,
6190 name : col . title ,
6291 type : col . type || 'string' ,
63- sample : sample && sample . length > 0 ? ( sample [ 0 ] [ col . dataIndex ] ?? '' ) : '' ,
92+ sample :
93+ sample && sample . length > 0 && sample [ 0 ] [ col . dataIndex ] !== undefined
94+ ? String ( sample [ 0 ] [ col . dataIndex ] )
95+ : '' ,
6496 comment : col . comment || ''
6597 } ) )
6698 ) ;
@@ -85,11 +117,12 @@ const EditColumnsModal = ({
85117 const modalColumns = useMemo (
86118 ( ) => [
87119 {
88- title : t ( 'Column Name' ) ,
120+ title : t ( 'Name' ) ,
89121 dataIndex : 'name' ,
90122 render : ( text : string , _ : EditRow , idx : number ) => (
91123 < Input
92124 value = { text }
125+ className = "hue-importer-edit-columns-modal__input--name"
93126 onChange = { ( e : ChangeEvent < HTMLInputElement > ) =>
94127 handleChange ( idx , 'name' , e . target . value )
95128 }
@@ -98,49 +131,52 @@ const EditColumnsModal = ({
98131 )
99132 } ,
100133 {
101- title : t ( 'Column Type' ) ,
134+ title : t ( 'Type' ) ,
102135 dataIndex : 'type' ,
103136 render : ( value : string , _ : EditRow , idx : number ) => (
104137 < Select
105138 value = { value }
106139 onChange = { ( val : string ) => handleChange ( idx , 'type' , val ) }
140+ className = "hue-importer-edit-columns-modal__select--type"
107141 getPopupContainer = { triggerNode => triggerNode . parentNode }
108- style = { { border : '1px solid #838b92' , borderRadius : '3px' , width : '150px' } }
142+ disabled = { sqlTypes . length === 0 }
109143 >
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 >
144+ { sqlTypes . map ( type => (
145+ < Select . Option key = { type } value = { type } >
146+ { type }
147+ </ Select . Option >
148+ ) ) }
114149 </ Select >
115150 )
116151 } ,
117152 {
118- title : t ( 'Sample Value ' ) ,
153+ title : t ( 'Sample' ) ,
119154 dataIndex : 'sample' ,
120155 render : ( text : string , _ : EditRow , idx : number ) => (
121156 < Input
122157 value = { text }
158+ className = "hue-importer-edit-columns-modal__input--sample"
123159 onChange = { ( e : ChangeEvent < HTMLInputElement > ) =>
124160 handleChange ( idx , 'sample' , e . target . value )
125161 }
126- style = { { border : 'none' } }
127162 />
128163 )
129164 } ,
130165 {
131166 title : t ( 'Comment' ) ,
132167 dataIndex : 'comment' ,
133168 render : ( text : string , _ : EditRow , idx : number ) => (
134- < Input
169+ < textarea
135170 value = { text }
136- onChange = { ( e : ChangeEvent < HTMLInputElement > ) =>
171+ onChange = { ( e : ChangeEvent < HTMLTextAreaElement > ) =>
137172 handleChange ( idx , 'comment' , e . target . value )
138173 }
174+ rows = { 2 }
139175 />
140176 )
141177 }
142178 ] ,
143- [ t ]
179+ [ t , sqlTypes ]
144180 ) ;
145181
146182 return (
@@ -151,8 +187,10 @@ const EditColumnsModal = ({
151187 cancelText = { t ( 'Cancel' ) }
152188 okText = { t ( 'Done' ) }
153189 onOk = { handleDone }
190+ className = "hue-importer-edit-columns-modal"
154191 width = { 800 }
155192 >
193+ { typeError && < div className = "hue-importer-edit-columns-modal__type-error" > { typeError } </ div > }
156194 < Table columns = { modalColumns } dataSource = { editRows } pagination = { false } />
157195 </ Modal >
158196 ) ;
0 commit comments