2023-09-07 14:59:59 +00:00
|
|
|
import { Loader } from 'lucide-react';
|
|
|
|
|
|
|
|
import { useEnvironment } from '@/react/portainer/environments/queries';
|
|
|
|
import { statusIcon } from '@/react/docker/components/ImageStatus/helpers';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
2023-10-22 09:32:05 +00:00
|
|
|
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
2023-09-07 14:59:59 +00:00
|
|
|
|
|
|
|
import { Icon } from '@@/Icon';
|
|
|
|
|
2023-10-03 12:55:23 +00:00
|
|
|
import { ResourceID, ResourceType } from './types';
|
|
|
|
import { useImageNotification } from './useImageNotification';
|
|
|
|
|
2023-09-07 14:59:59 +00:00
|
|
|
export interface Props {
|
|
|
|
environmentId: EnvironmentId;
|
|
|
|
resourceId: ResourceID;
|
|
|
|
resourceType?: ResourceType;
|
|
|
|
nodeName?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ImageStatus({
|
|
|
|
environmentId,
|
|
|
|
resourceId,
|
|
|
|
resourceType = ResourceType.CONTAINER,
|
|
|
|
nodeName = '',
|
|
|
|
}: Props) {
|
|
|
|
const enableImageNotificationQuery = useEnvironment(
|
|
|
|
environmentId,
|
|
|
|
(environment) => environment?.EnableImageNotification
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data, isLoading, isError } = useImageNotification(
|
|
|
|
environmentId,
|
|
|
|
resourceId,
|
|
|
|
resourceType,
|
|
|
|
nodeName,
|
|
|
|
enableImageNotificationQuery.data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!enableImageNotificationQuery.data || isError) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-22 09:32:05 +00:00
|
|
|
if (!isBE) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-09-07 14:59:59 +00:00
|
|
|
if (isLoading || !data) {
|
|
|
|
return (
|
|
|
|
<Icon
|
|
|
|
icon={Loader}
|
|
|
|
size="sm"
|
|
|
|
className="!mr-1 animate-spin-slow align-middle"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Icon icon={statusIcon(data)} size="sm" className="!mr-1 align-middle" />
|
|
|
|
);
|
|
|
|
}
|