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

Add Warnings for Missing Interfaces in Device Introspection #486

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
92 changes: 69 additions & 23 deletions src/DeviceStatusPage/IntrospectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
limitations under the License.
*/

import React from 'react';
import { Card, Table } from 'react-bootstrap';
import React, { useState, useEffect } from 'react';
import { Card, Table, OverlayTrigger, Tooltip } from 'react-bootstrap';
import { Link } from 'react-router-dom';

import type { AstarteDevice, AstarteDeviceInterfaceStats } from 'astarte-client';
import FullHeightCard from '../components/FullHeightCard';
import { useAstarte } from 'AstarteManager';

interface IntrospectionTableProps {
deviceId: string;
introspection: AstarteDeviceInterfaceStats[];
interfacesData: AstarteDeviceInterfaceStats[];
}

const IntrospectionTable = ({
deviceId,
introspection,
interfacesData,
}: IntrospectionTableProps): React.ReactElement => {
const astarte = useAstarte();

Expand All @@ -45,25 +46,54 @@ const IntrospectionTable = ({
</tr>
</thead>
<tbody>
{introspection.map((iface) => (
<tr key={iface.name}>
<td>
{astarte.token?.can(
'appEngine',
'GET',
`/devices/${deviceId}/interfaces/${iface.name}`,
) ? (
<Link to={`/devices/${deviceId}/interfaces/${iface.name}/${iface.major}`}>
{iface.name}
</Link>
) : (
iface.name
)}
</td>
<td>{iface.major}</td>
<td>{iface.minor}</td>
</tr>
))}
{introspection.map((iface) => {
const isInterfaceInstalled = interfacesData.some(
(interfaceData) => interfaceData.name === iface.name,
);
return (
<tr key={iface.name}>
<td>
{astarte.token?.can(
'appEngine',
'GET',
`/devices/${deviceId}/interfaces/${iface.name}`,
) ? (
!isInterfaceInstalled ? (
<>
<OverlayTrigger
placement="top"
overlay={
<Tooltip id={`tooltip-${iface.name}`}>
Interface not installed in the realm
</Tooltip>
}
>
<span
className="d-inline-flex align-items-center justify-content-center rounded-circle border border-danger bg-white text-danger fw-bold me-2"
style={{
width: '20px',
height: '20px',
}}
>
!
</span>
</OverlayTrigger>
{iface.name}
</>
) : (
<Link to={`/devices/${deviceId}/interfaces/${iface.name}/${iface.major}`}>
{iface.name}
</Link>
)
) : (
iface.name
)}
</td>
<td>{iface.major}</td>
<td>{iface.minor}</td>
</tr>
);
})}
</tbody>
</Table>
);
Expand All @@ -74,14 +104,30 @@ interface IntrospectionCardProps {
}

const IntrospectionCard = ({ device }: IntrospectionCardProps): React.ReactElement => {
const [interfacesData, setInterfacesData] = useState<AstarteDeviceInterfaceStats[]>([]);
const introspection = Array.from(device.introspection.values());
const astarte = useAstarte();

useEffect(() => {
const fetchData = async () => {
const data = await astarte.client.getInterfaces();
const formattedData = data.map((iface: string) => ({ name: iface }));
setInterfacesData(formattedData as AstarteDeviceInterfaceStats[]);
};

fetchData();
}, [astarte]);

return (
<FullHeightCard xs={12} md={6} className="mb-4">
<Card.Header as="h5">Interfaces</Card.Header>
<Card.Body className="d-flex flex-column">
{introspection.length > 0 ? (
<IntrospectionTable deviceId={device.id} introspection={introspection} />
<IntrospectionTable
deviceId={device.id}
introspection={introspection}
interfacesData={interfacesData}
/>
) : (
<p>No introspection info</p>
)}
Expand Down
Loading