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 [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(() => { const defaultValuesToDisplay = values[values.length-1] setDisplayedValues(defaultValuesToDisplay) }, [values]) useEffect(() => { let switchableColumns = [] isTableEditing ? 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) } const checkIsDataDefault = () => displayedValues?.isDefaultData ? true : false const crudButtons =