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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 31x 31x 31x 31x 31x 41x 41x 41x 41x 31x 31x 31x 31x 31x 41x 41x 41x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 41x 41x 31x 31x 31x 31x 31x 30x 30x 1x 1x 1x 1x 1x 1x 1x 10x 31x 41x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 41x 41x 30x 30x 30x 30x 30x 30x 30x 41x 41x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 41x 41x 31x 31x 31x 31x 31x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 126x 126x 126x 126x 126x 126x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 31x 31x 31x 31x 31x 31x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 30x 31x 31x 31x 28x 31x 2x 2x 2x 2x 2x 2x 31x 31x 31x 31x 1x | import React, { useMemo } from "react"; import { WIDGET_ICONS, WIDGET_TITLES } from "../../../constants/appConstants"; import { useCIAContentService } from "../../../hooks/useCIAContentService"; import { CIAComponent, SecurityLevel } from "../../../types/cia"; import { CostEstimationWidgetProps } from "../../../types/widgets"; import { calculateTotalSecurityCost } from "../../../utils/costCalculationUtils"; import { formatCurrency } from "../../../utils/formatUtils"; import { getImplementationComplexity } from "../../../utils/riskUtils"; import { getSecurityLevelValue } from "../../../utils/securityLevelUtils"; import { isArray, isNullish, isString } from "../../../utils/typeGuards"; import SecurityLevelBadge from "../../common/SecurityLevelBadge"; import WidgetContainer from "../../common/WidgetContainer"; /** * Widget for estimating implementation and operational costs * * ## Business Perspective * * This widget provides financial stakeholders with cost estimates * for implementing and maintaining the selected security levels, * helping with budget planning and investment decisions related * to security initiatives. 💲 */ const CostEstimationWidget: React.FC<CostEstimationWidgetProps> = ({ availabilityLevel, integrityLevel, confidentialityLevel, className = "", testId = "cost-estimation-widget", }) => { // Use the content service const { ciaContentService, error: serviceError, isLoading, } = useCIAContentService(); // Calculate costs using consistent utility function const { totalCapex, totalOpex, totalCost, availabilityCost, integrityCost, confidentialityCost, } = useMemo( () => calculateTotalSecurityCost( availabilityLevel, integrityLevel, confidentialityLevel ), [availabilityLevel, integrityLevel, confidentialityLevel] ); // Calculate implementation complexity using existing utility const implementationComplexity = useMemo( () => getImplementationComplexity( availabilityLevel, integrityLevel, confidentialityLevel ), [availabilityLevel, integrityLevel, confidentialityLevel] ); // Calculate FTE requirements using same approach as TechnicalDetailsWidget const fteRequirements = useMemo(() => { // FTE mapping from security level - same as in TechnicalDetailsWidget const levelFteMap: Record<SecurityLevel, number> = { None: 0.1, Low: 0.25, Moderate: 0.5, High: 1, "Very High": 2, }; // Calculate FTEs for each component based on their respective security levels const availFte = levelFteMap[availabilityLevel] || 0.5; const integFte = levelFteMap[integrityLevel] || 0.5; const confFte = levelFteMap[confidentialityLevel] || 0.5; // Find the max FTE across all components to match TechnicalDetailsWidget exactly const maxFte = Math.max(availFte, integFte, confFte); // Implementation is the primary FTE const implementationFte = maxFte; // Maintenance FTE is typically 60% of implementation const maintenanceFte = Number((implementationFte * 0.6).toFixed(1)); return { implementation: implementationFte, maintenance: maintenanceFte, total: Number((implementationFte + maintenanceFte).toFixed(1)), }; }, [availabilityLevel, integrityLevel, confidentialityLevel]); // Get expertise required - using defined type and handling missing property const getExpertiseForComponent = ( component: CIAComponent, level: SecurityLevel ): string[] => { try { if (isNullish(ciaContentService)) { return getDefaultExpertise(component, level); } const details = ciaContentService.getComponentDetails(component, level); // Since expertiseRequired is not in CIADetails type, we need to handle it differently // Use a type assertion with a runtime check for safety if (!isNullish(details)) { const anyDetails = details as any; if (isArray(anyDetails.expertiseRequired)) { return anyDetails.expertiseRequired; } if (isString(anyDetails.expertiseRequired)) { return [anyDetails.expertiseRequired]; } } return getDefaultExpertise(component, level); } catch (err) { console.error(`Error getting expertise for ${component}:`, err); return getDefaultExpertise(component, level); } }; // Get highest component expertise const expertiseRequired = useMemo(() => { // Get the component with the highest security level for expertise determination const highestComponent = [ { type: "availability" as CIAComponent, level: availabilityLevel }, { type: "integrity" as CIAComponent, level: integrityLevel }, { type: "confidentiality" as CIAComponent, level: confidentialityLevel, }, ].sort( (a, b) => getSecurityLevelValue(b.level) - getSecurityLevelValue(a.level) )[0]; return getExpertiseForComponent( highestComponent.type, highestComponent.level ); }, [availabilityLevel, integrityLevel, confidentialityLevel]); // Calculate the complexity percentage for visualization const complexityPercentage = useMemo(() => { const complexityMap: Record<string, number> = { Low: 25, Moderate: 50, High: 75, "Very High": 100, }; return complexityMap[implementationComplexity] || 0; }, [implementationComplexity]); // Calculate cost breakdown percentages for visualization const costBreakdown = useMemo(() => { const totalComponentCost = availabilityCost.capex + availabilityCost.opex + integrityCost.capex + integrityCost.opex + confidentialityCost.capex + confidentialityCost.opex; return { availability: totalComponentCost > 0 ? ( ((availabilityCost.capex + availabilityCost.opex) / totalComponentCost) * 100 ).toFixed(0) : "0", integrity: totalComponentCost > 0 ? ( ((integrityCost.capex + integrityCost.opex) / totalComponentCost) * 100 ).toFixed(0) : "0", confidentiality: totalComponentCost > 0 ? ( ((confidentialityCost.capex + confidentialityCost.opex) / totalComponentCost) * 100 ).toFixed(0) : "0", }; }, [availabilityCost, integrityCost, confidentialityCost]); // Calculate capex vs opex ratio const costRatio = useMemo(() => { const total = totalCapex + totalOpex; return { capex: total > 0 ? ((totalCapex / total) * 100).toFixed(0) : "0", opex: total > 0 ? ((totalOpex / total) * 100).toFixed(0) : "0", }; }, [totalCapex, totalOpex]); return ( <WidgetContainer title={WIDGET_TITLES.COST_ESTIMATION || "Cost Estimation"} icon={WIDGET_ICONS.COST_ESTIMATION || "💰"} className={className} testId={testId} isLoading={isLoading} error={serviceError} > <div className="p-4"> {/* Introduction */} <div className="mb-4 p-3 bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 rounded-lg"> <p className="text-sm"> This widget provides cost estimates for implementing and maintaining security controls based on your selected security levels across the CIA triad. </p> </div> {/* Summary cost section - using direct JSX instead of InfoCard */} <div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <div className="flex items-center mb-2"> <span className="mr-2 text-blue-500">💼</span> <div className="text-sm text-gray-600 dark:text-gray-400"> Implementation Cost </div> </div> <div className="text-2xl font-bold text-blue-600 dark:text-blue-400"> {formatCurrency(totalCapex)} </div> <div className="text-xs text-gray-500 dark:text-gray-500"> One-time capital expenditure </div> </div> <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <div className="flex items-center mb-2"> <span className="mr-2 text-green-500">🔄</span> <div className="text-sm text-gray-600 dark:text-gray-400"> Annual Operations </div> </div> <div className="text-2xl font-bold text-green-600 dark:text-green-400"> {formatCurrency(totalOpex)} </div> <div className="text-xs text-gray-500 dark:text-gray-500"> Yearly operational expenses </div> </div> <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <div className="flex items-center mb-2"> <span className="mr-2 text-purple-500">💲</span> <div className="text-sm text-gray-600 dark:text-gray-400"> Total First Year Cost </div> </div> <div className="text-2xl font-bold text-purple-600 dark:text-purple-400"> {formatCurrency(totalCost)} </div> <div className="text-xs text-gray-500 dark:text-gray-500"> Implementation + first year operations </div> </div> </div> {/* CAPEX vs OPEX ratio visualization */} <div className="mb-6"> <h3 className="text-lg font-medium mb-3">Cost Breakdown</h3> <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <div className="flex justify-between items-center mb-1"> <div className="text-sm font-medium">CAPEX</div> <div className="text-sm font-medium">OPEX</div> </div> <div className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-3 mb-2"> <div className="h-3 bg-blue-500 rounded-l-full" style={{ width: `${costRatio.capex}%` }} ></div> </div> <div className="flex justify-between text-xs text-gray-600 dark:text-gray-400"> <div> {costRatio.capex}% ({formatCurrency(totalCapex)}) </div> <div> {costRatio.opex}% ({formatCurrency(totalOpex)}) </div> </div> </div> </div> {/* Implementation details grid */} <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6"> {/* Implementation complexity */} <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <h4 className="text-md font-medium mb-3"> Implementation Complexity </h4> <div className="mb-3"> <div className="text-lg font-bold text-purple-600 dark:text-purple-400"> {implementationComplexity} </div> <div className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2.5 mt-2"> <div className="h-2.5 bg-purple-500 dark:bg-purple-600 rounded-full" style={{ width: `${complexityPercentage}%` }} ></div> </div> </div> <div className="text-xs text-gray-500 dark:text-gray-500"> Based on combined complexity across CIA components </div> </div> {/* Personnel requirements */} <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <h4 className="text-md font-medium mb-3">Personnel Requirements</h4> <div className="grid grid-cols-1 gap-3"> <div className="flex justify-between items-center"> <div className="text-sm text-gray-600 dark:text-gray-400"> Implementation Team </div> <div className="text-lg font-bold text-blue-600 dark:text-blue-400"> {fteRequirements.implementation} FTE </div> </div> <div className="flex justify-between items-center"> <div className="text-sm text-gray-600 dark:text-gray-400"> Ongoing Maintenance </div> <div className="text-lg font-bold text-green-600 dark:text-green-400"> {fteRequirements.maintenance} FTE </div> </div> <div className="flex justify-between items-center pt-2 mt-2 border-t border-gray-200 dark:border-gray-700"> <div className="text-sm font-medium text-gray-600 dark:text-gray-400"> Annual Personnel Cost </div> <div className="text-lg font-bold"> {formatCurrency(fteRequirements.total * 120000)} </div> </div> </div> </div> </div> {/* Component breakdown */} <div className="mb-6"> <h3 className="text-lg font-medium mb-3"> Cost by Security Component </h3> <div className="grid grid-cols-1 gap-3"> {/* Using SecurityLevelBadge component for consistency with other widgets */} <div className="p-3 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 rounded-lg"> <div className="flex justify-between items-center mb-2"> <div className="font-medium text-purple-800 dark:text-purple-300 flex items-center"> <span className="mr-2">🔒</span>Confidentiality </div> <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={`${testId}-conf-level`} /> </div> <div className="flex justify-between items-center"> <div className="text-md font-bold text-purple-600 dark:text-purple-400"> {formatCurrency( confidentialityCost.capex + confidentialityCost.opex )} </div> <div className="text-sm bg-purple-100 dark:bg-purple-900 dark:bg-opacity-30 px-2 py-1 rounded"> {costBreakdown.confidentiality}% of total </div> </div> <div className="text-xs mt-2 text-gray-600 dark:text-gray-400 flex justify-between"> <span>CAPEX: {formatCurrency(confidentialityCost.capex)}</span> <span>OPEX: {formatCurrency(confidentialityCost.opex)}</span> </div> </div> <div className="p-3 bg-green-50 dark:bg-green-900 dark:bg-opacity-20 rounded-lg"> <div className="flex justify-between items-center mb-2"> <div className="font-medium text-green-800 dark:text-green-300 flex items-center"> <span className="mr-2">✓</span>Integrity </div> <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={`${testId}-int-level`} /> </div> <div className="flex justify-between items-center"> <div className="text-md font-bold text-green-600 dark:text-green-400"> {formatCurrency(integrityCost.capex + integrityCost.opex)} </div> <div className="text-sm bg-green-100 dark:bg-green-900 dark:bg-opacity-30 px-2 py-1 rounded"> {costBreakdown.integrity}% of total </div> </div> <div className="text-xs mt-2 text-gray-600 dark:text-gray-400 flex justify-between"> <span>CAPEX: {formatCurrency(integrityCost.capex)}</span> <span>OPEX: {formatCurrency(integrityCost.opex)}</span> </div> </div> <div className="p-3 bg-blue-50 dark:bg-blue-900 dark:bg-opacity-20 rounded-lg"> <div className="flex justify-between items-center mb-2"> <div className="font-medium text-blue-800 dark:text-blue-300 flex items-center"> <span className="mr-2">⏱️</span>Availability </div> <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={`${testId}-avail-level`} /> </div> <div className="flex justify-between items-center"> <div className="text-md font-bold text-blue-600 dark:text-blue-400"> {formatCurrency( availabilityCost.capex + availabilityCost.opex )} </div> <div className="text-sm bg-blue-100 dark:bg-blue-900 dark:bg-opacity-30 px-2 py-1 rounded"> {costBreakdown.availability}% of total </div> </div> <div className="text-xs mt-2 text-gray-600 dark:text-gray-400 flex justify-between"> <span>CAPEX: {formatCurrency(availabilityCost.capex)}</span> <span>OPEX: {formatCurrency(availabilityCost.opex)}</span> </div> </div> </div> </div> {/* Expertise required */} <div className="mb-6"> <h3 className="text-lg font-medium mb-3">Expertise Required</h3> <div className="p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"> <ul className="grid grid-cols-1 md:grid-cols-2 gap-2"> {expertiseRequired.map((expertise: string, index: number) => ( <li key={`expertise-${index}`} className="flex items-center text-sm" > <span className="mr-2 text-blue-500">•</span> <span>{expertise}</span> </li> ))} </ul> </div> </div> {/* Cost notes */} <div className="p-3 bg-yellow-50 dark:bg-yellow-900 dark:bg-opacity-20 rounded-lg"> <h4 className="text-md font-medium mb-2 flex items-center"> <span className="mr-2">💡</span>Cost Notes </h4> <ul className="list-disc list-inside space-y-1 text-sm text-gray-600 dark:text-gray-400 pl-2"> <li> Estimates are based on industry averages for the selected security levels </li> <li> Actual costs may vary based on your organization's size and industry </li> <li> FTE calculations assume an average annual cost of $120,000 per full-time employee </li> <li> Consider consulting with security professionals for more accurate cost projections </li> </ul> </div> </div> </WidgetContainer> ); }; // Helper function to provide default expertise requirements function getDefaultExpertise( component: CIAComponent, level: SecurityLevel ): string[] { if (component === "confidentiality") { switch (level) { case "None": return ["No specific expertise required"]; case "Low": return ["Basic security knowledge", "Access control fundamentals"]; case "Moderate": return [ "Identity management", "Encryption technologies", "Authentication systems", ]; case "High": return [ "Advanced cryptography", "Identity and access management", "Security architecture", "Data protection", ]; case "Very High": return [ "Security architecture", "Advanced cryptography", "Zero-trust implementation", "Data protection specialization", "Hardware security", ]; default: return ["General security knowledge"]; } } if (component === "integrity") { switch (level) { case "None": return ["No specific expertise required"]; case "Low": return ["Basic data validation", "Error handling"]; case "Moderate": return [ "Data validation techniques", "Database integrity", "Error handling", ]; case "High": return [ "Cryptographic verification", "Digital signatures", "Secure logging", "Change management", ]; case "Very High": return [ "Advanced cryptography", "Formal verification", "Distributed ledger technologies", "Immutable logging systems", ]; default: return ["Data integrity fundamentals"]; } } // Default to availability expertise switch (level) { case "None": return ["No specific expertise required"]; case "Low": return ["Basic system monitoring", "Manual recovery procedures"]; case "Moderate": return ["System redundancy", "Backup management", "Basic load balancing"]; case "High": return [ "High availability architecture", "Disaster recovery", "Advanced monitoring", "Automated failover", ]; case "Very High": return [ "Distributed systems", "Site reliability engineering", "Global load balancing", "Chaos engineering", "Real-time recovery systems", ]; default: return ["System reliability fundamentals"]; } } export default CostEstimationWidget; |