Commit bb55b171 by zhaochengxiang

bug fix

parent 2ecb0e30
...@@ -360,6 +360,7 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -360,6 +360,7 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
const [form] = Form.useForm() const [form] = Form.useForm()
const tableRef = React.useRef() const tableRef = React.useRef()
const selectablePropertyTypesRef = React.useRef()
const isEditing = (record) => record.modelType?.name === editingKey const isEditing = (record) => record.modelType?.name === editingKey
...@@ -373,12 +374,6 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -373,12 +374,6 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
} }
}, [type]) }, [type])
const selectablePropertyTypes = React.useMemo(() => {
return (propertyTypes??[]).filter(item =>
(tableData??[]).map(_item => _item.modelType?.name).indexOf(item.modelType?.name)===-1 || item.modelType?.name === editingKey
)
}, [propertyTypes, tableData, editingKey])
const getPropertyTypes = () => { const getPropertyTypes = () => {
setLoadingPropertyTypes(true) setLoadingPropertyTypes(true)
dispatch({ dispatch({
...@@ -433,10 +428,11 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -433,10 +428,11 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
await save() await save()
if ( if (
(selectablePropertyTypes??[]).length>0 (selectablePropertyTypesRef.current??[]).length>0
&& (selectablePropertyTypes[0].supportedOperatorTypes??[]).length>0 && (selectablePropertyTypesRef.current[0].supportedOperatorTypes??[]).length>0
&& (selectablePropertyTypes[0].supportedMetadataTypes??[]).length>0 && (selectablePropertyTypesRef.current[0].supportedMetadataTypes??[]).length>0
) { ) {
const selectablePropertyTypes = [...selectablePropertyTypesRef.current??[]]
setTableData(prevTableData => { setTableData(prevTableData => {
return [...prevTableData??[], { return [...prevTableData??[], {
modelType: selectablePropertyTypes[0].modelType, modelType: selectablePropertyTypes[0].modelType,
...@@ -460,7 +456,8 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -460,7 +456,8 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
} }
} }
const onBatchDeleteClick = () => { const onBatchDeleteClick = (e) => {
e.stopPropagation()
setTableData(prevTableData => { setTableData(prevTableData => {
let newTableData = [...prevTableData??[]]; let newTableData = [...prevTableData??[]];
newTableData = (newTableData??[]).filter(item => (selectedRows??[]).map(_item => _item.modelType?.name).indexOf(item?.modelType?.name)===-1); newTableData = (newTableData??[]).filter(item => (selectedRows??[]).map(_item => _item.modelType?.name).indexOf(item?.modelType?.name)===-1);
...@@ -474,16 +471,16 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -474,16 +471,16 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
setSelectedRows() setSelectedRows()
} }
// const onRightEditClick = async (record) => { const onEditClick = async (record) => {
// try { try {
// await save() await save()
// setEditingKey(record?.modelType?.name) setEditingKey(record?.modelType?.name)
// setEditingModelKey(record?.modelType?.name) setEditingModelKey(record?.modelType?.name)
// } catch(e) { } catch(e) {
// } }
// } }
const onRightDeleteClick = (record) => { const onRightDeleteClick = (record) => {
if (isEditing(record)) { if (isEditing(record)) {
...@@ -507,14 +504,14 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -507,14 +504,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 = (selectablePropertyTypes??[]).findIndex(item => item.modelType?.name === changedValues['modelType']) const index = (selectablePropertyTypesRef.current??[]).findIndex(item => item.modelType?.name === changedValues['modelType'])
if (index !== -1 if (index !== -1
&& (selectablePropertyTypes[index].supportedOperatorTypes??[]).length>0 && (selectablePropertyTypesRef.current[index].supportedOperatorTypes??[]).length>0
&& (selectablePropertyTypes[index].supportedMetadataTypes??[]).length>0 && (selectablePropertyTypesRef.current[index].supportedMetadataTypes??[]).length>0
) { ) {
form?.setFieldsValue({ form?.setFieldsValue({
operatorType: selectablePropertyTypes[index].supportedOperatorTypes[0].id, operatorType: selectablePropertyTypesRef.current[index].supportedOperatorTypes[0].id,
metadataType: selectablePropertyTypes[index].supportedMetadataTypes[0].name, metadataType: selectablePropertyTypesRef.current[index].supportedMetadataTypes[0].name,
}) })
} }
} }
...@@ -560,11 +557,15 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -560,11 +557,15 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
title: col.title, title: col.title,
editing: isEditing(record), editing: isEditing(record),
editingModelKey, editingModelKey,
propertyTypes: selectablePropertyTypes, propertyTypes: selectablePropertyTypesRef.current,
}), }),
} }
}) })
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>
...@@ -588,6 +589,10 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) { ...@@ -588,6 +589,10 @@ const Strategy = React.forwardRef(function ({ type, task }, ref) {
setSelectedRows(selectedRows) setSelectedRows(selectedRows)
}, },
}} }}
onRowClick={(event, record) => {
event.stopPropagation()
onEditClick(record)
}}
pagination={false} pagination={false}
shouldRowContextMenu={(record) => { shouldRowContextMenu={(record) => {
return true return true
......
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