forked from ddrilling/asb_cloud_front
Исправлено отображение данных в таблице "Заполнить режимы текущей скважины" и в таблице на странице "Режимы"
This commit is contained in:
parent
292d4e0ef0
commit
95950458c8
@ -1,38 +1,20 @@
|
||||
import { InputNumber } from 'antd'
|
||||
import { ReactNode } from 'react'
|
||||
|
||||
import { makeNumericSorter, makeObjNumericSorter } from '../sorters'
|
||||
import { makeNumericSorter } from '../sorters'
|
||||
import { columnPropsOther, makeGroupColumn, RenderMethod } from '.'
|
||||
|
||||
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
||||
|
||||
export const makeNumericRender = <T extends unknown>(fixed?: number): RenderMethod<T> => (value) => {
|
||||
export const makeNumericRender = <T extends unknown>(fixed?: number, columnKey?: string): RenderMethod<T> => (value, obj) => {
|
||||
let val = '-'
|
||||
const isSelected = obj && columnKey ? obj[columnKey] : false
|
||||
if ((value ?? null) !== null && Number.isFinite(+value)) {
|
||||
val = (fixed ?? null) !== null
|
||||
? (+value).toFixed(fixed)
|
||||
: (+value).toPrecision(5)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={'text-align-r-container'}>
|
||||
<span>{val}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type ObjRenderType = {
|
||||
max: number
|
||||
avg: number
|
||||
min: number
|
||||
isMax: boolean
|
||||
isMin: boolean
|
||||
}
|
||||
|
||||
export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRenderType): RenderMethod<ObjRenderType> => (value: ObjRenderType) => {
|
||||
const val = key ? value[key]: '-'
|
||||
const isSelected = boolKey ? value[boolKey] : false
|
||||
|
||||
return (
|
||||
<div className={`text-align-r-container ${isSelected ? 'color-pale-green' : ''}`}>
|
||||
<span>{val}</span>
|
||||
@ -40,7 +22,7 @@ export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRende
|
||||
)
|
||||
}
|
||||
|
||||
export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({
|
||||
export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({
|
||||
editable: true,
|
||||
initialValue: 0,
|
||||
width: 100,
|
||||
@ -50,20 +32,7 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co
|
||||
message: 'Введите число',
|
||||
pattern: RegExpIsFloat,
|
||||
}],
|
||||
render: makeNumericRender(fixed),
|
||||
})
|
||||
|
||||
export const makeObjColumnOptions = (key: keyof ObjRenderType, sortedObj?: string, boolKey?: keyof ObjRenderType): columnPropsOther => ({
|
||||
editable: true,
|
||||
initialValue: 0,
|
||||
width: 100,
|
||||
sorter: sortedObj && key ? makeObjNumericSorter(sortedObj, key) : undefined,
|
||||
formItemRules: [{
|
||||
required: true,
|
||||
message: 'Введите число',
|
||||
pattern: RegExpIsFloat,
|
||||
}],
|
||||
render: makeObjRender(key, boolKey),
|
||||
render: makeNumericRender(fixed, columnKey),
|
||||
})
|
||||
|
||||
export const makeNumericColumn = (
|
||||
@ -135,9 +104,9 @@ export const makeNumericAvgRange = (
|
||||
renderDelegate: (_: any, row: object) => any,
|
||||
width: string
|
||||
) => makeGroupColumn(title, [
|
||||
makeNumericColumn('мин', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('min', dataIndex, 'isMin')),
|
||||
makeNumericColumn('сред', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('avg', dataIndex)),
|
||||
makeNumericColumn('макс', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('max', dataIndex, 'isMax'))
|
||||
makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min', dataIndex + 'IsMin')),
|
||||
makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')),
|
||||
makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Max', dataIndex + 'IsMax'))
|
||||
])
|
||||
|
||||
export default makeNumericColumn
|
||||
|
@ -7,9 +7,6 @@ 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 makeObjNumericSorter = <T extends unknown>(obj: keyof DataType<T>, key: keyof DataType<T>) =>
|
||||
(a: DataType<DataType<T>>, b: DataType<DataType<T>>) => Number(a[obj][key]) - Number(b[obj][key])
|
||||
|
||||
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
|
||||
|
@ -6,6 +6,7 @@ import { Table } from '@components/Table'
|
||||
import LoaderPortal from '@components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { DrillParamsService } from '@api'
|
||||
import { getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils'
|
||||
|
||||
import { getColumns } from '@pages/WellOperations/WellDrillParams'
|
||||
|
||||
@ -25,7 +26,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => {
|
||||
async () => {
|
||||
setIsParamsModalVisible(true)
|
||||
const params = await DrillParamsService.getCompositeAll(well.id)
|
||||
setParams(params)
|
||||
setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params))
|
||||
},
|
||||
setShowParamsLoader,
|
||||
`Не удалось загрузить список режимов`,
|
||||
|
@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react'
|
||||
|
||||
import { useWell } from '@asb/context'
|
||||
import {
|
||||
Table,
|
||||
EditableTable,
|
||||
makeSelectColumn,
|
||||
makeNumericAvgRange,
|
||||
makeNumericSorter,
|
||||
@ -10,7 +10,7 @@ import {
|
||||
import LoaderPortal from '@components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { DrillParamsService, WellOperationService } from '@api'
|
||||
import { arrayOrDefault } from '@utils'
|
||||
import { arrayOrDefault, getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils'
|
||||
|
||||
|
||||
export const getColumns = async (idWell) => {
|
||||
@ -44,9 +44,7 @@ export const WellDrillParams = memo(() => {
|
||||
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
|
||||
async () => {
|
||||
const params = arrayOrDefault(await DrillParamsService.getAll(well.id))
|
||||
// Typescript против использования числа в качестве типа значения select
|
||||
params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`)
|
||||
setParams(params)
|
||||
setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params))
|
||||
},
|
||||
setShowLoader,
|
||||
`Не удалось загрузить список режимов бурения`,
|
||||
@ -81,12 +79,15 @@ export const WellDrillParams = memo(() => {
|
||||
|
||||
return (
|
||||
<LoaderPortal show={showLoader}>
|
||||
<Table
|
||||
<EditableTable
|
||||
bordered
|
||||
size={'small'}
|
||||
columns={columns}
|
||||
dataSource={params}
|
||||
tableName={'well_drill_params'}
|
||||
onRowAdd={tableHandlers.add}
|
||||
onRowEdit={tableHandlers.edit}
|
||||
onRowDelete={tableHandlers.delete}
|
||||
pagination={false}
|
||||
/>
|
||||
</LoaderPortal>
|
||||
|
@ -0,0 +1,26 @@
|
||||
export type ObjType = {
|
||||
[key:string]: Object | any
|
||||
}
|
||||
|
||||
export function getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(arr: Array<ObjType>) {
|
||||
return arr.map(param => {
|
||||
const newObj:ObjType = {}
|
||||
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 default getArrayConvertedObjectsIntoObjectsWithPrimitiveValues
|
@ -27,3 +27,6 @@ export * from './svg'
|
||||
|
||||
export * from './table_settings'
|
||||
export type { TableColumnSettings, TableSettings, TableSettingsStore } from './table_settings'
|
||||
|
||||
export * from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues'
|
||||
export type { ObjType } from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues'
|
||||
|
Loading…
Reference in New Issue
Block a user