Skip to content

Commit fd5abb1

Browse files
authored
Merge pull request #470 from tapdata/fix/TAP-8781-data-validation
Fix/tap 8781 data validation
2 parents 4d4d40b + 89fc19c commit fd5abb1

5 files changed

Lines changed: 301 additions & 146 deletions

File tree

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
1-
import Http from './Http'
21
import { isPlainObj } from '@tap/shared'
2+
import Http from './Http'
33

44
export default class MetadataInstances extends Http {
55
constructor() {
66
super('/api/MetadataInstances')
77
}
88
getId(id, params) {
9-
return this.axios.get(this.url + '/' + id, { params })
9+
return this.axios.get(`${this.url}/${id}`, { params })
1010
}
1111
patchId(id, params) {
12-
return this.axios.patch(this.url + '/' + id, params)
12+
return this.axios.patch(`${this.url}/${id}`, params)
1313
}
1414
classification(params) {
15-
return this.axios.patch(this.url + '/classifications', params)
15+
return this.axios.patch(`${this.url}/classifications`, params)
1616
}
1717
download(where, type) {
1818
if (typeof where === 'object') where = JSON.stringify(where)
19-
window.open(this.url + `/download?where=${encodeURIComponent(where)}&type=${type}`)
19+
window.open(
20+
`${this.url}/download?where=${encodeURIComponent(where)}&type=${type}`,
21+
)
2022
// return this.axios.get(this.url + '/download?where=' + where);
2123
}
2224

2325
dataMap(params) {
24-
return this.axios.get(this.url + '/dataMap', { params })
26+
return this.axios.get(`${this.url}/dataMap`, { params })
2527
}
2628
schema(params) {
27-
return this.axios.get(this.url + '/schema', { params })
29+
return this.axios.get(`${this.url}/schema`, { params })
2830
}
2931
tableConnection(params) {
30-
return this.axios.get(this.url + '/tableConnection', { params })
32+
return this.axios.get(`${this.url}/tableConnection`, { params })
3133
}
3234
upload(upsert, type, listtags, params) {
33-
return this.axios.post(`${this.url}/upload?upsert=${upsert}&type=${type}&listtags=${listtags}`, params)
35+
return this.axios.post(
36+
`${this.url}/upload?upsert=${upsert}&type=${type}&listtags=${listtags}`,
37+
params,
38+
)
3439
}
3540
search(params) {
36-
return this.axios.get(this.url + '/search', { params })
41+
return this.axios.get(`${this.url}/search`, { params })
3742
}
3843
compareHistory(id, params) {
39-
return this.axios.get(this.url + '/compareHistory?id=' + id, params)
44+
return this.axios.get(`${this.url}/compareHistory?id=${id}`, params)
4045
}
4146

4247
/**
@@ -45,8 +50,12 @@ export default class MetadataInstances extends Http {
4550
* @param fields 筛选字段,如果有值,则请求结果只返回fields包含的字段;类型:字符串数组
4651
* @returns {Promise<AxiosResponse<any>>}
4752
*/
48-
nodeSchema(nodeId, fields = ['fields', 'indices'], nodeConfig) {
49-
return this.axios.get(this.url + '/node/schema', {
53+
nodeSchema(
54+
nodeId,
55+
fields = ['fields', 'indices', 'constraints'],
56+
nodeConfig,
57+
) {
58+
return this.axios.get(`${this.url}/node/schema`, {
5059
params: {
5160
nodeId,
5261
fields,
@@ -60,15 +69,24 @@ export default class MetadataInstances extends Http {
6069
*/
6170
originalData(qualified_name, target) {
6271
if (target) {
63-
return this.axios.get(this.url + '/originalData?qualified_name=' + encodeURIComponent(qualified_name) + target)
64-
} else return this.axios.get(this.url + '/originalData?qualified_name=' + encodeURIComponent(qualified_name))
72+
return this.axios.get(
73+
`${this.url}/originalData?qualified_name=${encodeURIComponent(
74+
qualified_name,
75+
)}${target}`,
76+
)
77+
} else
78+
return this.axios.get(
79+
`${this.url}/originalData?qualified_name=${encodeURIComponent(
80+
qualified_name,
81+
)}`,
82+
)
6583
}
6684

6785
get(params = {}, filter) {
6886
if (Array.isArray(params)) {
6987
filter = typeof filter === 'object' ? JSON.stringify(filter) : filter
70-
let qs = filter ? '?filter=' + encodeURIComponent(filter) : ''
71-
return this.axios.get(this.url + '/' + params.join('/') + qs)
88+
const qs = filter ? `?filter=${encodeURIComponent(filter)}` : ''
89+
return this.axios.get(`${this.url}/${params.join('/')}${qs}`)
7290
}
7391
const config = { params }
7492
if (isPlainObj(filter)) {
@@ -78,15 +96,17 @@ export default class MetadataInstances extends Http {
7896
}
7997

8098
getTables(connectionId) {
81-
return this.axios.get(this.url + '/tables?connectionId=' + connectionId)
99+
return this.axios.get(`${this.url}/tables?connectionId=${connectionId}`)
82100
}
83101

84102
getTablesValue(params) {
85-
return this.axios.get(this.url + '/tablesValue', { params })
103+
return this.axios.get(`${this.url}/tablesValue`, { params })
86104
}
87105

88106
getSourceTables(connectionId) {
89-
return this.axios.get(this.url + '/tables?connectionId=' + connectionId + '&sourceType=SOURCE')
107+
return this.axios.get(
108+
`${this.url}/tables?connectionId=${connectionId}&sourceType=SOURCE`,
109+
)
90110
}
91111

92112
/**
@@ -96,75 +116,79 @@ export default class MetadataInstances extends Http {
96116
* @returns {Promise<AxiosResponse<any>>}
97117
*/
98118
getMergerNodeParentFields(taskId, nodeId) {
99-
return this.axios.get(`${this.url}/mergerNode/parent/fields?taskId=${taskId}&nodeId=${nodeId}`)
119+
return this.axios.get(
120+
`${this.url}/mergerNode/parent/fields?taskId=${taskId}&nodeId=${nodeId}`,
121+
)
100122
}
101123
findTablesById(id) {
102-
return this.axios.get(this.url + '/findTablesById/' + id)
124+
return this.axios.get(`${this.url}/findTablesById/${id}`)
103125
}
104126
findInspect(data) {
105-
return this.axios.post(this.url + '/findInspectPost', data)
127+
return this.axios.post(`${this.url}/findInspectPost`, data)
106128
}
107129
//元数据修改
108130
saveTable(params) {
109-
return this.axios.post(this.url + '/migrate/saveTable', params)
131+
return this.axios.post(`${this.url}/migrate/saveTable`, params)
110132
}
111133
//元数据修改
112134
resetTable(params) {
113-
return this.axios.post(this.url + '/migrate/reset', params)
135+
return this.axios.post(`${this.url}/migrate/reset`, params)
114136
}
115137

116138
//61迭代 新增可以修改目标节点类型 新增接口
117139
changeFields(params) {
118-
return this.axios.post(this.url + '/changeFields', params)
140+
return this.axios.post(`${this.url}/changeFields`, params)
119141
}
120142
changeFieldsReset(params) {
121-
return this.axios.post(this.url + '/changeFields/reset', params)
143+
return this.axios.post(`${this.url}/changeFields/reset`, params)
122144
}
123145
dataType2TapType(params) {
124-
return this.axios.post(this.url + '/dataType2TapType', params)
146+
return this.axios.post(`${this.url}/dataType2TapType`, params)
125147
}
126148
nodeSchemaPage(params) {
127-
return this.axios.get(this.url + '/node/schemaPage', { params })
149+
return this.axios.get(`${this.url}/node/schemaPage`, { params })
128150
}
129151
tapTables(params) {
130-
return this.axios.get(this.url + '/tapTables?filter=' + encodeURIComponent(params.filter))
152+
return this.axios.get(
153+
`${this.url}/tapTables?filter=${encodeURIComponent(params.filter)}`,
154+
)
131155
}
132156
checkTableExist(params) {
133-
return this.axios.get(this.url + '/check/table/exist', { params })
157+
return this.axios.get(`${this.url}/check/table/exist`, { params })
134158
}
135159
deleteLogicSchema(taskId, params) {
136-
return this.axios.delete(this.url + '/logic/schema/' + taskId, { params })
160+
return this.axios.delete(`${this.url}/logic/schema/${taskId}`, { params })
137161
}
138162
pageTables(params) {
139-
return this.axios.get(this.url + '/page-tables', { params })
163+
return this.axios.get(`${this.url}/page-tables`, { params })
140164
}
141165
pagePartitionTables(params) {
142-
return this.axios.get(this.url + '/partition/page-tables', { params })
166+
return this.axios.get(`${this.url}/partition/page-tables`, { params })
143167
}
144168
//更新表描述
145169
updateTableDesc(params) {
146-
return this.axios.post(this.url + '/updateTableDesc', params)
170+
return this.axios.post(`${this.url}/updateTableDesc`, params)
147171
}
148172
dataTypeCheckMultiple(params) {
149-
return this.axios.post(this.url + '/dataType/checkMultiple', params)
173+
return this.axios.post(`${this.url}/dataType/checkMultiple`, params)
150174
}
151175
updateTableFieldDesc(id, params) {
152-
return this.axios.post(this.url + `/updateTableFieldDesc/${id}`, params)
176+
return this.axios.post(`${this.url}/updateTableFieldDesc/${id}`, params)
153177
}
154178
nodeFilterTypeList(params) {
155-
return this.axios.get(this.url + `/node/filterTypeList`, { params })
179+
return this.axios.get(`${this.url}/node/filterTypeList`, { params })
156180
}
157181
// 获取表最新的字段列表
158182
multiTransform(params) {
159-
return this.axios.post(this.url + `/multi/transform`, params)
183+
return this.axios.post(`${this.url}/multi/transform`, params)
160184
}
161185

162186
getNodeSchemaMapByIds(params) {
163-
return this.axios.get(this.url + `/nodes/schema-map`, { params })
187+
return this.axios.get(`${this.url}/nodes/schema-map`, { params })
164188
}
165189

166190
checkFiledIndex(params) {
167-
return this.axios.get(this.url + `/check/filedIndex`, { params })
191+
return this.axios.get(`${this.url}/check/filedIndex`, { params })
168192
}
169193
}
170194
export { MetadataInstances }

packages/business/src/views/verification/components/ConditionBox.vue

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import VCodeEditor from '@tap/component/src/base/VCodeEditor.vue'
55
import GitBook from '@tap/component/src/GitBook.vue'
66
import { Modal } from '@tap/component/src/modal'
77
import SwitchNumber from '@tap/component/src/SwitchNumber.vue'
8+
import { mapFieldsData } from '@tap/form/src/components/field-select/FieldSelect.tsx'
89
import AsyncSelect from '@tap/form/src/components/infinite-select/InfiniteSelect.vue'
910
import { JsonEditor } from '@tap/form/src/components/json-editor'
1011
import { SqlEditor } from '@tap/form/src/components/sql-editor'
@@ -298,7 +299,7 @@ const getTableListMethod = async (
298299
return { items: [], total: 0 }
299300
}
300301
if (props.taskId) {
301-
return getTablesInTask(nodeId, connectionId, filter)
302+
return getTablesInTask(nodeId as string, connectionId as string, filter)
302303
}
303304
try {
304305
const size = filter.size || 20
@@ -326,32 +327,14 @@ const getTableListMethod = async (
326327
// 缓存起来
327328
setFieldsByItem(
328329
[nodeId, connectionId, el.name],
329-
Object.values(el.nameFieldMap || {}).map((t: any) => {
330-
const {
331-
id,
332-
fieldName,
333-
primaryKeyPosition,
334-
fieldType,
335-
data_type,
336-
primaryKey,
337-
unique,
338-
} = t
339-
return {
340-
id,
341-
field_name: fieldName,
342-
primary_key_position: primaryKeyPosition,
343-
fieldType,
344-
data_type,
345-
primaryKey,
346-
unique,
347-
type: t.data_type,
348-
tapType: JSON.stringify(t.tapType),
349-
}
350-
}),
330+
mapFieldsData({
331+
fields: Object.values(el.nameFieldMap || {}),
332+
}).fields,
351333
)
352334
})
353335
return result
354-
} catch {
336+
} catch (error) {
337+
console.error('Failed to get table list:', error)
355338
return { items: [], total: 0 }
356339
}
357340
}
@@ -373,7 +356,14 @@ const getTablesInTask = async (
373356
374357
const params: TableParams = {
375358
nodeId,
376-
fields: ['original_name', 'fields', 'qualified_name', 'name'],
359+
fields: [
360+
'original_name',
361+
'fields',
362+
'qualified_name',
363+
'name',
364+
'indices',
365+
'constraints',
366+
],
377367
page: filter?.page || 1,
378368
pageSize: filter?.size || 20,
379369
...(filter.where?.name?.like
@@ -386,28 +376,7 @@ const getTablesInTask = async (
386376
const tableList = res.items?.map((t: TableItem) => t.name) || []
387377
const total = res.total
388378
res.items.forEach((el: TableItem) => {
389-
setFieldsByItem(
390-
[nodeId, connectionId, el.name],
391-
el.fields.map((t: any) => {
392-
const {
393-
id,
394-
field_name,
395-
primary_key_position,
396-
data_type,
397-
primaryKey,
398-
unique,
399-
} = t
400-
401-
return {
402-
id,
403-
field_name,
404-
primary_key_position,
405-
data_type,
406-
primaryKey,
407-
unique,
408-
}
409-
}),
410-
)
379+
setFieldsByItem([nodeId, connectionId, el.name], mapFieldsData(el).fields)
411380
})
412381
let tableNames = tableList
413382
if (isDB) {
@@ -1041,7 +1010,11 @@ const setFieldsByItem = (item: any[] = [], data: any[] = []) => {
10411010
}
10421011
10431012
const getFieldsByItem = (item: any, type = 'source') => {
1044-
const { nodeId, connectionId, table } = item[type] || {}
1013+
return getFields(item[type])
1014+
}
1015+
1016+
const getFields = (item: any = {}) => {
1017+
const { nodeId = '', connectionId = '', table = '' } = item
10451018
return (
10461019
fieldsMap[[nodeId || '', connectionId, table].filter((t) => t).join()] || []
10471020
)
@@ -1364,10 +1337,27 @@ const handleChangeFields = (data: any[] = [], id: string) => {
13641337
item.target.columns = data.map((t) => t.target)
13651338
}
13661339
1367-
const onVisibleChange = (opt: any = {}, visible: boolean) => {
1340+
const onVisibleChange = async (opt: any = {}, visible: boolean) => {
13681341
if (!visible || opt.fields?.length) {
13691342
return
13701343
}
1344+
1345+
if (props.taskId) {
1346+
opt.fields = getFields(opt)
1347+
1348+
if (!opt.fields.length) {
1349+
opt.fieldsLoading = true
1350+
const data = await metadataInstancesApi
1351+
.nodeSchema(opt.nodeId)
1352+
.finally(() => {
1353+
opt.fieldsLoading = false
1354+
})
1355+
const { fields } = mapFieldsData(data?.[0])
1356+
opt.fields = fields
1357+
}
1358+
return
1359+
}
1360+
13711361
opt.fieldsLoading = true
13721362
const connectionId = opt.connectionId
13731363
const params = {

0 commit comments

Comments
 (0)