From 11bb5f4c180253a2f0373192e4d74586aa1ea092 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Thu, 7 Oct 2021 17:23:01 +0500 Subject: [PATCH] CF2-49: Changed 'Measures' table crud buttons --- src/pages/Measure/MeasureTable.jsx | 140 ++++++++++++++++------------- src/styles/index.css | 8 ++ src/styles/measure.css | 9 +- 3 files changed, 88 insertions(+), 69 deletions(-) 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 ( -
- {config.map(conf => { - return ( - - ) - })} -
- ) + const markMeasuresAsDeleted = async () => { + setShowLoader(true) + await MeasureService.markAsDelete(idWell, displayedValues.id) + updateMeasuresFunc() + setShowLoader(false) + setIsTableEditing(false) } - const crudButtons = createButtons(buttonsConfig, (e) => { - setEditingActionName(e.target.innerText) - setIsTableEditing(true) - }) + const checkIsDataDefault = () => + displayedValues?.isDefaultData ? true : false + + const crudButtons = +
+ + + markMeasuresAsDeleted()} + disabled={checkIsDataDefault()} + > + + +
const confirmButtons = -
-

{editingActionName} данные?

-
+
+
@@ -132,9 +144,9 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update setShowLoader(true) - if(editingActionName === 'Добавить') { + if(editingActionName === 'add') { await MeasureService.insert(idWell, measureParams) - } else if (editingActionName === 'Редактировать') { + } else if (editingActionName === 'edit') { measureParams.id = displayedValues.id measureParams.timestamp = displayedValues.timestamp await MeasureService.update(idWell, measureParams) @@ -147,11 +159,11 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update return <>   -

{title}

+

{title}

 
-
+
{isTableEditing ? confirmButtons : crudButtons @@ -184,7 +196,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update onFinish={handleSubmitMeasuresForm} > diff --git a/src/styles/index.css b/src/styles/index.css index 16aee1c..59c2d76 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -27,6 +27,14 @@ body { width: 15% } +.w-33 { + width: 33% +} + +.w-50 { + width: 50% +} + .w-100 { width: 100% } diff --git a/src/styles/measure.css b/src/styles/measure.css index a4b5320..1425fdc 100644 --- a/src/styles/measure.css +++ b/src/styles/measure.css @@ -1,4 +1,4 @@ -input { +input.measure-input { font-weight:bold; } @@ -6,13 +6,12 @@ input { width: 300px; } -.button-container { - height: 100px; - align-items: center; +.measure-buttons-container { + height: 30px; } .measure-dates { - height: calc(100% - 130px); + height: 160px; overflow-y: scroll; }