/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { FC, useState } from 'react';
import { Box, Typography, Chip, CircularProgress, Link } from '@mui/material';
import {
AdminPanelSettings as AdminPanelIcon,
CheckCircle as CheckCircleIcon,
GppMaybe as WarningIcon,
Block as BlockIcon,
Cancel as CancelIcon,
Info as InfoIcon,
} from '@mui/icons-material';
import { ScanResult } from '../../../context/scan-admin';
import { ConditionalTooltip } from '../common';
import { useTheme } from '@mui/material/styles';
import {
ICON_SIZE,
isRunning,
shouldShowStriped,
getHypotheticalStatus,
getStatusColorSx,
} from './utils';
import { createRoute } from '../../../utils';
import { AdminDashboardRoutes } from '../../../pages/admin-dashboard/admin-dashboard-routes';
import { ExtensionDetailRoutes } from '../../../pages/extension-detail/extension-detail-routes';
interface ScanCardHeaderProps {
scan: ScanResult;
}
const getStatusIcon = (status: ScanResult['status']) => {
switch (status) {
case 'PASSED':
return ;
case 'QUARANTINED':
return ;
case 'AUTO REJECTED':
return ;
case 'ERROR':
return ;
default:
return null;
}
};
/**
* Header section of the ScanCard containing:
* - Extension icon
* - Display name and namespace
* - Status badge
*/
export const ScanCardHeader: FC = ({ scan }) => {
const theme = useTheme();
const [imageError, setImageError] = useState(false);
const hasValidIcon = scan.extensionIcon && !imageError;
const extensionRoute = createRoute([ExtensionDetailRoutes.ROOT, scan.namespace, scan.extensionName]);
const adminRoute = createRoute([AdminDashboardRoutes.ROOT, 'extensions'],
[
{ key: "namespace", value: scan.namespace },
{ key: "extension", value: scan.extensionName }
]);
return (
<>
{/* Column 1: Icon */}
{hasValidIcon ? (
setImageError(true)}
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
}}
/>
) : (
{scan.displayName.charAt(0).toUpperCase()}
)}
{/* Columns 2-5: Display Name and Namespace */}
{scan.displayName}
{scan.namespace}.{scan.extensionName}
{adminRoute !== undefined &&
}
{/* Column 6: Status Badge */}
{isRunning(scan.status) ? (
) : (
<>
{shouldShowStriped(scan) && getHypotheticalStatus(scan) && (
Would be {getHypotheticalStatus(scan)}
)}
>
)}
>
);
};