Исправлено отображение данных в таблице "Заполнить режимы текущей скважины" и в таблице на странице "Режимы"

This commit is contained in:
ts_salikhov 2022-09-29 13:36:07 +04:00
parent 0ce979fdc8
commit e0f8583f99
5 changed files with 41 additions and 98 deletions

View File

@ -1,7 +1,7 @@
import { InputNumber } from 'antd'
import { ReactNode } from 'react'
import { makeNumericSorter } from '../sorters'
import { makeNumericObjSorter, makeNumericSorter } from '../sorters'
import { columnPropsOther, makeGroupColumn, RenderMethod } from '.'
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
@ -21,9 +21,10 @@ export const makeNumericRender = <T extends unknown>(fixed?: number): RenderMeth
)
}
export const makeNumericColorRender = <T extends unknown>(fixed?: number, columnKey?: string): RenderMethod<T> => (value, obj) => {
export const makeNumericObjRender = (fixed?: number, columnKey?: [string, string]): RenderMethod => (value, obj) => {
let val = '-'
const isSelected = obj && columnKey ? obj[columnKey] : false
const isSelected = obj && columnKey && obj[columnKey[0]] ? obj[columnKey[0]][columnKey[1]] : false
if ((value ?? null) !== null && Number.isFinite(+value)) {
val = (fixed ?? null) !== null
? (+value).toFixed(fixed)
@ -50,17 +51,17 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co
render: makeNumericRender(fixed),
})
export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({
export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: [string, string], columnKey?: [string, string]): columnPropsOther => ({
editable: true,
initialValue: 0,
width: 100,
sorter: sorterKey ? makeNumericSorter(sorterKey) : undefined,
sorter: sorterKey ? makeNumericObjSorter(sorterKey) : undefined,
formItemRules: [{
required: true,
message: 'Введите число',
pattern: RegExpIsFloat,
}],
render: makeNumericColorRender(fixed, columnKey),
render: makeNumericObjRender(fixed, columnKey),
})
export const makeNumericColumn = (
@ -85,6 +86,28 @@ export const makeNumericColumn = (
...other
})
export const makeNumericObjColumn = (
title: ReactNode,
dataIndex: [string, string],
filters: object[],
filterDelegate: (key: [string, string]) => any,
renderDelegate: (_: any, row: object) => any,
width: string,
other?: columnPropsOther
) => ({
title: title,
dataIndex: dataIndex,
key: dataIndex,
filters: filters,
onFilter: filterDelegate ? filterDelegate(dataIndex) : null,
sorter: makeNumericObjSorter(dataIndex),
width: width,
input: <InputNumber style={{ width: '100%' }}/>,
render: renderDelegate ?? makeNumericRender(),
align: 'right',
...other
})
export const makeNumericColumnPlanFact = (
title: ReactNode,
dataIndex: string,
@ -128,13 +151,13 @@ export const makeNumericAvgRange = (
dataIndex: string,
fixed: number,
filters: object[],
filterDelegate: (key: string | number) => any,
filterDelegate: (key: [string, string]) => any,
renderDelegate: (_: any, row: object) => any,
width: string
) => makeGroupColumn(title, [
makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Min', dataIndex + 'IsMin')),
makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')),
makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Max', dataIndex + 'IsMax'))
makeNumericObjColumn('мин', [dataIndex, 'min'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'min'], [dataIndex, 'isMin'])),
makeNumericObjColumn('сред', [dataIndex, 'avg'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'avg'])),
makeNumericObjColumn('макс', [dataIndex, 'max'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'max'], [dataIndex, 'isMax']))
])
export default makeNumericColumn

View File

