Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | 6x 50x 50x 50x 50x 50x 33x 33x 21x 12x 50x 33x 11x 22x 50x 33x 11x 22x 50x 2x | import React, { useMemo } from "react";
import { WIDGET_ICONS, WIDGET_TITLES } from "../../../constants/appConstants";
import { INTEGRITY_IMPACT_TEST_IDS } from "../../../constants/testIds";
import {
getDefaultErrorRate,
getDefaultValidationLevel,
} from "../../../data/ciaOptionsData";
import { useBusinessImpact, useComponentDetails } from "../../../hooks";
import { useCIAContentService } from "../../../hooks/useCIAContentService";
import type { IntegrityImpactWidgetProps } from "../../../types/widget-props";
import { getSecurityLevelBackgroundClass } from "../../../utils/colorUtils";
import { normalizeSecurityLevel } from "../../../utils/securityLevelUtils";
import BusinessImpactSection from "../../common/BusinessImpactSection";
import SecurityLevelBadge from "../../common/SecurityLevelBadge";
import WidgetContainer from "../../common/WidgetContainer";
import WidgetErrorBoundary from "../../common/WidgetErrorBoundary";
/**
* Widget that displays the impact of selected integrity level
*
* ## Business Perspective
*
* This widget helps stakeholders understand the business impact of
* integrity controls, including how data accuracy and validation
* mechanisms protect business operations and decision-making. 📊
*/
const IntegrityImpactWidget: React.FC<IntegrityImpactWidgetProps> = ({
availabilityLevel: _availabilityLevel,
integrityLevel,
confidentialityLevel: _confidentialityLevel,
className = "",
testId = INTEGRITY_IMPACT_TEST_IDS.INTEGRITY_IMPACT_PREFIX,
showExtendedDetails = false,
}) => {
// Use the utility for consistent security level normalization
const effectiveLevel = normalizeSecurityLevel(integrityLevel || "Moderate");
// Get CIA content service for loading/error states
const { ciaContentService, error, isLoading } = useCIAContentService();
// Use custom hooks for data fetching (replaces manual useMemo logic)
const integrityDetails = useComponentDetails("integrity", effectiveLevel);
const businessImpact = useBusinessImpact("integrity", effectiveLevel);
// Get recommendations from service
const recommendations = useMemo(() => {
try {
if (!ciaContentService || !effectiveLevel) {
return [];
}
return (
ciaContentService.getRecommendations("integrity", effectiveLevel) || []
);
} catch (err) {
console.error("Error getting recommendations:", err);
return [];
}
}, [ciaContentService, effectiveLevel]);
// Get validation level with fallback to utility function
const validationLevel = useMemo(() => {
if (integrityDetails && integrityDetails.validationLevel) {
return integrityDetails.validationLevel;
}
return getDefaultValidationLevel(effectiveLevel);
}, [integrityDetails, effectiveLevel]);
// Get error rate with fallback to utility function
const errorRate = useMemo(() => {
if (integrityDetails && integrityDetails.errorRate) {
return integrityDetails.errorRate;
}
return getDefaultErrorRate(effectiveLevel);
}, [integrityDetails, effectiveLevel]);
return (
<WidgetErrorBoundary widgetName="Integrity Impact">
<WidgetContainer
title={WIDGET_TITLES.INTEGRITY_IMPACT || "Integrity Impact Analysis"}
icon={WIDGET_ICONS.INTEGRITY_IMPACT || "✓"}
className={className}
testId={testId}
isLoading={isLoading}
error={error}
>
<div className="p-4">
{/* Security level indicator */}
<div className="mb-4">
<SecurityLevelBadge
category="Integrity"
level={effectiveLevel}
// Use utility for consistent styling
colorClass={getSecurityLevelBackgroundClass("green")}
textClass="text-green-800 dark:text-green-300"
testId={`${testId}-integrity-badge`}
/>
</div>
{/* Business impact */}
{businessImpact && (
<div
className="mt-4"
data-testid={`${testId}-business-impact-container`}
>
<BusinessImpactSection
impact={businessImpact}
color="green"
testId={`${testId}-business-impact`}
/>
</div>
)}
{/* Data Integrity metrics */}
<div
className="mb-4 p-3 bg-green-50 dark:bg-green-900 dark:bg-opacity-20 rounded-lg"
data-testid={`${testId}-metrics`}
>
<h3 className="text-lg font-medium mb-2 text-green-800 dark:text-green-300">
Data Integrity Metrics
</h3>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
<div className="p-2 bg-white dark:bg-gray-800 rounded-lg">
<div className="text-sm font-medium mb-1">
Data Validation Controls:
</div>
<div className="text-lg font-bold text-green-600 dark:text-green-400">
{validationLevel}
</div>
</div>
<div className="p-2 bg-white dark:bg-gray-800 rounded-lg">
<div className="text-sm font-medium mb-1">
Acceptable Error Rate:
</div>
<div className="text-lg font-bold text-green-600 dark:text-green-400">
{errorRate}
</div>
</div>
</div>
</div>
{/* Recommendations (visible only when showExtendedDetails is true) */}
{showExtendedDetails && recommendations.length > 0 && (
<div className="mt-4">
<h3 className="text-lg font-medium mb-2">Recommendations</h3>
<ul className="list-disc pl-5 space-y-1">
{recommendations.map((rec, index) => (
<li
key={index}
className="text-sm text-gray-600 dark:text-gray-400"
>
{rec}
</li>
))}
</ul>
</div>
)}
</div>
</WidgetContainer>
</WidgetErrorBoundary>
);
};
export default IntegrityImpactWidget;
|