diff --git a/src/pages/Measure/MeasureTable.jsx b/src/pages/Measure/MeasureTable.jsx index 1f64da3..3abde58 100644 --- a/src/pages/Measure/MeasureTable.jsx +++ b/src/pages/Measure/MeasureTable.jsx @@ -1,7 +1,12 @@ import { useState, useEffect } from 'react' -import { Button, Form, Input, Timeline } from 'antd' +import { Button, Form, Input, Popconfirm, Timeline } from 'antd' import moment from 'moment' -import { CheckSquareOutlined } from '@ant-design/icons' +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' @@ -13,7 +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(0) + const [selectedTimeLineId, setSelectedTimeLineId] = useState(undefined) const [displayedValues, setDisplayedValues] = useState([]); const [editingColumns, setEditingColumns] = useState(columns); const [isTableEditing, setIsTableEditing] = useState(false); @@ -31,13 +36,12 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update useEffect(() => { let valuesToDisplay = [] - if(selectedTimeLineId === 0) { - valuesToDisplay = values.length + if(!selectedTimeLineId) + valuesToDisplay = values && values.length ? values[values.length-1] : [] - } else { + else valuesToDisplay = values.find(el => el.id === selectedTimeLineId) - } setDisplayedValues(valuesToDisplay) }, [selectedTimeLineId, values]) @@ -45,77 +49,85 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update useEffect(() => { let switchableColumns = [] - isTableEditing && editingActionName !== 'Удалить' - ? switchableColumns = createEditingColumns(columns, () => ) + isTableEditing && editingActionName !== 'delete' + ? switchableColumns = createEditingColumns(columns, () => ) : switchableColumns = createEditingColumns(columns, null) - if(editingActionName === 'Редактировать') + if(editingActionName === 'edit') measuresForm.setFieldsValue(displayedValues.data); - else if(editingActionName === 'Добавить') + else if(editingActionName === 'add') measuresForm.resetFields() setEditingColumns(switchableColumns) - }, [isTableEditing, columns, editingActionName, displayedValues.data, measuresForm]) + }, [isTableEditing, columns, editingActionName, displayedValues?.data, measuresForm]) - const buttonsConfig = [ - {name:'Добавить', key:'add'}, - {name:'Редактировать', key:'edit'}, - {name:'Удалить', key:'delete'} - ] - - const createButtons = (config, onClickDelegate) => { - return ( -