import { Button, Layout } from 'antd' import { CloseOutlined, FileWordOutlined, LoadingOutlined, ReloadOutlined, WarningOutlined } from '@ant-design/icons' import { memo, useCallback, useEffect, useState } from 'react' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { arrayOrDefault, formatDate } from '@utils' import { DrillingProgramService } from '@api' import CategoryAdder from './CategoryAdder' import CategoryRender from './CategoryRender' import CategoryEditor from './CategoryEditor' import CategoryHistory from './CategoryHistory' import '@styles/drilling_program.less' const idStateNotInitialized = 0 const idStateApproving = 1 const idStateCreating = 2 const idStateReady = 3 const idStateError = 4 const idStateUnknown = -1 const stateString = { [idStateNotInitialized]: { icon: CloseOutlined, text: 'Не настроена' }, [idStateApproving]: { icon: LoadingOutlined, text: 'Согласовывается' }, [idStateCreating]: { icon: LoadingOutlined, text: 'Формируется' }, [idStateReady]: { icon: null, text: 'Сформирована' }, [idStateError]: { icon: WarningOutlined, text: 'Ошибка формирования' }, [idStateUnknown]: { icon: WarningOutlined, text: 'Неизвестно' }, } export const DrillingProgram = memo(({ idWell }) => { const [selectedCategory, setSelectedCategory] = useState() const [historyVisible, setHistoryVisible] = useState(false) const [editorVisible, setEditorVisible] = useState(false) const [showLoader, setShowLoader] = useState(false) const [categories, setCategories] = useState([]) const [data, setData] = useState({}) const { idState, permissionToEdit, parts, program, error, } = data const stateId = idState ?? idStateUnknown const state = stateString[stateId] const StateIcon = state.icon console.log(parts) const updateData = useCallback(async () => await invokeWebApiWrapperAsync( async () => { const data = await DrillingProgramService.getState(idWell) const categories = arrayOrDefault(await DrillingProgramService.getCategories(idWell)) setData(data) setCategories(categories.filter(cat => { if (cat?.id && (cat.name || cat.shortName)) if (data.parts?.findIndex((val) => val.idFileCategory === cat.id) < 0) return true return false })) }, setShowLoader, `Не удалось загрузить название скважины "${idWell}"` ), [idWell]) useEffect(() => updateData(), [updateData]) const onCategoryEdit = (catId) => { setSelectedCategory(catId) setEditorVisible(!!catId) } const onCategoryHistory = (catId) => { setSelectedCategory(catId) setHistoryVisible(!!catId) } const onEditorClosed = useCallback(() => { setEditorVisible(false) updateData() }, [updateData]) return (

Программа бурения

{permissionToEdit && (
)}
{stateId === idStateReady ? ( <>
Размер: {program?.size}
Загружен: {formatDate(program?.uploadDate)}
) : (

{(stateId === idStateError && error?.message) ? error.message : state.text}

)}
{parts?.map?.((part, idx) => part && ( ))} {permissionToEdit && ( <> part.idFileCategory === selectedCategory) ?? {}} /> )} setHistoryVisible(false)} visible={historyVisible} />
) }) export default DrillingProgram