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 | 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 12x 14x 14x 12x 14x 14x 12x 14x 14x 14x 12x 60x 60x 12x 14x 14x 14x 14x 12x 60x 60x 12x 14x 14x 14x 14x 12x 60x 60x 12x 14x 14x 14x 14x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x | import React, { useCallback, useEffect, useMemo, useState } from "react"; import { CIA_COMPONENT_ICONS, CIA_LABELS } from "../../constants/coreConstants"; import { useCIAOptions } from "../../hooks/useCIAOptions"; import { SecurityLevel } from "../../types/cia"; import { Selection } from "./Selection"; type SecurityLevelSelectorProps = { availabilityLevel: SecurityLevel; integrityLevel: SecurityLevel; confidentialityLevel: SecurityLevel; onAvailabilityChange?: (level: SecurityLevel) => void; onIntegrityChange?: (level: SecurityLevel) => void; onConfidentialityChange?: (level: SecurityLevel) => void; disabled?: boolean; compact?: boolean; testId?: string; }; /** * Component for selecting CIA security levels * * ## Business Perspective * * The SecurityLevelSelector is the primary interface for security officers * to establish their organization's security posture across the CIA triad. * These selections drive compliance assessments and implementation costs. 💼 */ export const SecurityLevelSelector: React.FC<SecurityLevelSelectorProps> = ({ availabilityLevel, integrityLevel, confidentialityLevel, onAvailabilityChange, onIntegrityChange, onConfidentialityChange, disabled = false, compact = false, testId = "security-level-selector", }) => { const { availabilityOptions, integrityOptions, confidentialityOptions } = useCIAOptions(); // Add local state to sync with props const [localAvailabilityLevel, setLocalAvailabilityLevel] = useState<SecurityLevel>(availabilityLevel); const [localIntegrityLevel, setLocalIntegrityLevel] = useState<SecurityLevel>(integrityLevel); const [localConfidentialityLevel, setLocalConfidentialityLevel] = useState<SecurityLevel>(confidentialityLevel); // Sync local state with props useEffect(() => { setLocalAvailabilityLevel(availabilityLevel); }, [availabilityLevel]); useEffect(() => { setLocalIntegrityLevel(integrityLevel); }, [integrityLevel]); useEffect(() => { setLocalConfidentialityLevel(confidentialityLevel); }, [confidentialityLevel]); // Prepare options for each security level dropdown const availabilitySelectOptions = useMemo( () => Object.entries(availabilityOptions).map(([key]) => ({ value: key, label: `${key} - ${availabilityOptions[key as SecurityLevel]?.description || ""}`, })), [availabilityOptions] ); const integritySelectOptions = useMemo( () => Object.entries(integrityOptions).map(([key]) => ({ value: key, label: `${key} - ${integrityOptions[key as SecurityLevel]?.description || ""}`, })), [integrityOptions] ); const confidentialitySelectOptions = useMemo( () => Object.entries(confidentialityOptions).map(([key]) => ({ value: key, label: `${key} - ${confidentialityOptions[key as SecurityLevel]?.description || ""}`, })), [confidentialityOptions] ); // Handle level change callbacks const handleAvailabilityChange = useCallback( (value: string) => { const securityLevel = value as SecurityLevel; setLocalAvailabilityLevel(securityLevel); if (onAvailabilityChange) { onAvailabilityChange(securityLevel); } }, [onAvailabilityChange] ); const handleIntegrityChange = useCallback( (value: string) => { const securityLevel = value as SecurityLevel; setLocalIntegrityLevel(securityLevel); if (onIntegrityChange) { onIntegrityChange(securityLevel); } }, [onIntegrityChange] ); const handleConfidentialityChange = useCallback( (value: string) => { const securityLevel = value as SecurityLevel; setLocalConfidentialityLevel(securityLevel); if (onConfidentialityChange) { onConfidentialityChange(securityLevel); } }, [onConfidentialityChange] ); // Information for tooltip/info panels const confidentialityInfo = useMemo( () => confidentialityOptions[localConfidentialityLevel]?.technical || "", [confidentialityOptions, localConfidentialityLevel] ); const integrityInfo = useMemo( () => integrityOptions[localIntegrityLevel]?.technical || "", [integrityOptions, localIntegrityLevel] ); const availabilityInfo = useMemo( () => availabilityOptions[localAvailabilityLevel]?.technical || "", [availabilityOptions, localAvailabilityLevel] ); return ( <div className={`${compact ? 'space-y-3' : 'space-y-5'} ${disabled ? 'opacity-70' : ''}`} data-testid={testId} > <div className={`mb-5 pb-4 border-b border-gray-100 dark:border-gray-700`} data-testid="confidentiality-section" > <Selection id="confidentialitySelect" label={CIA_LABELS.CONFIDENTIALITY} icon={CIA_COMPONENT_ICONS.CONFIDENTIALITY} description="Controls who can access your data and systems" options={confidentialitySelectOptions} value={localConfidentialityLevel} onChange={handleConfidentialityChange} iconClassName="text-purple-600 dark:text-purple-400" labelClassName="terminal-text text-purple-600 dark:text-purple-400" infoContent={confidentialityInfo} contextInfo={confidentialityOptions[localConfidentialityLevel]?.description || ""} disabled={disabled} aria-label="Select confidentiality level" data-testid="confidentiality-select" /> </div> <div className={`mb-5 pb-4 border-b border-gray-100 dark:border-gray-700`} data-testid="integrity-section" > <Selection id="integritySelect" label={CIA_LABELS.INTEGRITY} icon={CIA_COMPONENT_ICONS.INTEGRITY} description="Ensures data remains accurate and unaltered" options={integritySelectOptions} value={localIntegrityLevel} onChange={handleIntegrityChange} iconClassName="text-green-600 dark:text-green-400" labelClassName="terminal-text text-green-600 dark:text-green-400" infoContent={integrityInfo} contextInfo={integrityOptions[localIntegrityLevel]?.description || ""} disabled={disabled} aria-label="Select integrity level" data-testid="integrity-select" /> </div> <div className={`mb-2`} data-testid="availability-section" > <Selection id="availabilitySelect" label={CIA_LABELS.AVAILABILITY} icon={CIA_COMPONENT_ICONS.AVAILABILITY} description="Determines how reliably your systems can be accessed" options={availabilitySelectOptions} value={localAvailabilityLevel} onChange={handleAvailabilityChange} iconClassName="text-blue-600 dark:text-blue-400" labelClassName="terminal-text text-blue-600 dark:text-blue-400" infoContent={availabilityInfo} contextInfo={availabilityOptions[localAvailabilityLevel]?.description || ""} disabled={disabled} aria-label="Select availability level" data-testid="availability-select" /> </div> </div> ); }; export default SecurityLevelSelector; |