пинг кнопка
This commit is contained in:
parent
f77a5be371
commit
21e21b87a8
1 changed files with 63 additions and 9 deletions
|
|
@ -3,6 +3,7 @@ import {
|
||||||
DatabaseOutlined,
|
DatabaseOutlined,
|
||||||
PlayCircleOutlined,
|
PlayCircleOutlined,
|
||||||
ThunderboltOutlined,
|
ThunderboltOutlined,
|
||||||
|
WifiOutlined,
|
||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
|
|
@ -23,14 +24,59 @@ import {
|
||||||
Typography,
|
Typography,
|
||||||
message,
|
message,
|
||||||
} from 'antd'
|
} from 'antd'
|
||||||
import { useMemo, useState } from 'react'
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { useNavigate, useParams } from 'react-router-dom'
|
import { useNavigate, useParams } from 'react-router-dom'
|
||||||
import { useDevices, useObject, type DeviceItem } from '../api/objects'
|
import { useDevices, useObject, type DeviceItem } from '../api/objects'
|
||||||
import { useRacks } from '../api/racks'
|
import { useRacks } from '../api/racks'
|
||||||
import { useActions, useCreateTask } from '../api/tasks'
|
import { useActions, useCreateTask, useTask } from '../api/tasks'
|
||||||
import { CategoryTag, DeviceStatusBadge } from '../components/StatusBadge'
|
import { CategoryTag, DeviceStatusBadge } from '../components/StatusBadge'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
function PingButton({
|
||||||
|
scope,
|
||||||
|
objId,
|
||||||
|
size = 'small',
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
scope: object
|
||||||
|
objId: number
|
||||||
|
size?: 'small' | 'middle' | 'large'
|
||||||
|
children?: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const [taskId, setTaskId] = useState<string | null>(null)
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const createTask = useCreateTask()
|
||||||
|
const { data: task } = useTask(taskId ?? undefined)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (task && ['success', 'failed', 'partial', 'stale', 'cancelled'].includes(task.status)) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['devices', objId] })
|
||||||
|
setTaskId(null)
|
||||||
|
}
|
||||||
|
}, [task?.status, queryClient, objId])
|
||||||
|
|
||||||
|
const handlePing = async () => {
|
||||||
|
try {
|
||||||
|
const t = await createTask.mutateAsync({ type: 'ping', target_scope: scope, params: {} })
|
||||||
|
setTaskId(t.id)
|
||||||
|
} catch {
|
||||||
|
message.error('Ошибка запуска пинга')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size={size}
|
||||||
|
loading={createTask.isPending || !!taskId}
|
||||||
|
icon={<WifiOutlined />}
|
||||||
|
onClick={handlePing}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const SERVER_CATEGORIES = new Set(['main_server', 'vm', 'router'])
|
const SERVER_CATEGORIES = new Set(['main_server', 'vm', 'router'])
|
||||||
const COL_SPAN = 7
|
const COL_SPAN = 7
|
||||||
|
|
||||||
|
|
@ -158,13 +204,18 @@ export function WorkObjectDetailPage() {
|
||||||
<Tag style={{ marginLeft: 2 }}>{row.count} устройств</Tag>
|
<Tag style={{ marginLeft: 2 }}>{row.count} устройств</Tag>
|
||||||
{row.onlineCount > 0 && <Tag color="green">Online: {row.onlineCount}</Tag>}
|
{row.onlineCount > 0 && <Tag color="green">Online: {row.onlineCount}</Tag>}
|
||||||
{row.rackScope && (
|
{row.rackScope && (
|
||||||
<Button
|
<>
|
||||||
size="small"
|
<PingButton scope={row.rackScope} objId={objId}>
|
||||||
icon={<PlayCircleOutlined />}
|
Пинг
|
||||||
onClick={() => openTaskModal(row.rackScope!, `Задача: ${row.label}`)}
|
</PingButton>
|
||||||
>
|
<Button
|
||||||
Задача на группу
|
size="small"
|
||||||
</Button>
|
icon={<PlayCircleOutlined />}
|
||||||
|
onClick={() => openTaskModal(row.rackScope!, `Задача: ${row.label}`)}
|
||||||
|
>
|
||||||
|
Задача на группу
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
|
|
@ -266,6 +317,9 @@ export function WorkObjectDetailPage() {
|
||||||
</Col>
|
</Col>
|
||||||
<Col>
|
<Col>
|
||||||
<Space>
|
<Space>
|
||||||
|
<PingButton scope={{ type: 'object', id: objId }} objId={objId} size="middle">
|
||||||
|
Пинг объекта
|
||||||
|
</PingButton>
|
||||||
<Button
|
<Button
|
||||||
icon={<ThunderboltOutlined />}
|
icon={<ThunderboltOutlined />}
|
||||||
onClick={() => openTaskModal({ type: 'object', id: objId }, 'Задача на весь объект')}
|
onClick={() => openTaskModal({ type: 'object', id: objId }, 'Задача на весь объект')}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue