Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(28933): Add device tags to the node visualisation #730

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@/api/__generated__'
import { MockAdapterType } from '@/__test-utils__/adapters/types.ts'
import { enumFromStringValue } from '@/utils/types.utils.ts'
import { DeviceMetadata } from '@/modules/Workspace/types.ts'

export const mockUISchema: UiSchema = {
'ui:tabs': [
Expand Down Expand Up @@ -208,6 +209,11 @@ export const mockProtocolAdapter: ProtocolAdapter = {
uiSchema: mockUISchema,
}

export const mockDeviceFromAdapter: DeviceMetadata = {
...mockProtocolAdapter,
sourceAdapterId: 'my-adapter',
}

export const mockProtocolAdapter_OPCUA: ProtocolAdapter = {
id: 'opcua',
protocol: 'OPC UA',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// <reference types="cypress" />

import { mockProtocolAdapter } from '@/api/hooks/useProtocolAdapters/__handlers__'
import { mockDeviceFromAdapter } from '@/api/hooks/useProtocolAdapters/__handlers__'
import DeviceMetadataViewer from '@/modules/Device/components/DeviceMetadataViewer.tsx'

describe('DeviceMetadataViewer', () => {
Expand All @@ -9,7 +7,7 @@ describe('DeviceMetadataViewer', () => {
})

it('should render the form', () => {
cy.mountWithProviders(<DeviceMetadataViewer protocolAdapter={mockProtocolAdapter} />)
cy.mountWithProviders(<DeviceMetadataViewer device={mockDeviceFromAdapter} />)

cy.getByTestId('device-metadata-header').should('be.visible')
cy.getByTestId('device-metadata-header').find('h2').should('contain.text', 'simulation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { Avatar, Box, Card, CardHeader, Flex, Heading, Text } from '@chakra-ui/r
import { DeviceMetadata } from '@/modules/Workspace/types.ts'

interface DeviceMetadataProps {
protocolAdapter?: DeviceMetadata
device: DeviceMetadata
}

const DeviceMetadataViewer: FC<DeviceMetadataProps> = ({ protocolAdapter }) => {
const DeviceMetadataViewer: FC<DeviceMetadataProps> = ({ device }) => {
return (
<Card size="sm">
<CardHeader>
<Flex data-testid="device-metadata-header">
<Flex flex="1" gap="4" alignItems="center" flexWrap="wrap">
<Avatar src={protocolAdapter?.logoUrl} />
<Avatar src={device.logoUrl} />
<Box>
<Heading size="sm">{protocolAdapter?.id}</Heading>
<Text>{protocolAdapter?.category?.displayName}</Text>
<Heading size="sm">{device.id}</Heading>
<Text>{device.category?.displayName}</Text>
</Box>
</Flex>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FC } from 'react'
import { FC, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { Handle, Position, NodeProps, useStore } from 'reactflow'
import { HStack, Icon, Text, VStack } from '@chakra-ui/react'

import { useGetDomainTags } from '@/api/hooks/useProtocolAdapters/useGetDomainTags.ts'
import ToolbarButtonGroup from '@/components/react-flow/ToolbarButtonGroup.tsx'
import IconButton from '@/components/Chakra/IconButton.tsx'
import { PLCTagIcon } from '@/components/Icons/TopicIcon.tsx'
Expand All @@ -17,12 +18,18 @@ import { useContextMenu } from '@/modules/Workspace/hooks/useContextMenu.ts'
import ContextualToolbar from '@/modules/Workspace/components/nodes/ContextualToolbar.tsx'
import { CONFIG_ADAPTER_WIDTH } from '@/modules/Workspace/utils/nodes-utils.ts'
import { selectorIsSkeletonZoom } from '@/modules/Workspace/utils/react-flow.utils.ts'
import MappingBadge from '@/modules/Workspace/components/parts/MappingBadge.tsx'

const NodeDevice: FC<NodeProps<DeviceMetadata>> = ({ id, selected, data, dragging }) => {
const { t } = useTranslation()
const { onContextMenu } = useContextMenu(id, selected, '/workspace/node')
const { category, capabilities } = data
const showSkeleton = useStore(selectorIsSkeletonZoom)
const { data: deviceTags } = useGetDomainTags(data.sourceAdapterId)

const tagNames = useMemo(() => {
return deviceTags?.items?.map((tag) => tag.name) || []
}, [deviceTags?.items])

return (
<>
Expand Down Expand Up @@ -58,6 +65,7 @@ const NodeDevice: FC<NodeProps<DeviceMetadata>> = ({ id, selected, data, draggin
/>
<Text>{data.protocol}</Text>
</HStack>
<MappingBadge destinations={tagNames} isTag />
</>
)}
{showSkeleton && (
Expand Down
2 changes: 1 addition & 1 deletion hivemq-edge/src/frontend/src/modules/Workspace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ export interface TopicTreeMetadata {
}

export interface DeviceMetadata extends ProtocolAdapter {
sourceAdapterId?: string
sourceAdapterId: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const MAX_ADAPTERS = 10

export const gluedNodeDefinition: Record<string, [NodeTypes, number, 'target' | 'source']> = {
[NodeTypes.BRIDGE_NODE]: [NodeTypes.HOST_NODE, 200, 'target'],
[NodeTypes.ADAPTER_NODE]: [NodeTypes.DEVICE_NODE, -125, 'target'],
[NodeTypes.ADAPTER_NODE]: [NodeTypes.DEVICE_NODE, -175, 'target'],
[NodeTypes.HOST_NODE]: [NodeTypes.BRIDGE_NODE, -200, 'source'],
[NodeTypes.DEVICE_NODE]: [NodeTypes.ADAPTER_NODE, 125, 'source'],
[NodeTypes.DEVICE_NODE]: [NodeTypes.ADAPTER_NODE, 175, 'source'],
}

export const createEdgeNode = (label: string, positionStorage?: Record<string, XYPosition>) => {
Expand Down
Loading