forked from ddrilling/asb_cloud_front
Add SelectFromDictionary
This commit is contained in:
parent
a1173fb6a4
commit
d9969a7468
23
src/components/Table/SelectFromDictionary.tsx
Normal file
23
src/components/Table/SelectFromDictionary.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import {Select} from 'antd'
|
||||
|
||||
const { Option } = Select
|
||||
|
||||
interface StandardComponentProps {
|
||||
dictionary: Map<any, any>,
|
||||
}
|
||||
|
||||
export const SelectFromDictionary = ({dictionary, ...other}: StandardComponentProps) =>{
|
||||
const options: any[] = []
|
||||
dictionary.forEach((value, key) => {
|
||||
options.push(
|
||||
<Option
|
||||
key={key}
|
||||
value={key}>
|
||||
{value}
|
||||
</Option>)
|
||||
})
|
||||
|
||||
return <Select {...other}>
|
||||
{options}
|
||||
</Select>
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
export { Table } from 'antd'
|
||||
export { EditableTable } from './EditableTable'
|
||||
export { DatePickerWrapper } from './DatePickerWrapper'
|
||||
export { Table } from 'antd'
|
||||
export { SelectFromDictionary } from './SelectFromDictionary'
|
||||
|
||||
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
||||
export const formatDate='YYYY.MM.DD HH:mm'
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Input, Select } from 'antd'
|
||||
import { Input } from 'antd'
|
||||
import moment from 'moment'
|
||||
import { EditableTable, DatePickerWrapper, numericColumnOptions, makeColumn } from "../../components/Table"
|
||||
import { EditableTable, DatePickerWrapper, SelectFromDictionary, numericColumnOptions, makeColumn } from "../../components/Table"
|
||||
import LoaderPortal from '../../components/LoaderPortal'
|
||||
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
||||
import { WellOperationService} from '../../services/api'
|
||||
import { dictionarySectionType, getNameById } from './dictionary'
|
||||
import { dictionarySectionType, getByKeyOrReturnKey } from './dictionary'
|
||||
|
||||
const { Option } = Select
|
||||
const { TextArea } = Input;
|
||||
|
||||
const basePageSize = 160;
|
||||
@ -16,14 +15,16 @@ const format='YYYY.MM.DD HH:mm'
|
||||
export const WellOperationsEditor = ({idWell, idType}) => {
|
||||
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize})
|
||||
const [paginationTotal, setPaginationTotal] = useState(0)
|
||||
const [dictionaryOperationCategory, setDictionaryOperationCategory] = useState([])
|
||||
const [dictionaryOperationCategory, setDictionaryOperationCategory] = useState(new Map())
|
||||
const [operations, setOperations] = useState([])
|
||||
const [showLoader, setShowLoader] = useState(false)
|
||||
|
||||
useEffect(() => invokeWebApiWrapperAsync(
|
||||
async () => {
|
||||
const r = await WellOperationService.getCategories(idWell)
|
||||
setDictionaryOperationCategory(r)
|
||||
const categories = await WellOperationService.getCategories(idWell)
|
||||
const dictCategories = new Map()
|
||||
categories?.forEach((item) => dictCategories.set(item.id, item.name))
|
||||
setDictionaryOperationCategory(dictCategories)
|
||||
}),[idWell])
|
||||
|
||||
const updateOperations = () => invokeWebApiWrapperAsync(
|
||||
@ -42,34 +43,18 @@ export const WellOperationsEditor = ({idWell, idType}) => {
|
||||
|
||||
useEffect(updateOperations, [idWell, idType, pageNumAndPageSize])
|
||||
|
||||
const SelectorSectionType = <Select>
|
||||
{dictionarySectionType.map(item =><Option
|
||||
key={item.id}
|
||||
value={item.id}>
|
||||
{item.name}
|
||||
</Option>)}
|
||||
</Select>
|
||||
|
||||
const SelectorOperationCategory = <Select>
|
||||
{dictionaryOperationCategory.map(item =><Option
|
||||
key={item.id}
|
||||
value={item.id}>
|
||||
{item.name}
|
||||
</Option>)}
|
||||
</Select>
|
||||
|
||||
const columns = [
|
||||
makeColumn('Конструкция секции','idWellSectionType', {
|
||||
editable:true,
|
||||
input:SelectorSectionType,
|
||||
width:105,
|
||||
render:(_, record)=>getNameById(dictionarySectionType, record.idWellSectionType)
|
||||
input:<SelectFromDictionary dictionary={dictionarySectionType}/>,
|
||||
width:110,
|
||||
render:(_, record)=>getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType)
|
||||
}),
|
||||
makeColumn('Операция','idCategory', {
|
||||
editable:true,
|
||||
input:SelectorOperationCategory,
|
||||
input:<SelectFromDictionary dictionary={dictionaryOperationCategory}/>,
|
||||
width:200,
|
||||
render:(_, record)=>getNameById(dictionaryOperationCategory, record.idCategory)
|
||||
render:(_, record)=>getByKeyOrReturnKey(dictionaryOperationCategory, record.idCategory)
|
||||
}),
|
||||
makeColumn('Доп. инфо','categoryInfo', {editable:true, width:300, input:<TextArea/>}),
|
||||
makeColumn('Глубина забоя','wellDepth', numericColumnOptions),
|
||||
|
@ -1,15 +1,14 @@
|
||||
export const getNameById = (dictionary, id) => {
|
||||
if(!dictionary?.length)
|
||||
return id
|
||||
const item = dictionary.find(i => i?.id === id)
|
||||
return item?.name ?? id
|
||||
}
|
||||
export const dictionarySectionType = new Map([
|
||||
[1, 'Пилотный ствол'],
|
||||
[2, 'Направление'],
|
||||
[3, 'Кондуктор'],
|
||||
[4, 'Эксплуатационная колонна'],
|
||||
[5, 'Транспортный ствол'],
|
||||
[6, 'Хвостовик'],
|
||||
])
|
||||
|
||||
export const dictionarySectionType = [
|
||||
{id:1, name:'Пилотный ствол'},
|
||||
{id:2, name:'Направление'},
|
||||
{id:3, name:'Кондуктор'},
|
||||
{id:4, name:'Эксплуатационная колонна'},
|
||||
{id:5, name:'Транспортный ствол'},
|
||||
{id:6, name:'Хвостовик'},
|
||||
]
|
||||
export const getByKeyOrReturnKey = (dictionary, key) => {
|
||||
if(!dictionary)
|
||||
return key
|
||||
return dictionary.get(key) ?? key
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user