Added filters to WellOperations Plan/Fact tables

This commit is contained in:
KharchenkoVV 2021-08-30 15:53:08 +05:00
parent 7a7a4663c5
commit fb8d693a15
2 changed files with 27 additions and 3 deletions

View File

@ -92,6 +92,15 @@ export const makeStringSorter = (key: string) => (a: any, b: any) =>
return 0
}
export const makeDateSorter = (key: string) => (a: any, b: any) => {
const date = new Date(a[key])
if(Number.isNaN(date.getTime()))
throw new Error('Date column contains not date formatted string(s)')
return date.getTime() - new Date(b[key]).getTime()
}
export const makeGroupColumn = (title: string, children: object[]) => ({
title: title,
children: children,

View File

@ -1,7 +1,14 @@
import { useState, useEffect } from 'react'
import { Input } from 'antd'
import moment from 'moment'
import { EditableTable, DatePickerWrapper, SelectFromDictionary, numericColumnOptions, makeColumn } from "../../components/Table"
import {
EditableTable,
DatePickerWrapper,
SelectFromDictionary,
makeColumn,
numericColumnOptions,
makeNumericSorter,
makeDateSorter } from "../../components/Table"
import LoaderPortal from '../../components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '../../components/factory'
import { WellOperationService} from '../../services/api'
@ -12,6 +19,11 @@ const { TextArea } = Input;
const basePageSize = 160;
const format='YYYY.MM.DD HH:mm'
const numericSortColumnOptions = Object.assign({
sorter: makeNumericSorter('wellDepth')
}, numericColumnOptions)
export const WellOperationsEditor = ({idWell, idType}) => {
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize})
const [paginationTotal, setPaginationTotal] = useState(0)
@ -31,7 +43,9 @@ export const WellOperationsEditor = ({idWell, idType}) => {
async () => {
const skip = ((pageNumAndPageSize.current - 1) * pageNumAndPageSize.pageSize) || 0
const take = pageNumAndPageSize.pageSize
const paginatedOperations = await WellOperationService.getOperations(idWell, idType, undefined, undefined, undefined, undefined, undefined, undefined, skip, take )
const paginatedOperations = await WellOperationService.getOperations(idWell,
idType, undefined, undefined, undefined, undefined,
undefined, undefined, skip, take )
const operations = paginatedOperations?.items ?? []
setOperations(operations)
const total = paginatedOperations.count?? paginatedOperations.items?.length ?? 0
@ -57,11 +71,12 @@ export const WellOperationsEditor = ({idWell, idType}) => {
render:(_, record)=>getByKeyOrReturnKey(dictionaryOperationCategory, record.idCategory)
}),
makeColumn('Доп. инфо','categoryInfo', {editable:true, width:300, input:<TextArea/>}),
makeColumn('Глубина забоя','wellDepth', numericColumnOptions),
makeColumn('Глубина забоя','wellDepth', numericSortColumnOptions),
makeColumn('Время начала','startDate', {
editable:true,
width:200,
input:<DatePickerWrapper/>,
sorter: makeDateSorter('startDate'),
render:(_, record) => moment.utc(record.startDate).local().format(format)
}),
makeColumn('Часы','durationHours', numericColumnOptions),