CF2-49: Removed unnecessary useEffect()

This commit is contained in:
KharchenkoVV 2021-10-08 10:50:27 +05:00
parent 49997e7449
commit 372617f314

View File

@ -18,8 +18,7 @@ const format='YYYY.MM.DD HH:mm'
export const MeasureTable = ({idWell, idCategory, title, columns, values, updateMeasuresFunc}) => {
const [showLoader, setShowLoader] = useState(false);
const [selectedTimeLineId, setSelectedTimeLineId] = useState(undefined)
const [displayedValues, setDisplayedValues] = useState([]);
const [displayedValues, setDisplayedValues] = useState({});
const [editingColumns, setEditingColumns] = useState(columns);
const [isTableEditing, setIsTableEditing] = useState(false);
const [editingActionName, setEditingActionName] = useState('');
@ -34,28 +33,20 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
)
useEffect(() => {
let valuesToDisplay = []
const defaultValuesToDisplay = values[values.length-1]
if(!selectedTimeLineId)
valuesToDisplay = values && values.length
? values[values.length-1]
: []
else
valuesToDisplay = values.find(el => el.id === selectedTimeLineId)
setDisplayedValues(valuesToDisplay)
setSelectedTimeLineId(valuesToDisplay?.id)
}, [selectedTimeLineId, values])
setDisplayedValues(defaultValuesToDisplay)
}, [values])
useEffect(() => {
let switchableColumns = []
isTableEditing && editingActionName !== 'delete'
isTableEditing
? switchableColumns = createEditingColumns(columns, () => <Input className='w-100 measure-input' />)
: switchableColumns = createEditingColumns(columns, null)
if(editingActionName === 'edit')
measuresForm.setFieldsValue(displayedValues.data);
measuresForm.setFieldsValue(displayedValues?.data);
else if(editingActionName === 'add')
measuresForm.resetFields()
@ -67,7 +58,6 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
await MeasureService.markAsDelete(idWell, displayedValues.id)
updateMeasuresFunc()
setShowLoader(false)
setIsTableEditing(false)
}
const checkIsDataDefault = () =>
@ -177,7 +167,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
<Timeline.Item
key={index}
className='measure-button'
onClick={() => setSelectedTimeLineId(item.id)}
onClick={() => setDisplayedValues(item)}
dot={item?.id === displayedValues?.id
? <CheckSquareOutlined className="timeline-clock-icon" />
: null}
@ -197,7 +187,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
onFinish={handleSubmitMeasuresForm}
>
<View
item={displayedValues?.data ?? []}
item={displayedValues?.data ?? {}}
columns={editingColumns}
/>
</Form>