forked from ddrilling/asb_cloud_front
Исправлено отображение данных в таблице "Заполнить режимы текущей скважины" и в таблице на странице "Режимы"
This commit is contained in:
parent
95950458c8
commit
b74d6d1e4f
@ -6,7 +6,22 @@ import { columnPropsOther, makeGroupColumn, RenderMethod } from '.'
|
||||
|
||||
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
||||
|
||||
export const makeNumericRender = <T extends unknown>(fixed?: number, columnKey?: string): RenderMethod<T> => (value, obj) => {
|
||||
export const makeNumericRender = <T extends unknown>(fixed?: number): RenderMethod<T> => (value) => {
|
||||
let val = '-'
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
export const makeNumericColorRender = <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)) {
|
||||
@ -22,7 +37,7 @@ export const makeNumericRender = <T extends unknown>(fixed?: number, columnKey?:
|
||||
)
|
||||
}
|
||||
|
||||
export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({
|
||||
export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({
|
||||
editable: true,
|
||||
initialValue: 0,
|
||||
width: 100,
|
||||
@ -32,7 +47,20 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, col
|
||||
message: 'Введите число',
|
||||
pattern: RegExpIsFloat,
|
||||
}],
|
||||
render: makeNumericRender(fixed, columnKey),
|
||||
render: makeNumericRender(fixed),
|
||||
})
|
||||
|
||||
export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({
|
||||
editable: true,
|
||||
initialValue: 0,
|
||||
width: 100,
|
||||
sorter: sorterKey ? makeNumericSorter(sorterKey) : undefined,
|
||||
formItemRules: [{
|
||||
required: true,
|
||||
message: 'Введите число',
|
||||
pattern: RegExpIsFloat,
|
||||
}],
|
||||
render: makeNumericColorRender(fixed, columnKey),
|
||||
})
|
||||
|
||||
export const makeNumericColumn = (
|
||||
@ -104,9 +132,9 @@ export const makeNumericAvgRange = (
|
||||
renderDelegate: (_: any, row: object) => any,
|
||||
width: string
|
||||
) => makeGroupColumn(title, [
|
||||
makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min', dataIndex + 'IsMin')),
|
||||
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, makeNumericColumnOptions(fixed, dataIndex + 'Max', dataIndex + 'IsMax'))
|
||||
makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Max', dataIndex + 'IsMax'))
|
||||
])
|
||||
|
||||
export default makeNumericColumn
|
||||
|
@ -6,9 +6,8 @@ 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'
|
||||
import { getColumns, convertValuesInObjectsToPrimitiveValues } from '@pages/WellOperations/WellDrillParams'
|
||||
|
||||
export const NewParamsTable = memo(({ selectedWellsKeys }) => {
|
||||
const [params, setParams] = useState([])
|
||||
@ -26,7 +25,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => {
|
||||
async () => {
|
||||
setIsParamsModalVisible(true)
|
||||
const params = await DrillParamsService.getCompositeAll(well.id)
|
||||
setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params))
|
||||
setParams(convertValuesInObjectsToPrimitiveValues(params))
|
||||
},
|
||||
setShowParamsLoader,
|
||||
`Не удалось загрузить список режимов`,
|
||||
|
@ -10,8 +10,28 @@ import {
|
||||
import LoaderPortal from '@components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||
import { DrillParamsService, WellOperationService } from '@api'
|
||||
import { arrayOrDefault, getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils'
|
||||
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)
|
||||
@ -44,7 +64,7 @@ export const WellDrillParams = memo(() => {
|
||||
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
|
||||
async () => {
|
||||
const params = arrayOrDefault(await DrillParamsService.getAll(well.id))
|
||||
setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params))
|
||||
setParams(convertValuesInObjectsToPrimitiveValues(params))
|
||||
},
|
||||
setShowLoader,
|
||||
`Не удалось загрузить список режимов бурения`,
|
||||
|
@ -1,26 +0,0 @@
|
||||
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,6 +27,3 @@ 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