From e82868bd2e065104468d7f743ab8014d0be4787d Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 25 Oct 2021 14:50:45 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Messages.jsx | 74 +++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/src/pages/Messages.jsx b/src/pages/Messages.jsx index 197efe7..7910e03 100644 --- a/src/pages/Messages.jsx +++ b/src/pages/Messages.jsx @@ -1,15 +1,15 @@ -import {Table, Select, DatePicker, Input} from 'antd'; -import {useState, useEffect} from 'react' +import { Table, Select, DatePicker, Input } from 'antd' +import { useState, useEffect } from 'react' import moment from 'moment' -import {MessageService} from '../services/api' +import { MessageService } from '../services/api' import LoaderPortal from '../components/LoaderPortal' -import { notify } from "../components/factory" +import { notify } from '../components/factory' import '../styles/message.css' -const {Option} = Select +const { Option } = Select const pageSize = 26 -const {RangePicker} = DatePicker; +const { RangePicker } = DatePicker const { Search } = Input // Словарь категорий для строк таблицы @@ -24,33 +24,29 @@ const columns = [ title: 'Дата', key: 'date', dataIndex: 'date', - render: (item) => moment(item).format('DD MMM YYYY, HH:MM:ss'), - }, - { + render: item => moment(item).format('DD MMM YYYY, HH:mm:ss'), + }, { title: 'Глубина', key: 'wellDepth', dataIndex: 'wellDepth', - render: (_, item) => {_} м., - }, - { + render: depth => {depth.toFixed(2)} м., + }, { title: 'Категория', key: 'categoryId', dataIndex: 'categoryId', render: (_, item) => categoryDictionary[item.categoryId].title, style: (_, item) => categoryDictionary[item.categoryId].style, ellipsis: true, - }, - { + }, { title: 'Сообщение', key: 'message', dataIndex: 'message', - }, - { + }, { title: 'Пользователь', key: 'user', dataIndex: 'user', }, -]; +] const filterOptions = [ {label: 'Важное', value: 1}, @@ -70,29 +66,15 @@ export default function Messages({idWell}) { const children = filterOptions.map((line) => ) - const onChangeRange = (range) => { - setRange(range) - } - - const onChangeSearchString = (message) => { - if (message.length < 3) { - setSearchString('') - return - } - setSearchString(message) - } + const onChangeRange = (range) => setRange(range) + const onChangeSearchString = (message) => setSearchString(message.length > 2 ? message : '') useEffect(() => { const GetMessages = async () => { setShowLoader(true) try { - let begin = null - let end = null - if (range?.length > 1) { - begin = range[0].toISOString() - end = range[1].toISOString() - } + const [begin, end] = range?.length > 1 ? [range[0].toISOString(), range[1].toISOString()] : [null, null] let paginatedMessages = await MessageService.getMessages(idWell, (page - 1) * pageSize, pageSize, @@ -106,14 +88,12 @@ export default function Messages({idWell}) { return } - setMessages(paginatedMessages.items.map(m => { - return { - key: m.id, - categoryids: categoryDictionary[m.categoryId], - begin: m.date, - ...m - } - })) + 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), @@ -133,10 +113,10 @@ export default function Messages({idWell}) {

Фильтр сообщений