Skip to content

Commit

Permalink
Protect: Fix in-progress fixer indicator (#38051)
Browse files Browse the repository at this point in the history
* Add logging to detect fixer status

* changelog

* Disable eslint for testing

* Remove logging

* Fix redux setup for threatsAreFixing, add disables for ignore and fix button when true

* Update variable names

* Update changelog type and update versions
  • Loading branch information
dkmyta authored Jun 26, 2024
1 parent b31b1b6 commit f387426
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Ensure in-progress fixer indicator is functional
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Text, Button, useBreakpointMatch } from '@automattic/jetpack-components';
import { useDispatch } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { createInterpolateElement } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import React, { useCallback } from 'react';
Expand All @@ -26,10 +26,12 @@ const ThreatAccordionItem = ( {
type,
severity,
} ) => {
const threatsAreFixing = useSelect( select => select( STORE_ID ).getThreatsAreFixing() );
const { setModal } = useDispatch( STORE_ID );

const { recordEvent } = useAnalyticsTracks();

const fixerInProgress = threatsAreFixing.indexOf( id ) >= 0;

const learnMoreButton = source ? (
<Button variant="link" isExternalLink={ true } weight="regular" href={ source }>
{ __( 'See more technical details of this threat', 'jetpack-protect' ) }
Expand Down Expand Up @@ -113,11 +115,16 @@ const ThreatAccordionItem = ( {
) }
{ ! description && <div className={ styles[ 'threat-section' ] }>{ learnMoreButton }</div> }
<div className={ styles[ 'threat-footer' ] }>
<Button isDestructive={ true } variant="secondary" onClick={ handleIgnoreThreatClick() }>
<Button
isDestructive={ true }
variant="secondary"
disabled={ fixerInProgress }
onClick={ handleIgnoreThreatClick() }
>
{ __( 'Ignore threat', 'jetpack-protect' ) }
</Button>
{ fixable && (
<Button onClick={ handleFixThreatClick() }>
<Button disabled={ fixerInProgress } onClick={ handleFixThreatClick() }>
{ __( 'Fix threat', 'jetpack-protect' ) }
</Button>
) }
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/protect/src/js/state/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const threatsUpdating = ( state = {}, action ) => {
return state;
};

const setThreatsFixing = ( state = [], action ) => {
const threatsAreFixing = ( state = [], action ) => {
switch ( action.type ) {
case SET_THREATS_ARE_FIXING:
return action.threatIds;
Expand Down Expand Up @@ -207,7 +207,7 @@ const reducers = combineReducers( {
threatsUpdating,
modal,
notice,
setThreatsFixing,
threatsAreFixing,
hasRequiredPlan,
onboardingProgress,
waf,
Expand Down

0 comments on commit f387426

Please sign in to comment.