import * as React from 'react'; import { Link } from 'react-router-dom'; import { Alert, AlertVariant, Card, CardBody, CardTitle, Content, ContentVariants, Flex, FlexItem, List, ListItem, Spinner, } from '@patternfly/react-core'; import { CheckCircleIcon } from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; import { t_global_icon_color_status_danger_default as dangerColor } from '@patternfly/react-tokens/dist/js/t_global_icon_color_status_danger_default'; import { t_global_icon_color_status_success_default as successColor } from '@patternfly/react-tokens/dist/js/t_global_icon_color_status_success_default'; import { TrackEvents } from '~/analytics'; import { useTrackAnalyticsEvent } from '~/analytics/hooks'; import { type ApplicationViolationSummary, useWorkspaceConformaViolations, } from '~/components/Issues/useWorkspaceConformaViolations'; import { APPLICATION_CONFORMA_RESULTS_PATH } from '~/routes/paths'; import { LoadingSkeleton } from '~/shared'; import { WarningIcon } from '~/shared/components/status/icons'; import { useNamespace } from '~/shared/providers/Namespace'; import { getErrorState } from '~/shared/utils/error-utils'; import './ConformaViolationsCard.scss'; type AppListProps = { applications: ApplicationViolationSummary[]; namespace: string; onLinkClick: () => void; }; const AppBreakdownList: React.FC = ({ applications, namespace, onLinkClick }) => ( {applications.map(({ applicationName, violationCount, warningCount }) => ( {applicationName} {violationCount > 0 && ( {` — ${violationCount} ${violationCount === 1 ? 'violation' : 'violations'}`} )} {warningCount > 0 && ( {` — ${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`} )} ))} ); export const ConformaViolationsCard: React.FC = () => { const namespace = useNamespace(); const trackEvent = useTrackAnalyticsEvent(); const { totalViolations, totalWarnings, applications, loaded, settling, error, partialError } = useWorkspaceConformaViolations(); const handleLinkClick = React.useCallback(() => { trackEvent(TrackEvents.conforma_violations_link_clicked_event, {}); }, [trackEvent]); const hasError = loaded && !!error; const hasViolations = totalViolations > 0; // Warning-only path: only shown when no violations are present. // During settling, showSkeleton stays true until at least one non-zero count // arrives, preventing a transient "0 warnings" header. const hasWarnings = !hasViolations && totalWarnings > 0; const allPassed = loaded && !settling && applications.length > 0 && !hasViolations && !hasWarnings && !hasError; const noData = loaded && !settling && applications.length === 0 && !hasError; const showSkeleton = !loaded || (settling && totalViolations === 0 && totalWarnings === 0); return ( Conforma policy results {showSkeleton ? ( ) : hasError ? ( getErrorState(error, loaded, 'policy results', true) ) : noData ? ( No policy evaluations found for this workspace. ) : allPassed ? ( All applications passed ) : ( <> {hasViolations ? ( <> {totalViolations}{' '} {totalViolations === 1 ? 'policy violation' : 'policy violations'} {totalWarnings > 0 && ( <>, {totalWarnings}{' '} {totalWarnings === 1 ? 'warning' : 'warnings'} )} ) : ( <> {totalWarnings}{' '} {totalWarnings === 1 ? 'warning' : 'warnings'} )} {settling && ( )} {applications.length > 0 && ( )} )} {loaded && !hasError && partialError && ( {partialError instanceof Error && partialError.message ? partialError.message : 'One or more policy result fetches failed. Results shown may be incomplete.'} )} ); };