Skip to content

Commit

Permalink
Adjustments to threat detail modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Jan 24, 2025
1 parent a9f9a7e commit b8fed04
Show file tree
Hide file tree
Showing 45 changed files with 1,718 additions and 1,326 deletions.
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/js-packages/components/components/badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from './style.module.scss';
type BadgeProps = {
children?: React.ReactNode;
className?: string;
variant?: 'success' | 'warning' | 'danger';
variant?: 'info' | 'success' | 'warning' | 'danger';
[ key: string ]: unknown;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export default function ShieldIcon( {
contrast?: string;
fill?: 'default' | 'info' | 'success' | 'warning' | 'error' | string;
height?: number;
icon?: 'success' | 'error';
icon?: 'success' | 'error' | 'warning';
outline?: boolean;
variant: 'default' | 'info' | 'success' | 'warning' | 'error';
variant?: 'default' | 'info' | 'success' | 'warning' | 'error';
} ): JSX.Element {
const shieldFill = COLORS[ fill ] || fill || COLORS[ variant ];
const iconFill = outline ? shieldFill : contrast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,41 @@ import {
getFixerState,
getFixerAction,
getFixerDescription,
ThreatsContext,
} from '@automattic/jetpack-scan';
import { Tooltip } from '@wordpress/components';
import { useCallback, useMemo } from '@wordpress/element';
import { useCallback, useContext, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button } from '@automattic/jetpack-components';
import styles from './styles.module.scss';

/**
* Threat Fixer Button component.
*
* @param {object} props - Component props.
* @param {object} props.threat - The threat.
* @param {Function} props.onClick - The onClick function.
* @param {string} props.className - The className.
* @param {object} props - Component props.
* @param {object} props.threat - The threat.
* @param {Function} props.onClick - The onClick function.
* @param {boolean} props.showToolTip - Whether to show a tooltip on button hover.
* @param {string} props.className - The className.
*
* @return {JSX.Element} The component.
*/
export default function ThreatFixerButton( {
threat,
className,
onClick,
showToolTip = true,
...buttonProps
}: {
threat: Threat;
onClick: ( items: Threat[] ) => void;
className?: string;
} ): JSX.Element {
const fixerState = useMemo( () => {
return getFixerState( threat.fixer );
}, [ threat.fixer ] );
showToolTip?: boolean;
} & React.ComponentProps< typeof Button > ): JSX.Element {
const { fixersStatus } = useContext( ThreatsContext );

const fixer = fixersStatus.ok && fixersStatus.threats?.[ threat.id ];
const fixerState = getFixerState( fixer );

const tooltipText = useMemo( () => {
if ( ! threat.fixable ) {
Expand Down Expand Up @@ -79,7 +85,7 @@ export default function ThreatFixerButton( {

return (
<div>
<Tooltip className={ styles.tooltip } text={ tooltipText }>
<Tooltip className={ styles.tooltip } text={ showToolTip ? tooltipText : undefined }>
<Button
size="small"
weight="regular"
Expand All @@ -94,6 +100,7 @@ export default function ThreatFixerButton( {
fixerState.stale
}
style={ { minWidth: '72px' } }
{ ...buttonProps }
/>
</Tooltip>
</div>
Expand Down
Loading

0 comments on commit b8fed04

Please sign in to comment.