diff --git a/projects/js-packages/components/components/threats-data-views/fixer-status.tsx b/projects/js-packages/components/components/threats-data-views/fixer-status.tsx deleted file mode 100644 index 3e9f5b5dd1efe..0000000000000 --- a/projects/js-packages/components/components/threats-data-views/fixer-status.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import { type ThreatFixStatus } from '@automattic/jetpack-scan'; -import { ExternalLink, Spinner } from '@wordpress/components'; -import { createInterpolateElement } from '@wordpress/element'; -import { __, sprintf } from '@wordpress/i18n'; -import { Icon } from '@wordpress/icons'; -import { check } from '@wordpress/icons'; -import IconTooltip from '../icon-tooltip'; -import Text from '../text'; -import { PAID_PLUGIN_SUPPORT_URL } from './constants'; -import styles from './styles.module.scss'; -import { fixerStatusIsStale } from './utils'; - -/** - * InfoIconTooltip component. - * - * @param {object} props - Component props. - * @param {boolean} props.message - The popover message. - * @param {object} props.size - The size of the icon. - * - * @return {JSX.Elenment} The component. - */ -export function InfoIconTooltip( { - message, - size = 20, -}: { - message?: string; - size?: number; -} ): JSX.Element { - return ( - - - { createInterpolateElement( - sprintf( - /* translators: %s: Number of hide items */ - __( '%s Please try again or contact support.', 'jetpack' ), - message - ), - { - supportLink: ( - - ), - } - ) } - - - ); -} - -/** - * Fixer Status component. - * - * @param {object} props - Component props. - * @param {boolean} props.fixer - The fixer status. - * - * @return {JSX.Element} The component. - */ -export default function FixerStatusIcon( { fixer }: { fixer?: ThreatFixStatus } ): JSX.Element { - if ( fixer && fixerStatusIsStale( fixer ) ) { - return ( - - ); - } - - if ( fixer && 'error' in fixer && fixer.error ) { - return ( - - ); - } - - if ( fixer && 'status' in fixer && fixer.status === 'in_progress' ) { - return ( -
- -
- ); - } - - return ; -} - -/** - * FixerStatusText component. - * - * @param {object} props - Component props. - * @param {boolean} props.fixer - The fixer status. - * - * @return {JSX.Element} The component. - */ -function FixerStatusText( { fixer }: { fixer?: ThreatFixStatus } ): JSX.Element { - if ( fixer && fixerStatusIsStale( fixer ) ) { - return ( - - { __( 'Fixer is taking longer than expected', 'jetpack' ) } - - ); - } - - if ( fixer && 'error' in fixer && fixer.error ) { - return ( - - { __( 'An error occurred auto-fixing this threat', 'jetpack' ) } - - ); - } - - if ( fixer && 'status' in fixer && fixer.status === 'in_progress' ) { - return { __( 'Auto-fixing', 'jetpack' ) }; - } - - return { __( 'Auto-fixable', 'jetpack' ) }; -} - -/** - * FixerStatusBadge component. - * - * @param {object} props - Component props. - * @param {boolean} props.fixer - The fixer status. - * - * @return {string} The component. - */ -export function FixerStatusBadge( { fixer }: { fixer?: ThreatFixStatus } ): JSX.Element { - return ( -
- - -
- ); -} diff --git a/projects/js-packages/components/components/threats-data-views/index.tsx b/projects/js-packages/components/components/threats-data-views/index.tsx index bbfd6df36edbc..4081fdf475adb 100644 --- a/projects/js-packages/components/components/threats-data-views/index.tsx +++ b/projects/js-packages/components/components/threats-data-views/index.tsx @@ -1,4 +1,4 @@ -import { ThreatStatus, type Threat } from '@automattic/jetpack-scan'; +import { getThreatType, type Threat } from '@automattic/jetpack-scan'; import { __experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControlOption as ToggleGroupControlOption, // eslint-disable-line @wordpress/no-unsafe-wp-apis @@ -17,14 +17,14 @@ import { } from '@wordpress/dataviews'; import { dateI18n } from '@wordpress/date'; import { __, sprintf } from '@wordpress/i18n'; +import { code, color, grid, plugins, shield, wordpress } from '@wordpress/icons'; import { Icon } from '@wordpress/icons'; import { useCallback, useMemo, useState } from 'react'; import Badge from '../badge'; +import ThreatFixerButton from '../threat-fixer-button'; import ThreatSeverityBadge from '../threat-severity-badge'; import { THREAT_STATUSES, THREAT_TYPES } from './constants'; -import FixerStatusIcon, { FixerStatusBadge } from './fixer-status'; import styles from './styles.module.scss'; -import { getThreatIcon, getThreatSubtitle, getThreatType } from './utils'; /** * ToggleGroupControl component for filtering threats by status. diff --git a/projects/js-packages/components/components/threats-data-views/utils.ts b/projects/js-packages/components/components/threats-data-views/utils.ts deleted file mode 100644 index f8c3151ea35b4..0000000000000 --- a/projects/js-packages/components/components/threats-data-views/utils.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { type Threat, type ThreatFixStatus } from '@automattic/jetpack-scan'; -import { code, color, grid, plugins, shield, wordpress } from '@wordpress/icons'; - -export const getThreatIcon = ( threat: Threat ) => { - const type = getThreatType( threat ); - - switch ( type ) { - case 'plugin': - return plugins; - case 'theme': - return color; - case 'core': - return wordpress; - case 'file': - return code; - case 'database': - return grid; - default: - return shield; - } -}; - -export const getThreatType = ( threat: Threat ) => { - if ( threat.signature === 'Vulnerable.WP.Core' ) { - return 'core'; - } - if ( threat.extension ) { - return threat.extension.type; - } - if ( threat.filename ) { - return 'file'; - } - if ( threat.table ) { - return 'database'; - } - - return null; -}; - -export const getThreatSubtitle = ( threat: Threat ) => { - const type = getThreatType( threat ); - - switch ( type ) { - case 'plugin': - case 'theme': - return `${ threat.extension?.name } (${ threat.extension?.version })`; - case 'core': - return 'WordPress Core'; - case 'file': - // Trim leading slash - if ( threat.filename.startsWith( '/' ) ) { - return threat.filename.slice( 1 ); - } - return threat.filename; - case 'database': - return threat.table; - default: - return ''; - } -}; - -const FIXER_IS_STALE_THRESHOLD = 1000 * 60 * 60 * 24; // 24 hours - -export const fixerTimestampIsStale = ( lastUpdatedTimestamp: string ) => { - const now = new Date(); - const lastUpdated = new Date( lastUpdatedTimestamp ); - return now.getTime() - lastUpdated.getTime() >= FIXER_IS_STALE_THRESHOLD; -}; - -export const fixerStatusIsStale = ( fixerStatus: ThreatFixStatus ) => { - return ( - 'status' in fixerStatus && - fixerStatus.status === 'in_progress' && - fixerTimestampIsStale( fixerStatus.last_updated ) - ); -}; diff --git a/projects/js-packages/scan/src/types/fixers.d.ts b/projects/js-packages/scan/src/types/fixers.d.ts deleted file mode 100644 index 6ba9433122dbb..0000000000000 --- a/projects/js-packages/scan/src/types/fixers.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -export type FixerStatus = 'not_started' | 'in_progress' | 'fixed' | 'not_fixed'; - -/** - * Threat Fix Status - * - * Individual fixer status for a threat. - */ -export type ThreatFixStatusError = { - error: string; -}; - -export type ThreatFixStatusSuccess = { - status: FixerStatus; - last_updated: string; -}; - -export type ThreatFixStatus = ThreatFixStatusError | ThreatFixStatusSuccess; diff --git a/projects/js-packages/scan/src/types/threats.d.ts b/projects/js-packages/scan/src/types/threats.d.ts deleted file mode 100644 index be81934adf3ac..0000000000000 --- a/projects/js-packages/scan/src/types/threats.d.ts +++ /dev/null @@ -1,70 +0,0 @@ -export type ThreatStatus = 'fixed' | 'ignored' | 'current'; - -export type ThreatFixType = 'replace' | 'delete' | 'update' | string; - -export type Threat = { - /** The threat's unique ID. */ - id: string | number; - - /** The threat's signature. */ - signature: string; - - /** The threat's title. */ - title: string; - - /** The threat's description. */ - description: string; - - /** The threat's current status. */ - status: ThreatStatus; - - /** The threat's severity level (0-10). */ - severity: number; - - /** The date the threat was first detected on the site, in YYYY-MM-DDTHH:MM:SS.000Z format. */ - firstDetected: string; - - /** The version the threat is fixed in. */ - fixedIn?: string | null; - - /** The date the threat was fixed, in YYYY-MM-DDTHH:MM:SS.000Z format. */ - fixedOn?: string | null; - - /** The fixable details. */ - fixable: - | { - fixer: ThreatFixType; - target?: string | null; - extensionStatus?: string | null; - } - | false; - - /** The fixer status. */ - fixer: ThreatFixStatus; - - /** The threat's source. */ - source?: string; - - /** The threat's context. */ - context?: Record< string, unknown > | null; - - /** The name of the affected file. */ - filename: string | null; - - /** The rows affected by the database threat. */ - rows?: unknown; - - /** The table name of the database threat. */ - table?: string; - - /** The diff showing the threat's modified file contents. */ - diff?: string; - - /** The affected extension. */ - extension?: { - slug: string; - name: string; - version: string; - type: 'plugin' | 'theme' | 'core'; - }; -};