Skip to content

Commit 3b83568

Browse files
committed
fix: enhance validation for merge properties in editor mixin and update 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)
1 parent 769b7c8 commit 3b83568

File tree

6 files changed

+73
-31
lines changed

6 files changed

+73
-31
lines changed

packages/dag/src/components/FormPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export default {
223223
this.updateTimer = setTimeout(() => {
224224
const node = this.nodeById(form.values.id)
225225
if (node && !deepEqual(toJS(form.values), node, ['alarmRules.0._ms', 'alarmRules.0._point'])) {
226-
console.log('还是更新了')
226+
console.debug('updateNodeProps in debounce')
227227
this.updateNodeProps(form)
228228
}
229229
}, 40)

packages/dag/src/locale/lang/en.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,5 +823,7 @@ export default {
823823
packages_dag_counting_num_of_rows_table: 'Counting the number of rows in the table',
824824
packages_dag_noPkSyncMode: 'No Primary Key Table Sync Mode',
825825
packages_dag_noPkSyncMode_ADD_HASH: 'Add Hash Column',
826-
packages_dag_noPkSyncMode_ALL_COLUMNS: 'Full Column Index'
826+
packages_dag_noPkSyncMode_ALL_COLUMNS: 'Full Column Index',
827+
packages_dag_join_keys_empty: 'Association conditions for {tableName} cannot be empty',
828+
packages_dag_join_keys_field_empty: 'Field in association condition #{index} for {tableName} cannot be empty.'
827829
}

packages/dag/src/locale/lang/zh-CN.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,5 +767,7 @@ export default {
767767
packages_dag_counting_num_of_rows_table: '正在统计表行数',
768768
packages_dag_noPkSyncMode: '无主键表同步方式',
769769
packages_dag_noPkSyncMode_ADD_HASH: '新增哈希列',
770-
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引'
770+
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引',
771+
packages_dag_join_keys_empty: '{tableName} 的关联条件不能为空',
772+
packages_dag_join_keys_field_empty: '{tableName} 的关联条件第 {index} 项的字段不能为空'
771773
}

packages/dag/src/locale/lang/zh-TW.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,5 +762,7 @@ export default {
762762
packages_dag_counting_num_of_rows_table: '正在統計表行數',
763763
packages_dag_noPkSyncMode: '無主鍵表同步方式',
764764
packages_dag_noPkSyncMode_ADD_HASH: '新增哈希列',
765-
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引'
765+
packages_dag_noPkSyncMode_ALL_COLUMNS: '全字段索引',
766+
packages_dag_join_keys_empty: '{tableName} 的關聯條件不能為空',
767+
packages_dag_join_keys_field_empty: '{tableName} 的關聯條件第 {index} 項的字段不能為空'
766768
}

packages/dag/src/mixins/editor.js

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,38 +1690,76 @@ export default {
16901690
if (this.dataflow.syncType === 'migrate') return
16911691

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

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

1698-
if (
1699-
fields?.length &&
1700-
!fields.some(item => {
1701-
return item.isPrimaryKey || item.indicesUnique
1702-
})
1703-
) {
1704-
// 缺少主键或唯一索引
1705-
return Promise.reject(input)
1703+
// 检查每个 joinKey 的 source/target
1704+
for (const [index, joinKey] of item.joinKeys.entries()) {
1705+
if (!joinKey.source || !joinKey.target) {
1706+
return i18n.t('packages_dag_join_keys_field_empty', { tableName: item.tableName, index: index + 1 })
1707+
}
1708+
}
1709+
}
1710+
1711+
// 递归检查子项
1712+
if (item.children?.length) {
1713+
const childrenError = validateMergeProperties(item.children, false)
1714+
if (childrenError) {
1715+
return childrenError
1716+
}
1717+
}
17061718
}
1719+
return ''
17071720
}
17081721

17091722
for (let node of nodes) {
1710-
for (let input of node.$inputs) {
1711-
allPromise.push(handle(input))
1723+
const error = validateMergeProperties(node.mergeProperties)
1724+
if (error) {
1725+
this.setNodeErrorMsg({
1726+
id: node.id,
1727+
msg: error
1728+
})
1729+
return error
17121730
}
17131731
}
17141732

1715-
try {
1716-
await Promise.all(allPromise)
1717-
} catch (id) {
1718-
this.setNodeErrorMsg({
1719-
id,
1720-
msg: i18n.t('packages_dag_missing_primary_key_or_index')
1721-
})
1722-
this.handleLocateNode(this.nodeById(id))
1723-
return i18n.t('packages_dag_merge_table_missing_key_or_index')
1724-
}
1733+
// const handle = async input => {
1734+
// const fields = await this.scope.loadNodeFieldOptions(input)
1735+
1736+
// if (
1737+
// fields?.length &&
1738+
// !fields.some(item => {
1739+
// return item.isPrimaryKey || item.indicesUnique
1740+
// })
1741+
// ) {
1742+
// // 缺少主键或唯一索引
1743+
// return Promise.reject(input)
1744+
// }
1745+
// }
1746+
1747+
// for (let node of nodes) {
1748+
// for (let input of node.$inputs) {
1749+
// allPromise.push(handle(input))
1750+
// }
1751+
// }
1752+
1753+
// try {
1754+
// await Promise.all(allPromise)
1755+
// } catch (id) {
1756+
// this.setNodeErrorMsg({
1757+
// id,
1758+
// msg: i18n.t('packages_dag_missing_primary_key_or_index')
1759+
// })
1760+
// this.handleLocateNode(this.nodeById(id))
1761+
// return i18n.t('packages_dag_merge_table_missing_key_or_index')
1762+
// }
17251763
},
17261764

17271765
async eachValidate(...fns) {
@@ -1759,8 +1797,8 @@ export default {
17591797
this.validateCustomSql,
17601798
this.validateUnwind,
17611799
this.validateTableRename,
1762-
this.validateMigrateUnion
1763-
// this.validateMergeTableProcessor
1800+
this.validateMigrateUnion,
1801+
this.validateMergeTableProcessor
17641802
)
17651803
},
17661804

packages/dag/src/nodes/MergeTable.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ export class MergeTable extends NodeType {
120120
title: i18n.t('packages_dag_nodes_mergetable_zhucongpeizhi'),
121121
type: 'array',
122122
required: true,
123-
'x-decorator': 'FormItem',
124-
'x-decorator-props': {},
125123
'x-component': 'MergeTableTree',
126124
'x-component-props': {
127125
treeWidth: 200,

0 commit comments

Comments
 (0)