fix: preserve snmp oid validation row numbers
This commit is contained in:
@@ -324,6 +324,19 @@ const normalizeSnmpOidRows = (rows: SnmpOidRow[]) =>
|
|||||||
}))
|
}))
|
||||||
.filter((row) => row.oid || row.metric_name || row.metric_unit || row.type)
|
.filter((row) => row.oid || row.metric_name || row.metric_unit || row.type)
|
||||||
|
|
||||||
|
const findIncompleteSnmpOidRowIndex = (rows: SnmpOidRow[]) =>
|
||||||
|
rows.findIndex((row) => {
|
||||||
|
const normalizedRow = {
|
||||||
|
oid: row.oid.trim(),
|
||||||
|
metric_name: row.metric_name.trim(),
|
||||||
|
metric_unit: row.metric_unit.trim(),
|
||||||
|
type: row.type.trim(),
|
||||||
|
}
|
||||||
|
const hasAnyValue =
|
||||||
|
normalizedRow.oid || normalizedRow.metric_name || normalizedRow.metric_unit || normalizedRow.type
|
||||||
|
return Boolean(hasAnyValue && (!normalizedRow.oid || !normalizedRow.metric_name))
|
||||||
|
})
|
||||||
|
|
||||||
const stringifySnmpOidRows = (rows: SnmpOidRow[]) => {
|
const stringifySnmpOidRows = (rows: SnmpOidRow[]) => {
|
||||||
const normalizedRows = normalizeSnmpOidRows(rows)
|
const normalizedRows = normalizeSnmpOidRows(rows)
|
||||||
return normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
return normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
||||||
@@ -491,12 +504,12 @@ const switchSnmpOidEditMode = () => {
|
|||||||
|
|
||||||
const validateSnmpOidConfigBeforeSubmit = () => {
|
const validateSnmpOidConfigBeforeSubmit = () => {
|
||||||
if (snmpOidEditMode.value === 'table') {
|
if (snmpOidEditMode.value === 'table') {
|
||||||
const rows = normalizeSnmpOidRows(snmpOidRows.value)
|
const invalidIndex = findIncompleteSnmpOidRowIndex(snmpOidRows.value)
|
||||||
const invalidIndex = rows.findIndex((row) => !row.oid || !row.metric_name)
|
|
||||||
if (invalidIndex >= 0) {
|
if (invalidIndex >= 0) {
|
||||||
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
const rows = normalizeSnmpOidRows(snmpOidRows.value)
|
||||||
formData.snmp_oids = rows.length ? JSON.stringify(rows, null, 2) : ''
|
formData.snmp_oids = rows.length ? JSON.stringify(rows, null, 2) : ''
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -509,12 +522,12 @@ const validateSnmpOidConfigBeforeSubmit = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const rows = parseSnmpOidRows(formData.snmp_oids)
|
const rows = parseSnmpOidRows(formData.snmp_oids)
|
||||||
const normalizedRows = normalizeSnmpOidRows(rows)
|
const invalidIndex = findIncompleteSnmpOidRowIndex(rows)
|
||||||
const invalidIndex = normalizedRows.findIndex((row) => !row.oid || !row.metric_name)
|
|
||||||
if (invalidIndex >= 0) {
|
if (invalidIndex >= 0) {
|
||||||
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
const normalizedRows = normalizeSnmpOidRows(rows)
|
||||||
snmpOidRows.value = normalizedRows
|
snmpOidRows.value = normalizedRows
|
||||||
formData.snmp_oids = normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
formData.snmp_oids = normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user