From ab44c0ce22f2b1e9c4d85bed8d6b66a717069f71 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Wed, 24 Apr 2024 12:05:29 +0300 Subject: [PATCH] MSP-3204 create Connections component --- src/components/Connections/connections.scss | 46 ++++++ src/components/Connections/index.tsx | 151 ++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 src/components/Connections/connections.scss create mode 100644 src/components/Connections/index.tsx diff --git a/src/components/Connections/connections.scss b/src/components/Connections/connections.scss new file mode 100644 index 0000000..f9484c8 --- /dev/null +++ b/src/components/Connections/connections.scss @@ -0,0 +1,46 @@ +@import "src/constants/style/styleConst"; + +.connection-page { + &__content { + padding: 2 * $basic-padding 3 * $basic-padding 2 * $basic-padding 0; + width: 100%; + + &__wrap-table { + overflow-x: scroll; + height: calc(100vh - 30px); + } + } + + &__endpoint-list { + &__item { + height: 25px; + display: flex; + } + + &__inner-marker { + font-size: 11px; + border: 1px solid #15D1E6; + border-radius: 12px; + padding: 0 4px; + margin: 4px + } + } + + &__no-data { + user-select: none; + display: flex; + flex: 1; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + font-size: 1.5em; + overflow: hidden; + font-family: PT Sans, sans-serif; + font-weight: 500; + padding: 8px; + text-overflow: ellipsis; + white-space: nowrap; + color: rgba(0, 0, 0, 0.45); + } +} diff --git a/src/components/Connections/index.tsx b/src/components/Connections/index.tsx new file mode 100644 index 0000000..90420b6 --- /dev/null +++ b/src/components/Connections/index.tsx @@ -0,0 +1,151 @@ +import { Spin, Table, Tooltip } from 'antd' +import { ColumnsType } from 'antd/es/table' +import moment from 'moment' +import 'moment/dist/locale/ru' +import { useEffect, useState } from 'react' +import { useNavigate, useParams } from 'react-router-dom' + +import { + AddressType, + EndpointType, + ModuleStatusType, + ModuleType +} from '@pages/ModulesPage/module.type.ts' + +import useRole from '@hooks/useRole.tsx' + +import modulesServiceApi from '@services/modulesService.ts' + +import { routePaths } from '@routes/routePaths.ts' + +import { PermissionKeysType } from '@type/roles.type.ts' + +import './connections.scss' + +const Connections = () => { + const { data: ConnectionsList = [], isLoading: isModulesLoading } = + modulesServiceApi.useGetModulesQuery('modules') + const { role, hasPermission } = useRole() + const navigate = useNavigate() + const { id } = useParams() + const [obj, setObj] = useState([]) + + const isLoading = isModulesLoading + const isPageAvailable = hasPermission(PermissionKeysType.read) + + useEffect(() => { + const filterId = ConnectionsList.find((item: ModuleType) => item.id === id) + if (filterId && filterId.status) { + setObj(filterId.status) + } + }, [ConnectionsList, id]) + + useEffect(() => { + if (!isPageAvailable) { + navigate(routePaths.home) + } + }, [isPageAvailable]) + useEffect(() => { + if (!role) { + navigate(routePaths.error) + } + }, [role]) + + if (isLoading) { + return + } + + const formatFullDate = (obj: string) => + moment(obj).format('YYYY-MM-DD, HH:mm:ss') + + const keySelector = ({ + address: { ip, port }, + establishedAt + }: ModuleStatusType) => ip + port + establishedAt + + const renderEndpoints = ({ endpoints }: ModuleStatusType) => { + if (endpoints && endpoints.length) { + return ( +
    + {endpoints.map(({ path, inner }) => ( +
  • + {path} + {inner && ( + + Внутренний + + )} +
  • + ))} +
+ ) + } + + return ( +
Нет реализованных методов
+ ) + } + + const columns: ColumnsType = [ + { + title: '#', + dataIndex: '', + key: 'num', + render: ( + _val: ModuleStatusType, + _record: ModuleStatusType, + index: number + ) => index + 1 + }, + { + title: 'Версия', + dataIndex: 'version', + key: 'version' + }, + { + title: 'Версия библиотеки', + dataIndex: 'libVersion', + key: 'libVersion' + }, + { + title: 'Адрес', + dataIndex: 'address', + key: 'address', + render: (value: AddressType) => `${value.ip}:${value.port}` + }, + { + title: 'Соединение установлено', + dataIndex: 'establishedAt', + key: 'establishedAt', + render: (val: string) => ( + {moment(val).fromNow()} + ) + }, + { + title: 'Реализованные методы', + dataIndex: 'endpoints', + key: 'endpoints', + render: (value: EndpointType[]) => (value && value.length) || '0' + } + ] + + return ( +
+
+
+ renderEndpoints(i) + }} + /> + + + + ) +} + +export default Connections