All files / src/components/widgets/impactanalysis ConfidentialityImpactWidget.tsx

80.64% Statements 25/31
76% Branches 19/25
100% Functions 5/5
80.64% Lines 25/31

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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192                                                                6x                           32x       32x     32x 32x 32x 21x     11x         11x               32x 32x 32x 21x     11x         11x                   32x 32x 21x     11x 11x               32x 32x 10x   22x     32x                                                                                                                                                          
import React, { useMemo } from "react";
import { WIDGET_ICONS, WIDGET_TITLES } from "../../../constants/appConstants";
import { getDefaultPrivacyImpact } from "../../../data/ciaOptionsData";
import { useCIAContentService } from "../../../hooks/useCIAContentService";
import { ComponentImpactBaseProps } from "../../../types/widgets";
import { getSecurityLevelBackgroundClass } from "../../../utils/colorUtils";
import { getDefaultComponentImpact } from "../../../utils/riskUtils";
import { isNullish } from "../../../utils/typeGuards";
import BusinessImpactSection from "../../common/BusinessImpactSection";
import SecurityLevelBadge from "../../common/SecurityLevelBadge";
import WidgetContainer from "../../common/WidgetContainer";
 
/**
 * Props for the Confidentiality Impact Widget
 */
export interface ConfidentialityImpactWidgetProps
  extends ComponentImpactBaseProps {
  // All required props are inherited from ComponentImpactBaseProps
}
 
/**
 * Displays confidentiality impact details for the selected security level
 *
 * ## Business Perspective
 *
 * This widget helps stakeholders understand how confidentiality security levels
 * affect business operations through metrics like data classification, access controls,
 * and encryption methods. The visualization of these metrics supports better decision-making
 * about data protection requirements and privacy investments. 🔒
 */
const ConfidentialityImpactWidget: React.FC<
  ConfidentialityImpactWidgetProps
> = ({
  level, // For backward compatibility
  availabilityLevel,
  integrityLevel,
  confidentialityLevel,
  className = "",
  testId = "widget-confidentiality-impact",
  onLevelChange,
}) => {
  // Use the content service to get component details
  const {
    ciaContentService,
    error: serviceError,
    isLoading,
  } = useCIAContentService();
 
  // Use the effective level - prefer the specific confidentialityLevel if available,
  // otherwise fall back to the legacy level prop
  const effectiveLevel = confidentialityLevel || level || "Moderate";
 
  // Get component details from service
  const details = useMemo(() => {
    try {
      if (isNullish(ciaContentService)) {
        return null;
      }
 
      const componentDetails = ciaContentService.getComponentDetails(
        "confidentiality",
        effectiveLevel
      );
 
      return isNullish(componentDetails) ? null : componentDetails;
    } catch (err) {
      console.error("Error fetching confidentiality details:", err);
      return null;
    }
  }, [ciaContentService, effectiveLevel]);
 
  // Get business impact from service with fallback to our utility
  const businessImpact = useMemo(() => {
    try {
      if (isNullish(ciaContentService)) {
        return getDefaultComponentImpact("confidentiality", effectiveLevel);
      }
 
      const impact = ciaContentService.getBusinessImpact(
        "confidentiality",
        effectiveLevel
      );
 
      return (
        impact || getDefaultComponentImpact("confidentiality", effectiveLevel)
      );
    } catch (err) {
      console.error("Error fetching business impact details:", err);
      return getDefaultComponentImpact("confidentiality", effectiveLevel);
    }
  }, [ciaContentService, effectiveLevel]);
 
  // Get data classification from service with fallback
  const dataClassification = useMemo(() => {
    if (isNullish(ciaContentService)) {
      return `${effectiveLevel} Classification`;
    }
 
    try {
      return ciaContentService.getInformationSensitivity(effectiveLevel);
    } catch (err) {
      console.error("Error getting data classification:", err);
      return `${effectiveLevel} Classification`;
    }
  }, [ciaContentService, effectiveLevel]);
 
  // Get privacy impact with fallback to utility function
  const privacyImpact = useMemo(() => {
    if (!isNullish(details) && details.privacyImpact) {
      return details.privacyImpact;
    }
    return getDefaultPrivacyImpact(effectiveLevel);
  }, [details, effectiveLevel]);
 
  return (
    <WidgetContainer
      title={
        WIDGET_TITLES.CONFIDENTIALITY_IMPACT ||
        "Confidentiality Impact Analysis"
      }
      icon={WIDGET_ICONS.CONFIDENTIALITY_IMPACT || "🔒"}
      className={`${className} overflow-visible`}
      testId={testId}
      isLoading={isLoading}
      error={serviceError}
    >
      <div className="max-h-[550px] overflow-y-auto pr-1">
        <div
          className="p-4"
          role="region"
          aria-labelledby="confidentiality-impact-heading"
        >
          <div className="mb-4">
            <SecurityLevelBadge
              category="Confidentiality"
              level={effectiveLevel}
              // Use utility functions for consistent color handling
              colorClass={getSecurityLevelBackgroundClass("purple")}
              textClass="text-purple-800 dark:text-purple-300"
              testId={`${testId}-confidentiality-badge`}
            />
          </div>
 
          {/* Business Impact */}
          {businessImpact && (
            <BusinessImpactSection
              impact={businessImpact}
              color="purple"
              testId={`${testId}-business-impact`}
            />
          )}
 
          {/* Data Protection & Classification */}
          <div className="mb-6">
            <h4 className="text-md font-medium mb-3 flex items-center">
              <span className="mr-2">📊</span>Data Protection
            </h4>
            <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
              <div className="p-3 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 rounded-lg border border-purple-100 dark:border-purple-800">
                <div className="text-sm font-medium mb-1 text-purple-700 dark:text-purple-300">
                  Data Classification
                </div>
                <div className="text-lg font-bold">{dataClassification}</div>
                <div className="text-xs text-purple-600 dark:text-purple-400">
                  Level of data sensitivity
                </div>
              </div>
            </div>
          </div>
 
          {/* Privacy Impact */}
          <div className="mb-6">
            <h4 className="text-md font-medium mb-3 flex items-center">
              <span className="mr-2">🔒</span>Privacy Impact
            </h4>
            <div className="grid grid-cols-1 md: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">Privacy Impact:</div>
                <div className="text-lg font-bold text-purple-600 dark:text-purple-400">
                  {privacyImpact}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </WidgetContainer>
  );
};
 
export default ConfidentialityImpactWidget;