From 220d28cb0b9495aaee61afe8a15f0c50735fa25e Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Fri, 22 Nov 2024 09:39:12 -0700 Subject: [PATCH] Use custom button for threat details toggle (#40298) --- .../threat-modal/fixer-state-notice.tsx | 55 +++++++++++-------- .../threat-modal/styles.module.scss | 23 +++++--- .../threat-modal/threat-technical-details.tsx | 44 +++++++++------ 3 files changed, 76 insertions(+), 46 deletions(-) diff --git a/projects/js-packages/components/components/threat-modal/fixer-state-notice.tsx b/projects/js-packages/components/components/threat-modal/fixer-state-notice.tsx index 4ade6c4f2b829..4c8a8a5cb53db 100644 --- a/projects/js-packages/components/components/threat-modal/fixer-state-notice.tsx +++ b/projects/js-packages/components/components/threat-modal/fixer-state-notice.tsx @@ -1,4 +1,5 @@ import { __ } from '@wordpress/i18n'; +import { useMemo } from 'react'; import styles from './styles.module.scss'; import ThreatNotice from './threat-notice'; @@ -18,29 +19,39 @@ const FixerStateNotice = ( { }: { fixerState: { inProgress: boolean; error: boolean; stale: boolean }; } ) => { - let status: 'error' | 'success' | undefined; - let title: string | undefined; - let content: string | undefined; + const { status, title, content } = useMemo( () => { + if ( fixerState.error ) { + return { + status: 'error' as const, + title: __( 'An error occurred auto-fixing this threat', 'jetpack' ), + content: __( + 'Jetpack encountered a filesystem error while attempting to auto-fix this threat. Please try again later or contact support.', + 'jetpack' + ), + }; + } - if ( fixerState.error ) { - status = 'error'; - title = __( 'An error occurred auto-fixing this threat', 'jetpack' ); - content = __( - 'Jetpack encountered a filesystem error while attempting to auto-fix this threat. Please try again later or contact support.', - 'jetpack' - ); - } else if ( fixerState.stale ) { - status = 'error'; - title = __( 'The auto-fixer is taking longer than expected', 'jetpack' ); - content = __( - 'Jetpack has been attempting to auto-fix this threat for too long, and something may have gone wrong. Please try again later or contact support.', - 'jetpack' - ); - } else if ( fixerState.inProgress ) { - status = 'success'; - title = __( 'An auto-fixer is in progress', 'jetpack' ); - content = __( 'Please wait while Jetpack auto-fixes the threat.', 'jetpack' ); - } + if ( fixerState.stale ) { + return { + status: 'error' as const, + title: __( 'The auto-fixer is taking longer than expected', 'jetpack' ), + content: __( + 'Jetpack has been attempting to auto-fix this threat for too long, and something may have gone wrong. Please try again later or contact support.', + 'jetpack' + ), + }; + } + + if ( fixerState.inProgress ) { + return { + status: 'success' as const, + title: __( 'An auto-fixer is in progress', 'jetpack' ), + content: __( 'Please wait while Jetpack auto-fixes the threat.', 'jetpack' ), + }; + } + + return {}; + }, [ fixerState ] ); return title ? (
diff --git a/projects/js-packages/components/components/threat-modal/styles.module.scss b/projects/js-packages/components/components/threat-modal/styles.module.scss index 4850724be6212..874a2285a098d 100644 --- a/projects/js-packages/components/components/threat-modal/styles.module.scss +++ b/projects/js-packages/components/components/threat-modal/styles.module.scss @@ -14,15 +14,24 @@ justify-content: flex-start; align-items: center; } +} - &__closed { - max-height: 0; - overflow: hidden; - } +.section__toggle { + border: none; + background: none; + padding: 0; + font-size: 1rem; + font-weight: 600; + cursor: pointer; + display: flex; + gap: calc( var( --spacing-base ) / 2 ); // 4px + align-items: center; + transition: text-underline-offset 0.2s; - &__open { - max-height: fit-content; - overflow: hidden; + &:hover { + text-decoration: underline; + text-decoration-thickness: 2px; + text-underline-offset: calc( var( --spacing-base ) / 2 ); // 4px } } diff --git a/projects/js-packages/components/components/threat-modal/threat-technical-details.tsx b/projects/js-packages/components/components/threat-modal/threat-technical-details.tsx index bb52a38042c93..182bdd863e4b1 100644 --- a/projects/js-packages/components/components/threat-modal/threat-technical-details.tsx +++ b/projects/js-packages/components/components/threat-modal/threat-technical-details.tsx @@ -1,7 +1,7 @@ -import { Text, Button } from '@automattic/jetpack-components'; +import { Text } from '@automattic/jetpack-components'; import { Threat } from '@automattic/jetpack-scan'; import { __ } from '@wordpress/i18n'; -import { chevronDown, chevronUp } from '@wordpress/icons'; +import { chevronDown, chevronUp, Icon } from '@wordpress/icons'; import { useState, useCallback } from 'react'; import DiffViewer from '../diff-viewer'; import MarkedLines from '../marked-lines'; @@ -29,25 +29,35 @@ const ThreatTechnicalDetails = ( { threat }: { threat: Threat } ): JSX.Element = return (
- { __( 'The technical details', 'jetpack' ) } -
-
- { threat.filename && ( - <> - { __( 'Threat found in file:', 'jetpack' ) } -
{ threat.filename }
- - ) } - { threat.context && } - { threat.diff && } + > + + { open + ? __( 'Hide the technical details', 'jetpack' ) + : __( 'Show the technical details', 'jetpack' ) } + + +
+ { open && ( +
+ { threat.filename && ( + <> + { __( 'Threat found in file:', 'jetpack' ) } +
{ threat.filename }
+ + ) } + { threat.context && } + { threat.diff && } +
+ ) }
); };