Skip to content

Commit e9aa4ef

Browse files
Integrating the new api
1 parent a3fba06 commit e9aa4ef

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

desktop/core/src/desktop/js/apps/admin/Components/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export const CHECK_CONFIG_EXAMPLES_API_URL = '/api/v1/check_config';
1919
export const ANALYTICS_PREFERENCES_API_URL = '/about/update_preferences';
2020
export const INSTALL_APP_EXAMPLES_API_URL = '/api/v1/install_app_examples';
2121
export const INSTALL_AVAILABLE_EXAMPLES_API_URL = '/api/v1/available_app_examples';
22+
export const SQL_TYPE_MAPPING_API_URL = '/api/v1/importer/sql_type_mapping';
2223
export const HUE_DOCS_CONFIG_URL = 'https://docs.gethue.com/administrator/configuration/';

desktop/core/src/desktop/js/apps/newimporter/ImporterFilePreview/EditColumns/EditColumnsModal.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Modal from 'cuix/dist/components/Modal';
2020
import Table from 'cuix/dist/components/Table';
2121
import Input from 'cuix/dist/components/Input';
2222
import Select from 'cuix/dist/components/Select';
23+
import { SQL_TYPE_MAPPING_API_URL } from '../../../admin/Components/utils';
2324

2425
export 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

Comments
 (0)