2022-12-07 14:51:20 +00:00
|
|
|
import { Activity } from 'lucide-react';
|
2022-03-08 12:14:23 +00:00
|
|
|
|
|
|
|
import { isoDateFromTimestamp } from '@/portainer/filters/filters';
|
2022-12-07 14:51:20 +00:00
|
|
|
import { useHasHeartbeat } from '@/react/edge/hooks/useHasHeartbeat';
|
2022-10-23 06:53:25 +00:00
|
|
|
import { Environment } from '@/react/portainer/environments/types';
|
2022-12-07 14:51:20 +00:00
|
|
|
|
|
|
|
import { EnvironmentStatusBadgeItem } from './EnvironmentStatusBadgeItem';
|
2022-03-08 12:14:23 +00:00
|
|
|
|
|
|
|
interface Props {
|
2022-05-23 14:32:51 +00:00
|
|
|
showLastCheckInDate?: boolean;
|
2022-06-22 17:11:46 +00:00
|
|
|
environment: Environment;
|
2022-03-08 12:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function EdgeIndicator({
|
2022-06-22 17:11:46 +00:00
|
|
|
environment,
|
|
|
|
|
2022-05-23 14:32:51 +00:00
|
|
|
showLastCheckInDate = false,
|
2022-03-08 12:14:23 +00:00
|
|
|
}: Props) {
|
2022-12-07 14:51:20 +00:00
|
|
|
const isValid = useHasHeartbeat(environment);
|
2022-06-22 17:11:46 +00:00
|
|
|
|
|
|
|
if (isValid === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-07 14:51:20 +00:00
|
|
|
const associated = !!environment.EdgeID;
|
2022-06-22 17:11:46 +00:00
|
|
|
if (!associated) {
|
2022-03-08 12:14:23 +00:00
|
|
|
return (
|
2022-06-22 17:11:46 +00:00
|
|
|
<span role="status" aria-label="edge-status">
|
2022-12-07 14:51:20 +00:00
|
|
|
<EnvironmentStatusBadgeItem aria-label="unassociated">
|
2023-01-22 20:14:06 +00:00
|
|
|
<span className="whitespace-nowrap">Not associated</span>
|
2022-12-07 14:51:20 +00:00
|
|
|
</EnvironmentStatusBadgeItem>
|
2022-03-08 12:14:23 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-12-07 14:51:20 +00:00
|
|
|
<span
|
|
|
|
role="status"
|
|
|
|
aria-label="edge-status"
|
|
|
|
className="flex items-center gap-1"
|
|
|
|
>
|
|
|
|
<EnvironmentStatusBadgeItem
|
|
|
|
color={isValid ? 'success' : 'danger'}
|
2023-01-22 20:14:06 +00:00
|
|
|
icon={isValid ? 'svg-heartbeatup' : 'svg-heartbeatdown'}
|
2022-03-08 12:14:23 +00:00
|
|
|
aria-label="edge-heartbeat"
|
|
|
|
>
|
|
|
|
heartbeat
|
2022-12-07 14:51:20 +00:00
|
|
|
</EnvironmentStatusBadgeItem>
|
2022-03-08 12:14:23 +00:00
|
|
|
|
2022-06-22 17:11:46 +00:00
|
|
|
{showLastCheckInDate && !!environment.LastCheckInDate && (
|
2022-03-08 12:14:23 +00:00
|
|
|
<span
|
2022-12-07 14:51:20 +00:00
|
|
|
className="small text-muted vertical-center"
|
2022-03-08 12:14:23 +00:00
|
|
|
aria-label="edge-last-checkin"
|
2022-12-07 14:51:20 +00:00
|
|
|
title="Last edge check-in"
|
2022-03-08 12:14:23 +00:00
|
|
|
>
|
2022-12-07 14:51:20 +00:00
|
|
|
<Activity className="icon icon-sm space-right" aria-hidden="true" />
|
2022-06-22 17:11:46 +00:00
|
|
|
{isoDateFromTimestamp(environment.LastCheckInDate)}
|
2022-03-08 12:14:23 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|