forked from ddrilling/asb_cloud_front
CF2-49: Fixed selecting of default values to display
This commit is contained in:
parent
9973009c65
commit
c6bdb27857
@ -10,12 +10,10 @@ import '../../styles/measure.css'
|
|||||||
|
|
||||||
const format='YYYY.MM.DD HH:mm'
|
const format='YYYY.MM.DD HH:mm'
|
||||||
|
|
||||||
export const MeasureTable = ({idWell, idCategory, title, columns, values, updateMeasuresDelegate}) => {
|
export const MeasureTable = ({idWell, idCategory, title, columns, values, updateMeasures}) => {
|
||||||
var defaultDisplay = values && values.length
|
|
||||||
? values[values.length-1]
|
|
||||||
: []
|
|
||||||
|
|
||||||
const [showLoader, setShowLoader] = useState(false);
|
const [showLoader, setShowLoader] = useState(false);
|
||||||
|
const [selectedTimeLineId, setSelectedTimeLineId] = useState(0)
|
||||||
const [displayedValues, setDisplayedValues] = useState([]);
|
const [displayedValues, setDisplayedValues] = useState([]);
|
||||||
const [editingColumns, setEditingColumns] = useState(columns);
|
const [editingColumns, setEditingColumns] = useState(columns);
|
||||||
const [isTableEditing, setIsTableEditing] = useState(false);
|
const [isTableEditing, setIsTableEditing] = useState(false);
|
||||||
@ -23,6 +21,36 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
|
|
||||||
const [measuresForm] = Form.useForm();
|
const [measuresForm] = Form.useForm();
|
||||||
|
|
||||||
|
const createEditingColumns = (cols, renderDelegate) =>
|
||||||
|
cols.map(col =>
|
||||||
|
({ render: renderDelegate,
|
||||||
|
...col
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let valuesToDisplay = []
|
||||||
|
|
||||||
|
if(selectedTimeLineId === 0) {
|
||||||
|
valuesToDisplay = values.length
|
||||||
|
? values[values.length-1]
|
||||||
|
: []
|
||||||
|
} else {
|
||||||
|
valuesToDisplay = values.find(el => el.id === selectedTimeLineId)
|
||||||
|
}
|
||||||
|
|
||||||
|
setDisplayedValues(valuesToDisplay)
|
||||||
|
}, [selectedTimeLineId, values])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let switchableColumns = []
|
||||||
|
isTableEditing && editingActionName !== 'Удалить'
|
||||||
|
? switchableColumns = createEditingColumns(columns, () => <input className='w-100'></input>)
|
||||||
|
: switchableColumns = createEditingColumns(columns, null)
|
||||||
|
|
||||||
|
setEditingColumns(switchableColumns)
|
||||||
|
}, [isTableEditing, columns, editingActionName])
|
||||||
|
|
||||||
const buttonsConfig = [
|
const buttonsConfig = [
|
||||||
{name:'Добавить', key:'add'},
|
{name:'Добавить', key:'add'},
|
||||||
{name:'Редактировать', key:'edit'},
|
{name:'Редактировать', key:'edit'},
|
||||||
@ -60,7 +88,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
if(editingActionName === 'Удалить'){
|
if(editingActionName === 'Удалить'){
|
||||||
setShowLoader(true)
|
setShowLoader(true)
|
||||||
await MeasureService.markAsDelete(idWell, displayedValues.id)
|
await MeasureService.markAsDelete(idWell, displayedValues.id)
|
||||||
updateMeasuresDelegate()
|
updateMeasures()
|
||||||
setShowLoader(false)
|
setShowLoader(false)
|
||||||
setIsTableEditing(false)
|
setIsTableEditing(false)
|
||||||
} else {
|
} else {
|
||||||
@ -74,27 +102,6 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
const createEditingColumns = (cols, renderDelegate) =>
|
|
||||||
cols.map(col =>
|
|
||||||
({ render: renderDelegate,
|
|
||||||
...col
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setDisplayedValues(defaultDisplay)
|
|
||||||
}, [defaultDisplay])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let switchableColumns = []
|
|
||||||
isTableEditing && editingActionName !== 'Удалить'
|
|
||||||
? switchableColumns = createEditingColumns(columns, () => <input className='w-100'></input>)
|
|
||||||
: switchableColumns = createEditingColumns(columns, null)
|
|
||||||
|
|
||||||
setEditingColumns(switchableColumns)
|
|
||||||
}, [isTableEditing, columns, editingActionName])
|
|
||||||
|
|
||||||
|
|
||||||
let handleSubmitMeasuresForm = async (formData) => {
|
let handleSubmitMeasuresForm = async (formData) => {
|
||||||
// if(isTableEditing)
|
// if(isTableEditing)
|
||||||
// measuresForm.setFieldsValue({
|
// measuresForm.setFieldsValue({
|
||||||
@ -112,7 +119,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
setShowLoader(true)
|
setShowLoader(true)
|
||||||
await MeasureService.insert(idWell, measureParams)
|
await MeasureService.insert(idWell, measureParams)
|
||||||
setIsTableEditing(false)
|
setIsTableEditing(false)
|
||||||
updateMeasuresDelegate()
|
updateMeasures()
|
||||||
setShowLoader(false)
|
setShowLoader(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,8 +144,8 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
className={index === values.length-1
|
className={index === values.length-1
|
||||||
? 'last-measure-button'
|
? 'last-measure-button'
|
||||||
: 'measure-button'}
|
: 'measure-button'}
|
||||||
onClick={() => setDisplayedValues(values.find(el => el.id === item.id))}
|
onClick={() => setSelectedTimeLineId(item.id)}
|
||||||
dot={item.id === displayedValues.id
|
dot={item?.id === displayedValues?.id
|
||||||
? <ExclamationCircleOutlined className="timeline-clock-icon" />
|
? <ExclamationCircleOutlined className="timeline-clock-icon" />
|
||||||
: null}
|
: null}
|
||||||
>
|
>
|
||||||
@ -155,7 +162,7 @@ export const MeasureTable = ({idWell, idCategory, title, columns, values, update
|
|||||||
onFinish={handleSubmitMeasuresForm}
|
onFinish={handleSubmitMeasuresForm}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
item={displayedValues.data}
|
item={displayedValues?.data ?? []}
|
||||||
columns={editingColumns}
|
columns={editingColumns}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
|
Loading…
Reference in New Issue
Block a user