Commit bcdf426a by zhaochengxiang

bug fix

parent bb55b171
...@@ -357,10 +357,21 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -357,10 +357,21 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
const [tableData, setTableData] = React.useState() const [tableData, setTableData] = React.useState()
const [editingKey, setEditingKey] = React.useState('') const [editingKey, setEditingKey] = React.useState('')
const [editingModelKey, setEditingModelKey] = React.useState('') const [editingModelKey, setEditingModelKey] = React.useState('')
const [selectablePropertyTypes, setSelectablePropertyTypes] = React.useState()
const [form] = Form.useForm() const [form] = Form.useForm()
const tableRef = React.useRef() const tableRef = React.useRef()
const selectablePropertyTypesRef = React.useRef()
const selectablePropertyTypeRef = React.useRef()
selectablePropertyTypeRef.current = selectablePropertyTypes
React.useEffect(() => {
setSelectablePropertyTypes(
(propertyTypes??[]).filter(item =>
(tableData??[]).map(_item => _item.modelType?.name).indexOf(item.modelType?.name)===-1 || item.modelType?.name === editingKey
)
)
}, [propertyTypes, tableData, editingKey])
const isEditing = (record) => record.modelType?.name === editingKey const isEditing = (record) => record.modelType?.name === editingKey
...@@ -402,16 +413,13 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -402,16 +413,13 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
const metadataIndex = (propertyTypes[modelIndex].supportedMetadataTypes??[]).findIndex(item => item.name === rows.metadataType) const metadataIndex = (propertyTypes[modelIndex].supportedMetadataTypes??[]).findIndex(item => item.name === rows.metadataType)
if (operatorIndex !== -1 && metadataIndex !== -1) { if (operatorIndex !== -1 && metadataIndex !== -1) {
setTableData(prevTableData => { const newTableData = [...tableData??[]];
let newTableData = [...prevTableData??[]]; (newTableData??[]).splice(index, 1, {
(newTableData??[]).splice(index, 1, { modelType: propertyTypes[modelIndex].modelType,
modelType: propertyTypes[modelIndex].modelType, operatorType: propertyTypes[modelIndex].supportedOperatorTypes[operatorIndex],
operatorType: propertyTypes[modelIndex].supportedOperatorTypes[operatorIndex], metadataType: propertyTypes[modelIndex].supportedMetadataTypes[metadataIndex],
metadataType: propertyTypes[modelIndex].supportedMetadataTypes[metadataIndex], });
}); setTableData(newTableData)
return newTableData;
})
} }
} }
...@@ -427,30 +435,31 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -427,30 +435,31 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
try { try {
await save() await save()
const currentSelectablePropertyTypes = [...selectablePropertyTypeRef.current??[]]
if ( if (
(selectablePropertyTypesRef.current??[]).length>0 (currentSelectablePropertyTypes??[]).length>0
&& (selectablePropertyTypesRef.current[0].supportedOperatorTypes??[]).length>0 && (currentSelectablePropertyTypes[0].supportedOperatorTypes??[]).length>0
&& (selectablePropertyTypesRef.current[0].supportedMetadataTypes??[]).length>0 && (currentSelectablePropertyTypes[0].supportedMetadataTypes??[]).length>0
) { ) {
const selectablePropertyTypes = [...selectablePropertyTypesRef.current??[]]
setTableData(prevTableData => { setTableData(prevTableData => {
return [...prevTableData??[], { return [...prevTableData??[], {
modelType: selectablePropertyTypes[0].modelType, modelType: currentSelectablePropertyTypes[0].modelType,
operatorType: selectablePropertyTypes[0].supportedOperatorTypes[0], operatorType: currentSelectablePropertyTypes[0].supportedOperatorTypes[0],
metadataType: selectablePropertyTypes[0].supportedMetadataTypes[0], metadataType: currentSelectablePropertyTypes[0].supportedMetadataTypes[0],
}] }]
}) })
setEditingKey(selectablePropertyTypes[0].modelType?.name) setEditingKey(currentSelectablePropertyTypes[0].modelType?.name)
setEditingModelKey(selectablePropertyTypes[0].modelType?.name) setEditingModelKey(currentSelectablePropertyTypes[0].modelType?.name)
form?.setFieldsValue({ form?.setFieldsValue({
modelType: selectablePropertyTypes[0].modelType?.name, modelType: currentSelectablePropertyTypes[0].modelType?.name,
operatorType: selectablePropertyTypes[0].supportedOperatorTypes[0].id, operatorType: currentSelectablePropertyTypes[0].supportedOperatorTypes[0].id,
metadataType: selectablePropertyTypes[0].supportedMetadataTypes[0].name, metadataType: currentSelectablePropertyTypes[0].supportedMetadataTypes[0].name,
}) })
} else { } else {
showMessage('warn', '模型属性都设置了策略') showMessage('warn', '模型属性都设置了策略')
} }
} catch(e) { } catch(e) {
} }
...@@ -477,6 +486,12 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -477,6 +486,12 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
setEditingKey(record?.modelType?.name) setEditingKey(record?.modelType?.name)
setEditingModelKey(record?.modelType?.name) setEditingModelKey(record?.modelType?.name)
form?.setFieldsValue({
modelType: record?.modelType?.name,
operatorType: record?.operatorType?.id,
metadataType: record?.metadataType?.name,
})
} catch(e) { } catch(e) {
} }
...@@ -504,14 +519,14 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -504,14 +519,14 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
const onValuesChange = (changedValues, allValues) => { const onValuesChange = (changedValues, allValues) => {
if (changedValues.hasOwnProperty('modelType')) { if (changedValues.hasOwnProperty('modelType')) {
setEditingModelKey(changedValues['modelType']) setEditingModelKey(changedValues['modelType'])
const index = (selectablePropertyTypesRef.current??[]).findIndex(item => item.modelType?.name === changedValues['modelType']) const index = (selectablePropertyTypes??[]).findIndex(item => item.modelType?.name === changedValues['modelType'])
if (index !== -1 if (index !== -1
&& (selectablePropertyTypesRef.current[index].supportedOperatorTypes??[]).length>0 && (selectablePropertyTypes[index].supportedOperatorTypes??[]).length>0
&& (selectablePropertyTypesRef.current[index].supportedMetadataTypes??[]).length>0 && (selectablePropertyTypes[index].supportedMetadataTypes??[]).length>0
) { ) {
form?.setFieldsValue({ form?.setFieldsValue({
operatorType: selectablePropertyTypesRef.current[index].supportedOperatorTypes[0].id, operatorType: selectablePropertyTypes[index].supportedOperatorTypes[0].id,
metadataType: selectablePropertyTypesRef.current[index].supportedMetadataTypes[0].name, metadataType: selectablePropertyTypes[index].supportedMetadataTypes[0].name,
}) })
} }
} }
...@@ -557,15 +572,11 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -557,15 +572,11 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
title: col.title, title: col.title,
editing: isEditing(record), editing: isEditing(record),
editingModelKey, editingModelKey,
propertyTypes: selectablePropertyTypesRef.current, propertyTypes: selectablePropertyTypes,
}), }),
} }
}) })
selectablePropertyTypesRef.current = (propertyTypes??[]).filter(item =>
(tableData??[]).map(_item => _item.modelType?.name).indexOf(item.modelType?.name)===-1 || item.modelType?.name === editingKey
)
return ( return (
<Spin spinning={loadingPropertyTypes}> <Spin spinning={loadingPropertyTypes}>
<div> <div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment