Skip to content

Commit e9aec02

Browse files
Integrating the new api
Before review comments First iteration of styling
1 parent cf2af03 commit e9aec02

File tree

3 files changed

+92
-13
lines changed

3 files changed

+92
-13
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/';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to Cloudera, Inc. under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. Cloudera, Inc. licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
@use 'variables' as vars;
18+
19+
.antd.cuix {
20+
.hue-importer-edit-columns-modal {
21+
&__input--name {
22+
width: 100px;
23+
}
24+
25+
&__select--type {
26+
border: 1px solid #838b92;
27+
border-radius: 3px;
28+
width: 100px;
29+
}
30+
31+
&__input--sample {
32+
border: none;
33+
}
34+
35+
&__type-error {
36+
color: red;
37+
margin-bottom: 16px;
38+
}
39+
}
40+
}

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

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ 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';
24+
25+
import './EditColumnsModal.scss';
2326

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

Comments
 (0)