From b87c7a750ba788274d05a2fb22a00bf3034253c4 Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 29 Oct 2021 18:04:14 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A8=D0=B8=D1=80=D0=B8=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=BB=D0=B1=D0=BE=D0=B2=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=B0=20rem.=20=D0=94=D1=83?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=82=20=D0=BA=D0=BE=D0=BD=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D1=82=D1=8B=20=D1=81=D1=82=D0=BE=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=83=D0=B4=D0=B0=D0=BB=D1=91=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Messages.jsx | 20 ++++++--- .../TelemetryView/ActiveMessagesOnline.jsx | 43 ++----------------- 2 files changed, 16 insertions(+), 47 deletions(-) diff --git a/src/pages/Messages.jsx b/src/pages/Messages.jsx index 20603c5..366206b 100644 --- a/src/pages/Messages.jsx +++ b/src/pages/Messages.jsx @@ -14,38 +14,44 @@ const { Search } = Input // Словарь категорий для строк таблицы const categoryDictionary = { - 1: {title: 'Авария'}, + 1: {title: 'Важное'}, 2: {title: 'Предупреждение'}, 3: {title: 'Информация'}, } -const columns = [ +// Конфигурация таблицы +export const columns = [ { - width: '10%', + width: '10rem', title: 'Дата', key: 'date', dataIndex: 'date', render: item => moment(item).format('DD MMM YYYY, HH:mm:ss'), + sorter: (a, b) => new Date(b.date) - new Date(a.date), + sortDirections: ['descend', 'ascend'], }, { - width: '10%', + width: '10rem', title: 'Глубина', key: 'wellDepth', dataIndex: 'wellDepth', render: depth => {depth.toFixed(2)} м., }, { - width: '10%', + width: '10rem', title: 'Категория', key: 'categoryId', dataIndex: 'categoryId', render: (_, item) => categoryDictionary[item.categoryId].title, - style: (_, item) => categoryDictionary[item.categoryId].style, + style: (_, item) => categoryDictionary[item.categoryId]?.style, + sorter: (a, b) => a.categoryId - b.categoryId, + sortDirections: ['descend', 'ascend'], ellipsis: true, }, { title: 'Сообщение', key: 'message', dataIndex: 'message', + onFilter: (value, record) => record.name.indexOf(value) === 0, }, { - width: '10%', + width: '10rem', title: 'Пользователь', key: 'user', dataIndex: 'user', diff --git a/src/pages/TelemetryView/ActiveMessagesOnline.jsx b/src/pages/TelemetryView/ActiveMessagesOnline.jsx index 73df56a..e112409 100644 --- a/src/pages/TelemetryView/ActiveMessagesOnline.jsx +++ b/src/pages/TelemetryView/ActiveMessagesOnline.jsx @@ -1,51 +1,14 @@ import {useState, useEffect} from 'react' -import {Table} from "antd"; -import moment from 'moment' +import {Table} from 'antd' import LoaderPortal from '../../components/LoaderPortal' import {invokeWebApiWrapperAsync} from '../../components/factory' +import {columns} from '../Messages' import {Subscribe} from '../../services/signalr' import {MessageService} from '../../services/api' import '../../styles/message.css' -// Словарь категорий для строк таблицы -const categoryDictionary = { - 1: {title: 'Важное'}, - 2: {title: 'Предупреждение'}, - 3: {title: 'Информация'}, -} - -// Конфигурация таблицы -const columns = [ - { - title: 'Дата', - dataIndex: 'date', - render: (item) => moment(item).format('DD MMM YYYY, HH:mm:ss'), - sorter: (a, b) => new Date(b.date) - new Date(a.date), - sortDirections: ['descend', 'ascend'], - }, { - title: 'Глубина', - key: 'wellDepth', - dataIndex: 'wellDepth', - render: depth => Глубина {depth.toFixed(2)} м., - }, { - title: 'Категория', - dataIndex: 'categoryId', - render: (_, item) => categoryDictionary[item.categoryId]?.title, - style: (_, item) => categoryDictionary[item.categoryId]?.style, - sorter: (a, b) => a.categoryId - b.categoryId, - sortDirections: ['descend', 'ascend'], - }, { - title: 'Сообщение', - dataIndex: 'message', - onFilter: (value, record) => record.name.indexOf(value) === 0, - }, { - title: 'Пользователь', - dataIndex: 'user', - }, -]; - export default function ActiveMessagesOnline({idWell}) { const [messages, setMessages] = useState([]) const [loader, setLoader] = useState(false) @@ -56,7 +19,7 @@ export default function ActiveMessagesOnline({idWell}) { } } - useEffect(() => { + useEffect(() => { invokeWebApiWrapperAsync( async () => { const messages = await MessageService.getMessages(idWell, 0, 4)