diff --git a/src/components/Table/SelectFromDictionary.tsx b/src/components/Table/SelectFromDictionary.tsx new file mode 100644 index 0000000..25259cd --- /dev/null +++ b/src/components/Table/SelectFromDictionary.tsx @@ -0,0 +1,23 @@ +import {Select} from 'antd' + +const { Option } = Select + +interface StandardComponentProps { + dictionary: Map, +} + +export const SelectFromDictionary = ({dictionary, ...other}: StandardComponentProps) =>{ + const options: any[] = [] + dictionary.forEach((value, key) => { + options.push( + ) + }) + + return +} diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts index 47b36eb..46cb2fc 100644 --- a/src/components/Table/index.ts +++ b/src/components/Table/index.ts @@ -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' @@ -80,4 +81,4 @@ export const makePaginationObject = (paginationContainer:PaginationContainer, .. total: paginationContainer.count ?? paginationContainer.items?.length ?? 0, current: page, } -} \ No newline at end of file +} diff --git a/src/pages/WellOperations/WellOperationsEditor.jsx b/src/pages/WellOperations/WellOperationsEditor.jsx index 6f69271..ab45ace 100644 --- a/src/pages/WellOperations/WellOperationsEditor.jsx +++ b/src/pages/WellOperations/WellOperationsEditor.jsx @@ -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 = - - const SelectorOperationCategory = - const columns = [ makeColumn('Конструкция секции','idWellSectionType', { editable:true, - input:SelectorSectionType, - width:105, - render:(_, record)=>getNameById(dictionarySectionType, record.idWellSectionType) + input:, + width:110, + render:(_, record)=>getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType) }), makeColumn('Операция','idCategory', { editable:true, - input:SelectorOperationCategory, + input:, width:200, - render:(_, record)=>getNameById(dictionaryOperationCategory, record.idCategory) + render:(_, record)=>getByKeyOrReturnKey(dictionaryOperationCategory, record.idCategory) }), makeColumn('Доп. инфо','categoryInfo', {editable:true, width:300, input: