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 { ExclamationCircleOutlined } from '@ant-design/icons'
|
||||||
import { View } from './View'
|
import { View } from './View'
|
||||||
import LoaderPortal from '../../components/LoaderPortal'
|
import LoaderPortal from '../../components/LoaderPortal'
|
||||||
|
import { MeasureService } from '../../services/api'
|
||||||
import '../../styles/index.css'
|
import '../../styles/index.css'
|
||||||
import '../../styles/measure.css'
|
import '../../styles/measure.css'
|
||||||
|
|
||||||
const format='YYYY.MM.DD HH:mm'
|
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
|
var defaultDisplay = values && values.length
|
||||||
? values[values.length-1]
|
? values[values.length-1]
|
||||||
: []
|
: []
|
||||||
@ -55,7 +56,20 @@ export const MeasureTable = ({title, columns, values}) => {
|
|||||||
<div className='w-300px'>
|
<div className='w-300px'>
|
||||||
<h3 style={{textAlign: 'center'}}>{editingActionName} данные?</h3>
|
<h3 style={{textAlign: 'center'}}>{editingActionName} данные?</h3>
|
||||||
<div className='d-flex mt-20px'>
|
<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>
|
<Button key='decline' className='w-100' onClick={()=> setIsTableEditing(false)}>Нет</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -78,7 +92,7 @@ export const MeasureTable = ({title, columns, values}) => {
|
|||||||
: switchableColumns = createEditingColumns(columns, null)
|
: switchableColumns = createEditingColumns(columns, null)
|
||||||
|
|
||||||
setEditingColumns(switchableColumns)
|
setEditingColumns(switchableColumns)
|
||||||
}, [isTableEditing])
|
}, [isTableEditing, columns, editingActionName])
|
||||||
|
|
||||||
|
|
||||||
let handleSubmitMeasuresForm = async (formData) => {
|
let handleSubmitMeasuresForm = async (formData) => {
|
||||||
@ -86,10 +100,19 @@ export const MeasureTable = ({title, columns, values}) => {
|
|||||||
// measuresForm.setFieldsValue({
|
// measuresForm.setFieldsValue({
|
||||||
// ...displayedValues
|
// ...displayedValues
|
||||||
// });
|
// });
|
||||||
|
|
||||||
measuresForm.validateFields()
|
measuresForm.validateFields()
|
||||||
|
|
||||||
|
const measureParams = {
|
||||||
|
idWell: idWell,
|
||||||
|
idCategory: idCategory,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
data: formData
|
||||||
|
}
|
||||||
|
|
||||||
setShowLoader(true)
|
setShowLoader(true)
|
||||||
|
await MeasureService.insert(idWell, measureParams)
|
||||||
|
setIsTableEditing(false)
|
||||||
|
updateMeasuresDelegate()
|
||||||
setShowLoader(false)
|
setShowLoader(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ export default function Measure({idWell}){
|
|||||||
const [fluidValues, setFluidValues] = useState([])
|
const [fluidValues, setFluidValues] = useState([])
|
||||||
const [mudValues, setMudValues] = useState([])
|
const [mudValues, setMudValues] = useState([])
|
||||||
const [nnbValues, setNnbValues] = useState([])
|
const [nnbValues, setNnbValues] = useState([])
|
||||||
|
const [isMeasuresUpdating, setIsMeasuresUpdating] = useState(false)
|
||||||
|
|
||||||
const updateCurrentValues = () => invokeWebApiWrapperAsync(async()=>{
|
const updateCurrentValues = () => invokeWebApiWrapperAsync(async()=>{
|
||||||
const measures = await MeasureService.getHisory(idWell)
|
const measures = await MeasureService.getHisory(idWell)
|
||||||
@ -26,24 +27,33 @@ export default function Measure({idWell}){
|
|||||||
,setShowLoader
|
,setShowLoader
|
||||||
,`Не удалось загрузить последние данные по скважине ${idWell}`)
|
,`Не удалось загрузить последние данные по скважине ${idWell}`)
|
||||||
|
|
||||||
useEffect(updateCurrentValues, [idWell])
|
useEffect(updateCurrentValues, [idWell, isMeasuresUpdating])
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<LoaderPortal show={showLoader}>
|
<LoaderPortal show={showLoader}>
|
||||||
<MeasureTable
|
<MeasureTable
|
||||||
|
idWell={idWell}
|
||||||
|
idCategory={1}
|
||||||
title='Замер бурового раствора'
|
title='Замер бурового раствора'
|
||||||
columns={columnsDrillingFluid}
|
columns={columnsDrillingFluid}
|
||||||
values={fluidValues}
|
values={fluidValues}
|
||||||
|
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||||
/>
|
/>
|
||||||
<MeasureTable
|
<MeasureTable
|
||||||
|
idWell={idWell}
|
||||||
|
idCategory={2}
|
||||||
title='Шламограмма'
|
title='Шламограмма'
|
||||||
columns={columnsMudDiagram}
|
columns={columnsMudDiagram}
|
||||||
values={mudValues}
|
values={mudValues}
|
||||||
|
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||||
/>
|
/>
|
||||||
<MeasureTable
|
<MeasureTable
|
||||||
|
idWell={idWell}
|
||||||
|
idCategory={3}
|
||||||
title='ННБ'
|
title='ННБ'
|
||||||
columns={columnsNnb}
|
columns={columnsNnb}
|
||||||
values={nnbValues}
|
values={nnbValues}
|
||||||
|
updateMeasuresDelegate = {() => setIsMeasuresUpdating(true)}
|
||||||
/>
|
/>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user