@ -117,24 +117,6 @@ export const EditableTable = memo(({
newData.splice(index, 1, newItem)
if (otherTableProps.objRowType) {
const newObj = {}
const objRowType = otherTableProps.objRowType
for (const itemElement in objRowType) {
if (typeof objRowType[itemElement] === 'object') {
for (const el in objRowType[itemElement]) {
if (!newObj[itemElement]) {
newObj[itemElement] = {}
}
newObj[itemElement][el] = newItem[itemElement + el[0].toUpperCase() + el.slice(1)] ?? objRowType[itemElement][el]
}
} else {
newObj[itemElement] = newItem[itemElement]
}
}
newItem = newObj
}
if (item.key === newRowKeyValue)
item.key = newRowKeyValue + newData.length

View File

@ -7,6 +7,9 @@ import { DataType } from './Columns'
export const makeNumericSorter = <T extends unknown>(key: keyof DataType<T>) =>
(a: DataType<T>, b: DataType<T>) => Number(a[key]) - Number(b[key])
export const makeNumericObjSorter = (key: [string, string]) =>
(a: DataType, b: DataType) => Number(a[key[0]][key[1]]) - Number(b[key[0]][key[1]])
export const makeStringSorter = <T extends unknown>(key: keyof DataType<T>) => (a?: DataType<T> | null, b?: DataType<T> | null) => {
if (!a && !b) return 0
if (!a) return 1

View File

@ -7,7 +7,7 @@ import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory'
import { DrillParamsService } from '@api'
import { getColumns, convertValuesInObjectsToPrimitiveValues } from '@pages/WellOperations/WellDrillParams'
import { getColumns } from '@pages/WellOperations/WellDrillParams'
export const NewParamsTable = memo(({ selectedWellsKeys }) => {
const [params, setParams] = useState([])
@ -25,7 +25,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => {
async () => {
setIsParamsModalVisible(true)
const params = await DrillParamsService.getCompositeAll(well.id)
setParams(convertValuesInObjectsToPrimitiveValues(params))
setParams(params)
},
setShowParamsLoader,
`Не удалось загрузить список режимов`,

View File

@ -12,27 +12,6 @@ import { invokeWebApiWrapperAsync } from '@components/factory'
import { DrillParamsService, WellOperationService } from '@api'
import { arrayOrDefault } from '@utils'
export function convertValuesInObjectsToPrimitiveValues(arr) {
return arr.map(param => {
const newObj = {}
for (const paramElement in param) {
if (typeof param[paramElement] === 'object') {
for (const item in param[paramElement]) {
newObj[paramElement + item[0].toUpperCase() + item.slice(1)] = param[paramElement][item]
}
} else {
// Typescript против использования числа в качестве типа значения select
if (paramElement === 'idWellSectionType') {
newObj[paramElement] = String(param[paramElement])
} else {
newObj[paramElement] = param[paramElement]
}
}
}
return newObj
})
}
export const getColumns = async (idWell) => {
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({
@ -54,51 +33,6 @@ export const getColumns = async (idWell) => {
]
}
const objRowType = {
'id': 0,
'idWell': 0,
'depth': {
'min': 0,
'max': 0
},
'idWellSectionType': 0,
'axialLoad': {
'min': 0,
'max': 0,
'avg': 0,
'isMax': false,
'isMin': false,
},
'pressure': {
'min': 0,
'max': 0,
'avg': 0,
'isMax': false,
'isMin': false,
},
'rotorTorque': {
'min': 0,
'max': 0,
'avg': 0,
'isMax': false,
'isMin': false,
},
'rotorSpeed': {
'min': 0,
'max': 0,
'avg': 0,
'isMax': false,
'isMin': false,
},
'flow': {
'min': 0,
'max': 0,
'avg': 0,
'isMax': false,
'isMin': false,
}
}
export const WellDrillParams = memo(() => {
const [params, setParams] = useState([])
const [showLoader, setShowLoader] = useState(false)
@ -109,7 +43,9 @@ export const WellDrillParams = memo(() => {
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
async () => {
const params = arrayOrDefault(await DrillParamsService.getAll(well.id))
setParams(convertValuesInObjectsToPrimitiveValues(params))
// Typescript против использования числа в качестве типа значения select
params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`)
setParams(params)
},
setShowLoader,
`Не удалось загрузить список режимов бурения`,
@ -153,7 +89,6 @@ export const WellDrillParams = memo(() => {
onRowAdd={tableHandlers.add}
onRowEdit={tableHandlers.edit}
onRowDelete={tableHandlers.delete}
objRowType={objRowType}
pagination={false}
/>
</LoaderPortal>