diff --git a/src/components/factory.ts b/src/components/factory.ts index 5ed92b3..ca09446 100644 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -1,5 +1,6 @@ import { Dispatch, SetStateAction } from "react" import { notification } from 'antd'; +import { FileInfoDto } from '../services/api' const notificationTypeDictionary = new Map([ ['error', {notifyInstance: notification.error, caption: 'Ошибка'}], @@ -89,6 +90,15 @@ export const upload = async (url:string, formData: FormData) => { }) } +export const downloadFile = async (fileInfo: FileInfoDto) => { + try { + await download(`/api/well/${fileInfo.idWell}/files/${fileInfo.id}`) + } catch (error) { + notify(`Не удалось скачать файл ${fileInfo.name} по скважине (${fileInfo.idWell})`, 'error') + console.log(error) + } +} + export const formatBytes = (bytes:number) => { if(bytes < 1024) return `${bytes.toFixed(0)}b` diff --git a/src/pages/Documents/DocumentsTemplate.jsx b/src/pages/Documents/DocumentsTemplate.jsx index b156cf9..4f8c6af 100644 --- a/src/pages/Documents/DocumentsTemplate.jsx +++ b/src/pages/Documents/DocumentsTemplate.jsx @@ -4,7 +4,7 @@ import moment from "moment" import { FileService } from "../../services/api" import { invokeWebApiWrapperAsync, - download, + downloadFile, formatBytes, } from "../../components/factory" import { EditableTable, makePaginationObject } from "../../components/Table" @@ -28,16 +28,6 @@ export default function DocumentsTemplate({ idCategory, idWell, accept, headerCh const uploadUrl = `/api/well/${idWell}/files/?idCategory=${idCategory}` - const handleFileDownload = async (_, row) => { - invokeWebApiWrapperAsync( - async () => { - await download(`/api/well/${idWell}/files/${row.id}`) - }, - setShowLoader, - `Не удалось скачать файл ${row}` - ) - } - const handleUploadComplete = () => { update() } @@ -61,7 +51,7 @@ export default function DocumentsTemplate({ idCategory, idWell, accept, headerCh key: "document", dataIndex: "name", render: (name, row) => ( - ), }, diff --git a/src/pages/Report/ReportCreationNotify.jsx b/src/pages/Report/ReportCreationNotify.jsx index 9e8f0dc..fdf76ad 100644 --- a/src/pages/Report/ReportCreationNotify.jsx +++ b/src/pages/Report/ReportCreationNotify.jsx @@ -1,14 +1,5 @@ import { Progress, Button } from "antd" -import { download, notify } from "../../components/factory" - -export const getReportFile = async (fileInfo) => { - try { - await download(`/api/well/${fileInfo.idWell}/files/${fileInfo.id}`) - } catch (error) { - notify(`Не удалось скачать отчет ${fileInfo.name} по скважине (${fileInfo.idWell})`, 'error') - console.log(error) - } -} +import { downloadFile } from "../../components/factory" export const ReportCreationNotify = ({progressData}) => { progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета'} @@ -17,7 +8,7 @@ export const ReportCreationNotify = ({progressData}) => { if (progressData.file) downloadButton = diff --git a/src/pages/Report/Reports.jsx b/src/pages/Report/Reports.jsx index 8b753eb..064be92 100644 --- a/src/pages/Report/Reports.jsx +++ b/src/pages/Report/Reports.jsx @@ -3,7 +3,7 @@ import { Table, makeDateSorter, makeNumericSorter, formatDate} from "../../compo import { Button, Tooltip } from "antd" import { FilePdfOutlined, FileTextOutlined} from '@ant-design/icons' import { ReportService } from "../../services/api" -import { invokeWebApiWrapperAsync, download, formatTimespan} from "../../components/factory" +import { invokeWebApiWrapperAsync, downloadFile, formatTimespan} from "../../components/factory" import LoaderPortal from "../../components/LoaderPortal" import moment from "moment" @@ -12,16 +12,6 @@ const imgPaths = { ".las": , } -const handleFileDownload = async (idWell, idFile) => { - invokeWebApiWrapperAsync( - async () => { - await download(`/api/well/${idWell}/files/${idFile}`) - }, - null, - `Не удалось скачать файл ${idFile}` - ) -} - const columns = [ { title: "Название", @@ -31,7 +21,7 @@ const columns = [