forked from ddrilling/asb_cloud_front
CF2-49: Added 'Insert' and 'Delete' actions
This commit is contained in:
parent
cf0b3161f0
commit
9973009c65
@ -4,12 +4,13 @@ import moment from 'moment'
|
||||
import { ExclamationCircleOutlined } 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 = ({title, columns, values}) => {
|
||||
export const MeasureTable = ({idWell, idCategory, title, columns, values, updateMeasuresDelegate}) => {
|
||||
var defaultDisplay = values && values.length
|
||||
? values[values.length-1]
|
||||
: []
|
||||
@ -55,7 +56,20 @@ export const MeasureTable = ({title, columns, values}) => {
|
||||
<div className='w-300px'>
|
||||
<h3 style={{textAlign: 'center'}}>{editingActionName} данные?</h3>
|
||||
<div className='d-flex mt-20px'>
|
||||
<Button key='confirm' className='w-100' onClick={()=> measuresForm.submit()}>Да</Button>
|
||||
<Button key='confirm' className='w-100' onClick={async () => {
|
||||
if(editingActionName === 'Удалить'){
|
||||
setShowLoader(true)
|
||||
await MeasureService.markAsDelete(idWell, displayedValues.id)
|
||||
updateMeasuresDelegate()
|
||||
setShowLoader(false)
|
||||
setIsTableEditing(false)
|
||||
} else {
|
||||
measuresForm.submit()
|
||||
}
|
||||
}}
|
||||
>
|
||||
Да
|
||||
</Button>
|
||||
<Button key='decline' className='w-100' onClick={()=> setIsTableEditing(false)}>Нет</Button>
|
||||
</div>
|
||||
</div>
|
||||
@ -78,7 +92,7 @@ export const MeasureTable = ({title, columns, values}) => {
|
||||
: switchableColumns = createEditingColumns(columns, null)
|
||||
|
||||
setEditingColumns(switchableColumns)
|
||||
}, [isTableEditing])
|
||||
}, [isTableEditing, columns, editingActionName])
|
||||
|
||||
|
||||
let handleSubmitMeasuresForm = async (formData) => {
|
||||
@ -86,10 +100,19 @@ export const MeasureTable = ({title, columns, values}) => {
|
||||
// measuresForm.setFieldsValue({
|
||||
// ...displayedValues
|
||||
// });
|
||||
|
||||
measuresForm.validateFields()
|
||||
|
||||
const measureParams = {
|
||||
idWell: idWell,
|
||||
idCategory: idCategory,
|
||||
timestamp: new Date().toISOString(),
|
||||
data: formData
|
||||
}
|
||||
|
||||
setShowLoader(true)
|
||||
await MeasureService.insert(idWell, measureParams)
|
||||
setIsTableEditing(false)
|
||||
updateMeasuresDelegate()
|
||||
setShowLoader(false)
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ export default function Measure({idWell}){
|
||||
const [fluidValues, setFluidValues] = useState([])
|
||||
const [mudValues, setMudValues] = useState([])
|
||||
const [nnbValues, setNnbValues] = useState([])
|
||||
const [isMeasuresUpdating, setIsMeasuresUpdating] = useState(false)
|
||||
|
||||
const updateCurrentValues = () => invokeWebApiWrapperAsync(async()=>{
|
||||
const measures = await MeasureService.getHisory(idWell)
|
||||
@ -26,24 +27,33 @@ export default function Measure({idWell}){
|
||||
,setShowLoader
|
||||
,`Не удалось загрузить последние данные по скважине ${idWell}`)
|
||||
|
||||
useEffect(updateCurrentValues, [idWell])
|
||||
useEffect(updateCurrentValues, [idWell, isMeasuresUpdating])
|
||||
|
||||
return <>
|
||||
<LoaderPortal show={showLoader}>
|
||||
<MeasureTable
|
||||
idWell={idWell}
|
||||
idCategory={1}
|
||||
title='Замер бурового раствора'
|
||||
columns={columnsDrillingFluid}
|
||||
values={fluidValues}
|
||||
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||
/>
|
||||
<MeasureTable
|
||||
idWell={idWell}
|
||||
idCategory={2}
|
||||
title='Шламограмма'
|
||||
columns={columnsMudDiagram}
|
||||
values={mudValues}
|
||||
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||
/>
|
||||
<MeasureTable
|
||||
idWell={idWell}
|
||||
idCategory={3}
|
||||
title='ННБ'
|
||||
columns={columnsNnb}
|
||||
values={nnbValues}
|
||||
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||
/>
|
||||
</LoaderPortal>
|
||||
</>
|
||||
|
Loading…
Reference in New Issue
Block a user