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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 35x 35x 35x 34x 34x 1x 1x 1x 35x 35x 35x 35x 35x 35x 35x 35x 34x 34x 34x 34x 34x 34x 35x 35x 35x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 219x 219x 219x 219x 219x 73x 73x 73x 45x 18x 2x 219x 73x 73x 73x 29x 2x 219x 73x 73x 73x 29x 4x 219x 219x 219x 73x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 38x 38x 38x 38x 38x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 365x 365x 365x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 365x 365x 365x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 365x 365x 365x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 72x 72x 72x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x | import React, { useCallback, useEffect, useState } from "react"; import { SECURITY_LEVELS, WIDGET_ICONS, WIDGET_TITLES, } from "../../../constants/appConstants"; import { CIA_COMPONENT_ICONS } from "../../../constants/uiConstants"; import { useCIAContentService } from "../../../hooks/useCIAContentService"; import { SecurityLevel } from "../../../types/cia"; import SecurityLevelBadge from "../../common/SecurityLevelBadge"; import WidgetContainer from "../../common/WidgetContainer"; /** * Props for SecurityLevelWidget component */ export interface SecurityLevelWidgetProps { /** * Selected availability level */ availabilityLevel: SecurityLevel; /** * Selected integrity level */ integrityLevel: SecurityLevel; /** * Selected confidentiality level */ confidentialityLevel: SecurityLevel; /** * Handler for availability level changes */ onAvailabilityChange?: (level: SecurityLevel) => void; /** * Handler for integrity level changes */ onIntegrityChange?: (level: SecurityLevel) => void; /** * Handler for confidentiality level changes */ onConfidentialityChange?: (level: SecurityLevel) => void; /** * Optional CSS class name */ className?: string; /** * Optional test ID for testing */ testId?: string; } /** * Widget for configuring CIA triad security levels * * ## Business Perspective * * This widget serves as the primary control center for security officers to * configure their organization's security posture across the CIA triad. It * provides clear descriptions of each security level to help users make * informed decisions about their security requirements. 🔒 * * ## Security Perspective * * Enables fine-grained control over each CIA component, with detailed * explanations of security implications for each level. Helps security * teams implement appropriate controls based on organizational needs. * * ## Architecture Perspective * * Provides technical implementation details for each security level, * helping system architects understand what controls and mechanisms * need to be implemented to achieve the selected security levels. */ const SecurityLevelWidget: React.FC<SecurityLevelWidgetProps> = ({ availabilityLevel, integrityLevel, confidentialityLevel, onAvailabilityChange, onIntegrityChange, onConfidentialityChange, className = "", testId = "security-level-widget", }) => { // Use the content service for security level details const { ciaContentService } = useCIAContentService(); // Define local state for error and loading const [serviceError, setServiceError] = useState<Error | null>(null); const [isLoading, setIsLoading] = useState(false); // Track which component is active for details display const [activeComponent, setActiveComponent] = useState< "availability" | "integrity" | "confidentiality" >("availability"); // Add error state const [error, setError] = useState<Error | null>(null); const [activeDetails, setActiveDetails] = useState<any>(null); // Track the last changed component for visual feedback const [lastChangedComponent, setLastChangedComponent] = useState< "availability" | "integrity" | "confidentiality" | null >(null); // Get details for the active component with error handling useEffect(() => { setIsLoading(true); try { if (!ciaContentService) { throw new Error("Content service unavailable"); } const selectedLevel = activeComponent === "availability" ? availabilityLevel : activeComponent === "integrity" ? integrityLevel : confidentialityLevel; const details = ciaContentService.getComponentDetails( activeComponent, selectedLevel ) || { description: "No details available", technical: "No technical information available", businessImpact: "No business impact information available", recommendations: [], }; setActiveDetails(details); setError(null); setServiceError(null); } catch (err) { console.error("Error loading component details:", err); setError( err instanceof Error ? err : new Error("Failed to load component details") ); setServiceError(err instanceof Error ? err : new Error("Service error")); } finally { setIsLoading(false); } }, [ ciaContentService, activeComponent, availabilityLevel, integrityLevel, confidentialityLevel, ]); // Create handler functions that call the prop handlers const handleAvailabilityChange = useCallback( (event: React.ChangeEvent<HTMLSelectElement>) => { const newLevel = event.target.value as SecurityLevel; console.log("SecurityLevelWidget: Setting availability to", newLevel); if (onAvailabilityChange) onAvailabilityChange(newLevel); setLastChangedComponent("availability"); }, [onAvailabilityChange] ); const handleIntegrityChange = useCallback( (event: React.ChangeEvent<HTMLSelectElement>) => { const newLevel = event.target.value as SecurityLevel; console.log("SecurityLevelWidget: Setting integrity to", newLevel); if (onIntegrityChange) onIntegrityChange(newLevel); setLastChangedComponent("integrity"); }, [onIntegrityChange] ); const handleConfidentialityChange = useCallback( (event: React.ChangeEvent<HTMLSelectElement>) => { const newLevel = event.target.value as SecurityLevel; console.log("SecurityLevelWidget: Setting confidentiality to", newLevel); if (onConfidentialityChange) onConfidentialityChange(newLevel); setLastChangedComponent("confidentiality"); }, [onConfidentialityChange] ); // Get security level options const securityLevelOptions = [ SECURITY_LEVELS.NONE, SECURITY_LEVELS.LOW, SECURITY_LEVELS.MODERATE, SECURITY_LEVELS.HIGH, SECURITY_LEVELS.VERY_HIGH, ]; // Helper function to get component-specific summary const getComponentSummary = ( component: string, level: SecurityLevel ): string => { switch (component) { case "availability": if (level === "None") return "No uptime guarantees"; if (level === "Low") return "~95% uptime, 24-48h recovery"; if (level === "Moderate") return "~99% uptime, 4-8h recovery"; if (level === "High") return "~99.9% uptime, 15-60min recovery"; if (level === "Very High") return "~99.99% uptime, <5min recovery"; return ""; case "integrity": if (level === "None") return "No validation controls"; if (level === "Low") return "Manual validation with basic checks"; if (level === "Moderate") return "Automated validation with checks"; if (level === "High") return "Cryptographic verification"; if (level === "Very High") return "Blockchain validation"; return ""; case "confidentiality": if (level === "None") return "No access controls"; if (level === "Low") return "Basic access control"; if (level === "Moderate") return "RBAC with encryption"; if (level === "High") return "E2E encryption with MFA"; if (level === "Very High") return "Zero-trust architecture"; return ""; default: return "No details available"; } }; // Get color class for component - Use standardized utility const getComponentColor = (component: string): string => { switch (component) { case "availability": return "text-blue-600 dark:text-blue-400"; case "integrity": return "text-green-600 dark:text-green-400"; case "confidentiality": return "text-purple-600 dark:text-purple-400"; default: return "text-gray-600 dark:text-gray-400"; } }; // Add debugging to the component render console.log("SecurityLevelWidget rendering with levels:", { availabilityLevel, integrityLevel, confidentialityLevel, }); return ( <WidgetContainer title={WIDGET_TITLES.SECURITY_LEVEL} icon={WIDGET_ICONS.SECURITY_LEVEL} className={className} testId={testId} > <div className="p-4"> <div className="mb-4 p-3 bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 rounded-lg"> <p className="text-sm"> Configure security levels for each CIA component to set your organization's security posture. Higher levels provide stronger protection but may require more resources to implement. </p> </div> {/* Display error message if there's an error */} {(error || serviceError) && ( <div className="p-3 mb-4 bg-red-100 dark:bg-red-900 dark:bg-opacity-20 text-red-800 dark:text-red-200 rounded-lg"> <h4 className="font-medium">Error</h4> <p className="text-sm"> Unable to load component details. Please try again later. </p> </div> )} {/* Display loading state */} {isLoading && ( <div className="p-3 mb-4 bg-blue-100 dark:bg-blue-900 dark:bg-opacity-20 text-blue-800 dark:text-blue-200 rounded-lg"> <p className="text-sm">Loading security level details...</p> </div> )} <div className="grid grid-cols-1 md:grid-cols-2 gap-6"> {/* Security level selectors */} <div> <h3 className="text-lg font-medium mb-4"> Configure Security Levels </h3> <div className="space-y-4"> {/* Availability selector */} <div className="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700" data-testid="security-level-availability" > <div className="flex justify-between items-center mb-2"> <label htmlFor="availability-select" className="text-sm font-medium flex items-center" > <span className="text-blue-500 dark:text-blue-400 mr-2"> {CIA_COMPONENT_ICONS.availability} </span> Availability </label> <SecurityLevelBadge category="" level={availabilityLevel} colorClass="bg-blue-100 dark:bg-blue-900 dark:bg-opacity-20" textClass="text-blue-800 dark:text-blue-300" testId="security-level-widget-availability-badge" /> </div> <select id="availability-select" className="w-full p-2 border rounded-md bg-white dark:bg-gray-700 dark:border-gray-600 transition-all duration-300 hover:border-blue-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-200" value={availabilityLevel} onChange={handleAvailabilityChange} data-testid="availability-select" > {securityLevelOptions.map((level) => ( <option key={`availability-${level}`} value={level}> {level} </option> ))} </select> <div className="mt-2 text-xs text-gray-600 dark:text-gray-400" data-testid="security-level-widget-availability-summary" > {availabilityLevel}:{" "} {getComponentSummary("availability", availabilityLevel)} </div> <button className="mt-2 text-xs text-blue-600 dark:text-blue-400 hover:underline" onClick={() => setActiveComponent("availability")} data-testid="availability-details-button" > View details </button> {lastChangedComponent === "availability" && ( <div className="mt-2 text-xs text-green-600 dark:text-green-400 animate-pulse" data-testid="availability-changed-indicator" > ✓ Security level updated </div> )} </div> {/* Integrity selector */} <div className="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700" data-testid="security-level-integrity" > <div className="flex justify-between items-center mb-2"> <label htmlFor="integrity-select" className="text-sm font-medium flex items-center" > <span className="text-green-500 dark:text-green-400 mr-2"> {CIA_COMPONENT_ICONS.integrity} </span> Integrity </label> <SecurityLevelBadge category="" level={integrityLevel} colorClass="bg-green-100 dark:bg-green-900 dark:bg-opacity-20" textClass="text-green-800 dark:text-green-300" testId="security-level-widget-integrity-badge" /> </div> <select id="integrity-select" className="w-full p-2 border rounded-md bg-white dark:bg-gray-700 dark:border-gray-600 transition-all duration-300 hover:border-green-400 focus:border-green-500 focus:ring-2 focus:ring-green-200" value={integrityLevel} onChange={handleIntegrityChange} data-testid="integrity-select" > {securityLevelOptions.map((level) => ( <option key={`integrity-${level}`} value={level}> {level} </option> ))} </select> <div className="mt-2 text-xs text-gray-600 dark:text-gray-400" data-testid="security-level-widget-integrity-summary" > {integrityLevel}:{" "} {getComponentSummary("integrity", integrityLevel)} </div> <button className="mt-2 text-xs text-blue-600 dark:text-blue-400 hover:underline" onClick={() => setActiveComponent("integrity")} data-testid="integrity-details-button" > View details </button> {lastChangedComponent === "integrity" && ( <div className="mt-2 text-xs text-green-600 dark:text-green-400 animate-pulse" data-testid="integrity-changed-indicator" > ✓ Security level updated </div> )} </div> {/* Confidentiality selector */} <div className="p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700" data-testid="security-level-confidentiality" > <div className="flex justify-between items-center mb-2"> <label htmlFor="confidentiality-select" className="text-sm font-medium flex items-center" > <span className="text-purple-500 dark:text-purple-400 mr-2"> {CIA_COMPONENT_ICONS.confidentiality} </span> Confidentiality </label> <SecurityLevelBadge category="" level={confidentialityLevel} colorClass="bg-purple-100 dark:bg-purple-900 dark:bg-opacity-20" textClass="text-purple-800 dark:text-purple-300" testId="security-level-widget-confidentiality-badge" /> </div> <select id="confidentiality-select" className="w-full p-2 border rounded-md bg-white dark:bg-gray-700 dark:border-gray-600 transition-all duration-300 hover:border-purple-400 focus:border-purple-500 focus:ring-2 focus:ring-purple-200" value={confidentialityLevel} onChange={handleConfidentialityChange} data-testid="confidentiality-select" > {securityLevelOptions.map((level) => ( <option key={`confidentiality-${level}`} value={level}> {level} </option> ))} </select> <div className="mt-2 text-xs text-gray-600 dark:text-gray-400" data-testid="security-level-widget-confidentiality-summary" > {confidentialityLevel}:{" "} {getComponentSummary("confidentiality", confidentialityLevel)} </div> <button className="mt-2 text-xs text-blue-600 dark:text-blue-400 hover:underline" onClick={() => setActiveComponent("confidentiality")} data-testid="confidentiality-details-button" > View details </button> {lastChangedComponent === "confidentiality" && ( <div className="mt-2 text-xs text-green-600 dark:text-green-400 animate-pulse" data-testid="confidentiality-changed-indicator" > ✓ Security level updated </div> )} </div> </div> </div> {/* Security level details */} <div> <h3 className="text-lg font-medium mb-4"> {activeComponent.charAt(0).toUpperCase() + activeComponent.slice(1)}{" "} Details </h3> <div className="p-4 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 h-full" data-testid={`${activeComponent}-details-content`} > {activeDetails ? ( <div className="space-y-4"> <h4 className={`font-medium ${getComponentColor( activeComponent )}`} > {activeComponent === "availability" ? availabilityLevel : activeComponent === "integrity" ? integrityLevel : confidentialityLevel}{" "} Level </h4> <div className="space-y-3"> {/* Description */} <div> <h5 className="text-sm font-medium mb-1">Description</h5> <p className="text-sm text-gray-600 dark:text-gray-400"> {activeDetails.description || "No description available"} </p> </div> {/* Technical implementation */} <div> <h5 className="text-sm font-medium mb-1"> Technical Implementation </h5> <p className="text-sm text-gray-600 dark:text-gray-400"> {activeDetails.technical || "No technical details available"} </p> </div> {/* Business impact */} <div> <h5 className="text-sm font-medium mb-1"> Business Impact </h5> <p className="text-sm text-gray-600 dark:text-gray-400"> {activeDetails.businessImpact || "No business impact details available"} </p> </div> {/* Component-specific details */} {activeComponent === "availability" && ( <div className="mt-4 grid grid-cols-2 gap-3"> <div className="bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 p-2 rounded"> <div className="text-xs font-medium mb-1 text-blue-700 dark:text-blue-300"> Uptime </div> <div className="text-sm"> {activeDetails.uptime || "N/A"} </div> </div> <div className="bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 p-2 rounded"> <div className="text-xs font-medium mb-1 text-blue-700 dark:text-blue-300"> Recovery Time </div> <div className="text-sm"> {activeDetails.rto || "N/A"} </div> </div> </div> )} {activeComponent === "integrity" && activeDetails.validationMethod && ( <div className="mt-4 bg-green-50 dark:bg-green-900 dark:bg-opacity-20 p-2 rounded"> <div className="text-xs font-medium mb-1 text-green-700 dark:text-green-300"> Validation Method </div> <div className="text-sm"> {activeDetails.validationMethod} </div> </div> )} {activeComponent === "confidentiality" && activeDetails.protectionMethod && ( <div className="mt-4 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 p-2 rounded"> <div className="text-xs font-medium mb-1 text-purple-700 dark:text-purple-300"> Protection Method </div> <div className="text-sm"> {activeDetails.protectionMethod} </div> </div> )} </div> </div> ) : ( <div className="text-center text-gray-500 dark:text-gray-400 py-8"> <p>No details available for this security level.</p> </div> )} </div> </div> </div> {/* Security level overview */} <div className="mt-6 bg-gray-100 dark:bg-gray-800 p-4 rounded-lg"> <h3 className="text-md font-medium mb-2">Security Level Overview</h3> <p className="text-sm text-gray-600 dark:text-gray-400 mb-3"> Higher security levels provide stronger protection but typically require more resources to implement and maintain. Consider your organization's needs and constraints when selecting security levels. </p> <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 text-xs"> <div className="p-2 bg-red-50 dark:bg-red-900 dark:bg-opacity-20 rounded"> <div className="font-medium text-red-700 dark:text-red-300"> None </div> <div className="text-red-600 dark:text-red-400"> Minimal to no security controls </div> </div> <div className="p-2 bg-yellow-50 dark:bg-yellow-900 dark:bg-opacity-20 rounded"> <div className="font-medium text-yellow-700 dark:text-yellow-300"> Low </div> <div className="text-yellow-600 dark:text-yellow-400"> Basic security controls </div> </div> <div className="p-2 bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 rounded"> <div className="font-medium text-blue-700 dark:text-blue-300"> Moderate </div> <div className="text-blue-600 dark:text-blue-400"> Standard security controls </div> </div> <div className="p-2 bg-green-50 dark:bg-green-900 dark:bg-opacity-20 rounded"> <div className="font-medium text-green-700 dark:text-green-300"> High </div> <div className="text-green-600 dark:text-green-400"> Advanced security controls </div> </div> <div className="p-2 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 rounded"> <div className="font-medium text-purple-700 dark:text-purple-300"> Very High </div> <div className="text-purple-600 dark:text-purple-400"> Maximum security controls </div> </div> </div> </div> </div> </WidgetContainer> ); }; // Export the component directly without HOC export default SecurityLevelWidget; |