2021-08-13 10:30:26 +05:00
|
|
|
|
import moment from 'moment'
|
2022-03-18 19:40:52 +05:00
|
|
|
|
import { useState, useEffect, memo, useCallback } from 'react'
|
2022-01-24 17:32:45 +05:00
|
|
|
|
import { Table, Select, DatePicker, Input } from 'antd'
|
2021-08-13 10:30:26 +05:00
|
|
|
|
|
2022-01-24 17:32:45 +05:00
|
|
|
|
import { MessageService } from '@api'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
2022-02-07 15:01:07 +05:00
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
2022-01-24 17:32:45 +05:00
|
|
|
|
|
|
|
|
|
import '@styles/message.css'
|
2021-05-19 16:05:01 +05:00
|
|
|
|
|
2021-10-25 14:50:45 +05:00
|
|
|
|
const { Option } = Select
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const pageSize = 26
|
2021-10-25 14:50:45 +05:00
|
|
|
|
const { RangePicker } = DatePicker
|
2021-08-09 16:27:13 +05:00
|
|
|
|
const { Search } = Input
|
2021-05-28 12:04:38 +05:00
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
// Словарь категорий для строк таблицы
|
|
|
|
|
const categoryDictionary = {
|
2022-01-24 17:32:45 +05:00
|
|
|
|
1: { title: 'Важное' },
|
|
|
|
|
2: { title: 'Предупреждение' },
|
|
|
|
|
3: { title: 'Информация' },
|
2021-05-19 16:05:01 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 18:04:14 +05:00
|
|
|
|
// Конфигурация таблицы
|
|
|
|
|
export const columns = [
|
2021-06-01 12:20:29 +05:00
|
|
|
|
{
|
2021-10-29 18:04:14 +05:00
|
|
|
|
width: '10rem',
|
2021-06-01 12:20:29 +05:00
|
|
|
|
title: 'Дата',
|
|
|
|
|
key: 'date',
|
|
|
|
|
dataIndex: 'date',
|
2021-10-25 14:50:45 +05:00
|
|
|
|
render: item => moment(item).format('DD MMM YYYY, HH:mm:ss'),
|
2021-10-29 18:04:14 +05:00
|
|
|
|
sorter: (a, b) => new Date(b.date) - new Date(a.date),
|
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
2021-10-25 14:50:45 +05:00
|
|
|
|
}, {
|
2021-10-29 18:04:14 +05:00
|
|
|
|
width: '10rem',
|
2021-09-24 11:16:03 +05:00
|
|
|
|
title: 'Глубина',
|
|
|
|
|
key: 'wellDepth',
|
|
|
|
|
dataIndex: 'wellDepth',
|
2021-10-25 14:50:45 +05:00
|
|
|
|
render: depth => <span>{depth.toFixed(2)} м.</span>,
|
|
|
|
|
}, {
|
2021-10-29 18:04:14 +05:00
|
|
|
|
width: '10rem',
|
2021-06-01 12:20:29 +05:00
|
|
|
|
title: 'Категория',
|
|
|
|
|
key: 'categoryId',
|
|
|
|
|
dataIndex: 'categoryId',
|
|
|
|
|
render: (_, item) => categoryDictionary[item.categoryId].title,
|
2021-10-29 18:04:14 +05:00
|
|
|
|
style: (_, item) => categoryDictionary[item.categoryId]?.style,
|
|
|
|
|
sorter: (a, b) => a.categoryId - b.categoryId,
|
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
2021-06-01 12:20:29 +05:00
|
|
|
|
ellipsis: true,
|
2021-10-25 14:50:45 +05:00
|
|
|
|
}, {
|
2021-06-01 12:20:29 +05:00
|
|
|
|
title: 'Сообщение',
|
|
|
|
|
key: 'message',
|
|
|
|
|
dataIndex: 'message',
|
2021-10-29 18:04:14 +05:00
|
|
|
|
onFilter: (value, record) => record.name.indexOf(value) === 0,
|
2021-10-25 14:50:45 +05:00
|
|
|
|
}, {
|
2021-10-29 18:04:14 +05:00
|
|
|
|
width: '10rem',
|
2021-06-01 12:20:29 +05:00
|
|
|
|
title: 'Пользователь',
|
|
|
|
|
key: 'user',
|
|
|
|
|
dataIndex: 'user',
|
|
|
|
|
},
|
2021-10-25 14:50:45 +05:00
|
|
|
|
]
|
2021-06-01 12:20:29 +05:00
|
|
|
|
|
|
|
|
|
const filterOptions = [
|
2022-01-24 17:32:45 +05:00
|
|
|
|
{ value: 1, label: 'Важное' },
|
|
|
|
|
{ value: 2, label: 'Предупреждение' },
|
|
|
|
|
{ value: 3, label: 'Информация' },
|
2021-06-01 12:20:29 +05:00
|
|
|
|
]
|
|
|
|
|
|
2022-03-18 19:40:52 +05:00
|
|
|
|
const children = filterOptions.map((line) => <Option key={line.value}>{line.label}</Option>)
|
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
// Данные для таблицы
|
2022-01-24 17:32:45 +05:00
|
|
|
|
export const Messages = memo(({ idWell }) => {
|
2021-05-19 16:05:01 +05:00
|
|
|
|
const [messages, setMessages] = useState([])
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const [pagination, setPagination] = useState(null)
|
2021-06-01 14:32:36 +05:00
|
|
|
|
const [page, setPage] = useState(1)
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const [range, setRange] = useState([])
|
|
|
|
|
const [categories, setCategories] = useState([])
|
2021-08-09 16:27:13 +05:00
|
|
|
|
const [searchString, setSearchString] = useState('')
|
2021-08-18 13:50:44 +05:00
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-05-28 12:04:38 +05:00
|
|
|
|
|
2022-03-18 19:40:52 +05:00
|
|
|
|
const onChangeSearchString = useCallback((message) => setSearchString(message.length > 2 ? message : ''), [])
|
2021-08-09 16:49:14 +05:00
|
|
|
|
|
2022-01-24 17:32:45 +05:00
|
|
|
|
useEffect(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const [begin, end] = range?.length > 1 ? [range[0].toISOString(), range[1].toISOString()] : [null, null]
|
|
|
|
|
const skip = (page - 1) * pageSize
|
|
|
|
|
const paginatedMessages = await MessageService.getMessages(idWell, skip, pageSize, categories, begin, end, searchString)
|
|
|
|
|
if (!paginatedMessages) return
|
2021-06-24 15:36:57 +05:00
|
|
|
|
|
2022-01-24 17:32:45 +05:00
|
|
|
|
setMessages(paginatedMessages.items.map(m => ({
|
|
|
|
|
key: m.id,
|
|
|
|
|
categoryids: categoryDictionary[m.categoryId],
|
|
|
|
|
begin: m.date,
|
|
|
|
|
...m
|
|
|
|
|
})))
|
|
|
|
|
setPagination({
|
|
|
|
|
total: paginatedMessages.count,
|
|
|
|
|
current: Math.floor(paginatedMessages.skip / pageSize),
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-02-07 17:44:46 +05:00
|
|
|
|
`Не удалось загрузить сообщения по скважине "${idWell}"`,
|
|
|
|
|
'Полученик списка сообщений'
|
2022-01-24 17:32:45 +05:00
|
|
|
|
), [idWell, page, categories, range, searchString])
|
2021-05-31 09:34:22 +05:00
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
return (
|
2021-05-27 12:53:42 +05:00
|
|
|
|
<>
|
2022-02-07 15:01:07 +05:00
|
|
|
|
<div className={'filter-group'}>
|
|
|
|
|
<h3 className={'filter-group-heading'}>Фильтр сообщений</h3>
|
2021-06-01 14:32:36 +05:00
|
|
|
|
<Select
|
2021-10-25 14:50:45 +05:00
|
|
|
|
mode={'multiple'}
|
2021-06-01 14:32:36 +05:00
|
|
|
|
allowClear
|
2021-10-25 14:50:45 +05:00
|
|
|
|
placeholder={'Фильтр сообщений'}
|
|
|
|
|
className={'filter-selector'}
|
2021-06-01 14:32:36 +05:00
|
|
|
|
value={categories}
|
|
|
|
|
onChange={setCategories}>
|
|
|
|
|
{children}
|
|
|
|
|
</Select>
|
2022-01-24 17:32:45 +05:00
|
|
|
|
<RangePicker showTime onChange={(range) => setRange(range)} />
|
2021-08-09 16:27:13 +05:00
|
|
|
|
<Search
|
2021-10-25 14:50:45 +05:00
|
|
|
|
className={'filter-selector'}
|
|
|
|
|
placeholder={'Фильтр сообщений по тексту'}
|
2021-08-09 16:27:13 +05:00
|
|
|
|
onSearch={onChangeSearchString}
|
|
|
|
|
/>
|
2021-06-01 14:32:36 +05:00
|
|
|
|
</div>
|
2021-08-18 13:50:44 +05:00
|
|
|
|
<LoaderPortal show={showLoader}>
|
2021-06-02 11:38:27 +05:00
|
|
|
|
<Table
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={messages}
|
|
|
|
|
rowClassName={(record) => `event_message_${record.categoryId} event_message`}
|
|
|
|
|
size={'small'}
|
|
|
|
|
pagination={{
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
showSizeChanger: false,
|
|
|
|
|
total: pagination?.total,
|
|
|
|
|
current: page,
|
|
|
|
|
onChange: (page) => setPage(page)
|
|
|
|
|
}}
|
|
|
|
|
rowKey={(record) => record.id}
|
2022-03-10 20:46:02 +05:00
|
|
|
|
tableName={'messages'}
|
2021-06-02 11:38:27 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
2021-05-27 12:53:42 +05:00
|
|
|
|
</>
|
2021-05-19 16:05:01 +05:00
|
|
|
|
)
|
2022-01-24 17:32:45 +05:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default Messages
|