import { useState, useEffect } from 'react' import { Button, Form, Input, Popconfirm, Timeline } from 'antd' import moment from 'moment' import { CheckSquareOutlined, EditOutlined, SaveOutlined, PlusOutlined, CloseCircleOutlined, DeleteOutlined } from '@ant-design/icons' import { View } from './View' import LoaderPortal from '../../components/LoaderPortal' import { MeasureService } from '../../services/api' import '../../styles/index.css' import '../../styles/measure.css' 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 [editingColumns, setEditingColumns] = useState(columns); const [isTableEditing, setIsTableEditing] = useState(false); const [editingActionName, setEditingActionName] = useState(''); const [measuresForm] = Form.useForm(); const createEditingColumns = (cols, renderDelegate) => cols.map(col => ({ render: renderDelegate, ...col }) ) useEffect(() => { let valuesToDisplay = [] 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]) useEffect(() => { let switchableColumns = [] isTableEditing && editingActionName !== 'delete' ? switchableColumns = createEditingColumns(columns, () => ) : switchableColumns = createEditingColumns(columns, null) if(editingActionName === 'edit') measuresForm.setFieldsValue(displayedValues.data); else if(editingActionName === 'add') measuresForm.resetFields() setEditingColumns(switchableColumns) }, [isTableEditing, columns, editingActionName, displayedValues?.data, measuresForm]) const markMeasuresAsDeleted = async () => { setShowLoader(true) await MeasureService.markAsDelete(idWell, displayedValues.id) updateMeasuresFunc() setShowLoader(false) setIsTableEditing(false) } const checkIsDataDefault = () => displayedValues?.isDefaultData ? true : false const crudButtons =