Skip to content

Commit

Permalink
fix: enhance validation for merge properties in editor mixin and upda…
Browse files Browse the repository at this point in the history
…te locale strings

- Improved validation logic for merge properties in the editor mixin to ensure join keys are not empty and source/target fields are specified.
- Added new locale strings for error messages related to empty join keys in English, Simplified Chinese, and Traditional Chinese.
- Updated console log to use `console.debug` for better debugging practices in FormPanel.vue.

(cherry picked from commit 9ee884a)
  • Loading branch information
cn-xufei committed Jan 6, 2025
1 parent e881cfc commit 781c90c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/dag/src/components/FormPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default {
this.updateTimer = setTimeout(() => {
const node = this.nodeById(form.values.id)
if (node && !deepEqual(toJS(form.values), node, ['alarmRules.0._ms', 'alarmRules.0._point'])) {
console.log('还是更新了')
console.debug('updateNodeProps in debounce')
this.updateNodeProps(form)
}
}, 40)
Expand Down
4 changes: 3 additions & 1 deletion packages/dag/src/locale/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,5 +819,7 @@ export default {
packages_dag_counting_num_of_rows_table: 'Counting the number of rows in the table',
packages_dag_noPkSyncMode: 'No Primary Key Table Sync Mode',
packages_dag_noPkSyncMode_ADD_HASH: 'Add Hash Column',
packages_dag_noPkSyncMode_ALL_COLUMNS: 'Full Column Index'
packages_dag_noPkSyncMode_ALL_COLUMNS: 'Full Column Index',
packages_dag_join_keys_empty: 'Association conditions for {tableName} cannot be empty',
packages_dag_join_keys_field_empty: 'Field in association condition #{index} for {tableName} cannot be empty.'
}
4 changes: 3 additions & 1 deletion packages/dag/src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,5 +764,7 @@ export default {
packages_dag_counting_num_of_rows_table: '正在统计表行数',
packages_dag_noPkSyncMode: '无主键表同步方式',
packages_dag_noPkSyncMode_ADD_HASH: '新增哈希列',
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引'
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引',
packages_dag_join_keys_empty: '{tableName} 的关联条件不能为空',
packages_dag_join_keys_field_empty: '{tableName} 的关联条件第 {index} 项的字段不能为空'
}
4 changes: 3 additions & 1 deletion packages/dag/src/locale/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,5 +759,7 @@ export default {
packages_dag_counting_num_of_rows_table: '正在統計表行數',
packages_dag_noPkSyncMode: '無主鍵表同步方式',
packages_dag_noPkSyncMode_ADD_HASH: '新增哈希列',
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引'
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引',
packages_dag_join_keys_empty: '{tableName} 的關聯條件不能為空',
packages_dag_join_keys_field_empty: '{tableName} 的關聯條件第 {index} 項的字段不能為空'
}
88 changes: 63 additions & 25 deletions packages/dag/src/mixins/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1690,38 +1690,76 @@ export default {
if (this.dataflow.syncType === 'migrate') return

const nodes = this.allNodes.filter(node => node.type === 'merge_table_processor')
const allPromise = []

const handle = async input => {
const fields = await this.scope.loadNodeFieldOptions(input)
const validateMergeProperties = (items, isFirstLevel = true) => {
for (const item of items) {
// 跳过第一级,只检查 children 层级的 joinKeys
if (!isFirstLevel) {
// 检查 joinKeys 是否为空数组
if (!item.joinKeys?.length) {
return i18n.t('packages_dag_join_keys_empty', { tableName: item.tableName })
}

if (
fields?.length &&
!fields.some(item => {
return item.isPrimaryKey || item.indicesUnique
})
) {
// 缺少主键或唯一索引
return Promise.reject(input)
// 检查每个 joinKey 的 source/target
for (const [index, joinKey] of item.joinKeys.entries()) {
if (!joinKey.source || !joinKey.target) {
return i18n.t('packages_dag_join_keys_field_empty', { tableName: item.tableName, index: index + 1 })
}
}
}

// 递归检查子项
if (item.children?.length) {
const childrenError = validateMergeProperties(item.children, false)
if (childrenError) {
return childrenError
}
}
}
return ''
}

for (let node of nodes) {
for (let input of node.$inputs) {
allPromise.push(handle(input))
const error = validateMergeProperties(node.mergeProperties)
if (error) {
this.setNodeErrorMsg({
id: node.id,
msg: error
})
return error
}
}

try {
await Promise.all(allPromise)
} catch (id) {
this.setNodeErrorMsg({
id,
msg: i18n.t('packages_dag_missing_primary_key_or_index')
})
this.handleLocateNode(this.nodeById(id))
return i18n.t('packages_dag_merge_table_missing_key_or_index')
}
// const handle = async input => {
// const fields = await this.scope.loadNodeFieldOptions(input)

// if (
// fields?.length &&
// !fields.some(item => {
// return item.isPrimaryKey || item.indicesUnique
// })
// ) {
// // 缺少主键或唯一索引
// return Promise.reject(input)
// }
// }

// for (let node of nodes) {
// for (let input of node.$inputs) {
// allPromise.push(handle(input))
// }
// }

// try {
// await Promise.all(allPromise)
// } catch (id) {
// this.setNodeErrorMsg({
// id,
// msg: i18n.t('packages_dag_missing_primary_key_or_index')
// })
// this.handleLocateNode(this.nodeById(id))
// return i18n.t('packages_dag_merge_table_missing_key_or_index')
// }
},

async eachValidate(...fns) {
Expand Down Expand Up @@ -1759,8 +1797,8 @@ export default {
this.validateCustomSql,
this.validateUnwind,
this.validateTableRename,
this.validateMigrateUnion
// this.validateMergeTableProcessor
this.validateMigrateUnion,
this.validateMergeTableProcessor
)
},

Expand Down
2 changes: 0 additions & 2 deletions packages/dag/src/nodes/MergeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ export class MergeTable extends NodeType {
title: i18n.t('packages_dag_nodes_mergetable_zhucongpeizhi'),
type: 'array',
required: true,
'x-decorator': 'FormItem',
'x-decorator-props': {},
'x-component': 'MergeTableTree',
'x-component-props': {
treeWidth: 200,
Expand Down

0 comments on commit 781c90c

Please sign in to comment.