Skip to content

Commit

Permalink
Components: Migrate ThreatSeverityBadge from Jetpack Protect (#39758)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller authored Oct 15, 2024
1 parent 54a0bb7 commit 9601737
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add ThreatSeverityBadge component
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const severityClassNames = severity => {

const severityText = severity => {
if ( severity >= 5 ) {
return _x( 'Critical', 'Severity label for issues rated 5 or higher.', 'jetpack-protect' );
return _x( 'Critical', 'Severity label for issues rated 5 or higher.', 'jetpack' );
} else if ( severity >= 3 && severity < 5 ) {
return _x( 'High', 'Severity label for issues rated between 3 and 5.', 'jetpack-protect' );
return _x( 'High', 'Severity label for issues rated between 3 and 5.', 'jetpack' );
}
return _x( 'Low', 'Severity label for issues rated below 3.', 'jetpack-protect' );
return _x( 'Low', 'Severity label for issues rated below 3.', 'jetpack' );
};

const ThreatSeverityBadge = ( { severity } ) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import ThreatSeverityBadge from '../index.jsx';
import ThreatSeverityBadge from '../index.js';

export default {
title: 'Plugins/Protect/Threat Severity Badge',
title: 'JS Packages/Components/Threat Severity Badge',
component: ThreatSeverityBadge,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { render, screen } from '@testing-library/react';
import ThreatSeverityBadge from '..';

describe( 'ThreatSeverityBadge', () => {
it( 'renders the correct severity label', () => {
render( <ThreatSeverityBadge severity={ 4 } /> );
expect( screen.getByText( 'High' ) ).toBeInTheDocument();
} );
} );
1 change: 1 addition & 0 deletions projects/js-packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export { default as CopyToClipboard } from './components/copy-to-clipboard';
export * from './components/icons';
export { default as SplitButton } from './components/split-button';
export { default as ThemeProvider } from './components/theme-provider';
export { default as ThreatSeverityBadge } from './components/threat-severity-badge';
export { default as Text, H2, H3, Title } from './components/text';
export { default as ToggleControl } from './components/toggle-control';
export { default as numberFormat } from './components/number-format';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Use component from package


Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Button, getRedirectUrl, Text } from '@automattic/jetpack-components';
import { Button, getRedirectUrl, Text, ThreatSeverityBadge } from '@automattic/jetpack-components';
import { createInterpolateElement, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import useIgnoreThreatMutation from '../../data/scan/use-ignore-threat-mutation';
import useModal from '../../hooks/use-modal';
import ThreatSeverityBadge from '../severity';
import UserConnectionGate from '../user-connection-gate';
import styles from './styles.module.scss';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Spinner, Text, useBreakpointMatch } from '@automattic/jetpack-components';
import {
Spinner,
Text,
ThreatSeverityBadge,
useBreakpointMatch,
} from '@automattic/jetpack-components';
import { ExternalLink } from '@wordpress/components';
import { dateI18n } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';
Expand All @@ -9,7 +14,6 @@ import React, { useState, useCallback, useContext, useMemo } from 'react';
import { PAID_PLUGIN_SUPPORT_URL } from '../../constants';
import useFixers from '../../hooks/use-fixers';
import IconTooltip from '../icon-tooltip';
import ThreatSeverityBadge from '../severity';
import styles from './styles.module.scss';

// Extract context provider for clarity and reusability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Text } from '@automattic/jetpack-components';
import { Text, ThreatSeverityBadge } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import React, { useState, useCallback } from 'react';
import ThreatSeverityBadge from '../severity';
import styles from './styles.module.scss';

//TODO: Move this to WPCom like we did the other messages?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Button, Text } from '@automattic/jetpack-components';
import { Button, Text, ThreatSeverityBadge } from '@automattic/jetpack-components';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useState } from 'react';
import useUnIgnoreThreatMutation from '../../data/scan/use-unignore-threat-mutation';
import useModal from '../../hooks/use-modal';
import ThreatSeverityBadge from '../severity';
import UserConnectionGate from '../user-connection-gate';
import styles from './styles.module.scss';

Expand Down

0 comments on commit 9601737

Please sign in to comment.