Skip to content

Commit

Permalink
Use computed label over title
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Dec 20, 2024
1 parent 9177646 commit 289900f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getThreatType, type Threat, THREAT_ICONS } from '@automattic/jetpack-scan';
import { getLabel, getThreatType, type Threat, THREAT_ICONS } from '@automattic/jetpack-scan';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useContext, useState, useCallback, useMemo } from 'react';
Expand Down Expand Up @@ -56,7 +56,7 @@ const ThreatFixConfirmation = () => {
</div>
) }
<div className={ styles.bulk__title }>
<Text variant="title-small">{ threat.title }</Text>
<Text variant="title-small">{ getLabel( threat ) }</Text>
<ThreatFixDetails showTitle={ false } threat={ threat } />
</div>
</div>
Expand All @@ -74,7 +74,7 @@ const ThreatFixConfirmation = () => {
<div key={ threat.id } className={ styles.individual }>
<div className={ styles.individual__heading }>
<div className={ styles.individual__title }>
<Text variant="title-small">{ threat.title }</Text>
<Text variant="title-small">{ getLabel( threat ) }</Text>
{ !! threat.severity && <ThreatSeverityBadge severity={ threat.severity } /> }
</div>
<ThreatSummary threat={ threat } />
Expand Down
3 changes: 3 additions & 0 deletions projects/js-packages/scan/src/types/threats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ export type Threat = {

/** The affected extension. */
extension?: Extension;

/** The affected version */
version?: string;
};
19 changes: 18 additions & 1 deletion projects/js-packages/scan/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const getFixerDescription = ( threat: Threat ) => {
if ( threat.fixedIn && threat.extension?.name ) {
return sprintf(
/* translators: Translates to Updates to version. %1$s: Name. %2$s: Fixed version */
__( 'Update %1$s to version %2$s', 'jetpack-scan' ),
__( 'Update %1$s to version %2$s.', 'jetpack-scan' ),
threat.extension.name,
threat.fixedIn
);
Expand Down Expand Up @@ -187,3 +187,20 @@ export const getFixerDescription = ( threat: Threat ) => {
return __( 'Jetpack will auto-fix the threat.', 'jetpack-scan' );
}
};

export const getLabel = ( threat: Threat ) => {
if ( threat.signature === 'Vulnerable.WP.Core' ) {
// Core threat i.e. "WordPress (5.8)"
return `WordPress (${ threat.version })`;
}

if ( threat.extension?.name && threat.extension?.version ) {
// Extension threat i.e. "Woocommerce (3.0.0)"
return `${ threat.extension.name } (${ threat.extension.version })`;
}

if ( threat.filename ) {
// File threat i.e. "index.php"
return threat.filename.split( '/' ).pop();
}
};

0 comments on commit 289900f

Please sign in to comment.