Исправлена фильтрация суточных рапортов по дате

This commit is contained in:
goodmice 2022-04-19 19:09:05 +05:00
parent 0ed91387b9
commit f9ddf172f5

View File

@ -1,10 +1,9 @@
import moment from 'moment'
import { Button } from 'antd'
import { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { Button, DatePicker } from 'antd'
import { FileExcelOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons'
import { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import LoaderPortal from '@components/LoaderPortal'
import DateRangeWrapper from '@components/Table/DateRangeWrapper'
import { Table, makeDateColumn, makeColumn } from '@components/Table'
import { download, invokeWebApiWrapperAsync } from '@components/factory'
import { DailyReportService } from '@api'
@ -16,7 +15,7 @@ import { IdWellContext } from '@pages/Well'
export const DailyReport = memo(() => {
const [data, setData] = useState([])
const [isLoading, setIsLoading] = useState(false)
const [searchDate, setSearchDate] = useState(null)
const [searchDate, setSearchDate] = useState([moment().subtract(1, 'week'), moment()])
const [selectedReport, setSelectedReport] = useState(null)
const [isEditorVisible, setIsEditorVisible] = useState(false)
@ -42,9 +41,8 @@ export const DailyReport = memo(() => {
type={'link'}
icon={<FileExcelOutlined />}
onClick={async () => await download(`/api/well/${idWell}/DailyReport/${report.reportDate}/excel`)}
>
Скачать XLSX
</Button>
children={'Скачать XLSX'}
/>
<Button
type={'link'}
icon={<EditOutlined />}
@ -52,16 +50,15 @@ export const DailyReport = memo(() => {
setSelectedReport(report)
setIsEditorVisible(true)
}}
>
Редактировать
</Button>
children={'Редактировать'}
/>
</>
)}),
], [idWell])
const filteredData = useMemo(() => {
if (!searchDate) return data
return data.filter((row) => moment(row.date).isBetween(...searchDate))
return data.filter((row) => moment.utc(row.reportDate).local().isBetween(...searchDate))
}, [data, searchDate])
return (
@ -71,7 +68,13 @@ export const DailyReport = memo(() => {
<div>
<div>
<div>Диапозон дат отчёта</div>
<DateRangeWrapper onCalendarChange={setSearchDate} />
<DatePicker.RangePicker
allowClear={false}
format={'DD.MM.YYYY'}
defaultValue={searchDate}
onCalendarChange={setSearchDate}
disabledDate={(date) => date.isAfter(moment())}
/>
</div>
</div>
<div style={{ display: 'flex', alignItems: 'end' }}>