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