MSP-3204 create Connections component

This commit is contained in:
Anastasiia committed 2024-04-26 10:33:49 +03:00
1 parent 76f2105e58
commit ab44c0ce22
2 files changed
+197

No files matched your search

@@ -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);
}
}
+151
View File
@@ -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<ModuleStatusType[] | []>([])
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 <Spin />
}
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 (
<ul className="connection-page__endpoint-list">
{endpoints.map(({ path, inner }) => (
<li className="connection-page__endpoint-list__item" key={path}>
{path}
{inner && (
<span className="connection-page__endpoint-list__inner-marker">
Внутренний
</span>
)}
</li>
))}
</ul>
)
}
return (
<div className="connection-page__no-data">Нет реализованных методов</div>
)
}
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) => (
<Tooltip title={formatFullDate(val)}>{moment(val).fromNow()}</Tooltip>
)
},
{
title: 'Реализованные методы',
dataIndex: 'endpoints',
key: 'endpoints',
render: (value: EndpointType[]) => (value && value.length) || '0'
}
]
return (
<section className="connection-page">
<div className="connection-page__content">
<div className="connection-page__content__wrap-table">
<Table
rowKey={keySelector}
pagination={false}
dataSource={obj}
columns={columns}
expandable={{
expandedRowRender: (i) => renderEndpoints(i)
}}
/>
</div>
</div>
</section>
)
}
export default Connections