Merge branch 'dev' into feature/add-zoom-for-d3chart

This commit is contained in:
ts_salikhov 2022-11-01 13:46:08 +04:00
commit f481a212c5
3 changed files with 18 additions and 26 deletions

View File

@ -42,7 +42,7 @@ export const App = memo(() => (
{/* User pages */}
<Route element={<UserOutlet />}>
<Route path={'/file_download/:idWell/:idFile/*'} element={<FileDownload />} />
<Route path={'/file_download/:idFile/*'} element={<FileDownload />} />
<Route element={<LayoutPortal />}>
{/* Admin pages */}

View File

@ -1,40 +1,30 @@
import { Link, useNavigate, useParams } from 'react-router-dom'
import { memo, useCallback, useEffect, useState } from 'react'
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons'
import { Button, Result, Typography } from 'antd'
import { downloadFile, invokeWebApiWrapperAsync } from '@components/factory'
import { withPermissions } from '@utils'
import { FileService, WellService } from '@api'
import { FileService } from '@api'
const { Paragraph, Text } = Typography
export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.idWell}/${fileInfo.id}`
export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.id}`
const FileDownload = memo(function FileDownload() {
const { idWell, idFile } = useParams()
const [well, setWell] = useState({})
const { idFile } = useParams()
const [file, setFile] = useState({})
const [isError, setIsError] = useState(false)
const navigate = useNavigate()
useEffect(() => {
invokeWebApiWrapperAsync(
async () => setWell(await WellService.get(idWell)),
null,
'Не удалось получить информацию о скважине',
{ actionName: 'Получение данных о скважине' }
)
}, [idWell])
const location = useLocation()
const isFirstOpenApp = useMemo(() => location.key === 'default', [location])
useEffect(() => {
invokeWebApiWrapperAsync(
async () => {
const files = await FileService.getFilesInfo(idWell)
// TODO Получается только одна категория файлов.
// Поменять при появлении метода получения инфы о конкретном файле
setFile(files.items.find((file) => file.id === idFile) ?? { id: idFile, idWell, name: `File_${idWell}_${idFile}` })
const file = await FileService.getFileInfo(idFile)
setFile(file)
},
null,
() => {
@ -43,10 +33,10 @@ const FileDownload = memo(function FileDownload() {
},
{ actionName: 'Получение информации о файле' }
)
}, [idWell, idFile])
}, [idFile])
const download = useCallback(async () => {
if (!await downloadFile(file))
if (!file || !await downloadFile(file))
setIsError(true)
}, [file])
@ -58,13 +48,16 @@ const FileDownload = memo(function FileDownload() {
<>
Вы перешли к странице загрузки файла!
<br />
Файл "{file.name ?? ('№' + idFile)}", скважина "{well.caption ?? ('№' + idWell)}".
Файл "{file?.name ?? ('№' + idFile)}".
</>
)}
// subTitle={}
extra={(
<>
<Button type={'ghost'} onClick={() => navigate('/')}>Вернуться на главную</Button>
{isFirstOpenApp
? <Button type={'ghost'} onClick={() => navigate('/')}>Вернуться на главную</Button>
: <Button type={'ghost'} onClick={() => navigate(-1)}>Вернуться на страницу документов</Button>
}
<Button type={'primary'} onClick={download}>Загрузить</Button>
</>
)}

View File

@ -72,8 +72,7 @@ const DailyReport = memo(() => {
const filteredData = useMemo(() => {
if (!searchDate) return data
const endDate = moment(searchDate[1]).add(1, 'd')
return data.filter((row) => moment(row.reportDate).isBetween(searchDate[0], endDate, 'ms', '[)'))
return data.filter((row) => moment(row.reportDate).isBetween(searchDate[0], searchDate[1], 'day', '[]'))
}, [data, searchDate])
return (