Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect: Update fixer UI to handle long running fixers #39301

Merged
merged 97 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
cfe4e3b
Protect: React Query
nateweller Aug 20, 2024
07f4237
Add fixerStatus to initial state
dkmyta Aug 28, 2024
c3de3f7
changelog
dkmyta Aug 28, 2024
d4b71ee
Fix in_progress fixer state
dkmyta Aug 28, 2024
9758e3b
Fix tests
dkmyta Aug 28, 2024
ba489fe
Fix fixThreats apiFetch call
dkmyta Aug 28, 2024
a392ec1
Do not camelize fixerStatus in useFixersQuery initialData
dkmyta Aug 28, 2024
b510e1e
Protect: React Query
nateweller Aug 20, 2024
49fda28
Merge base
dkmyta Aug 28, 2024
3695e1a
Use fixableThreats prop from scan status
dkmyta Aug 28, 2024
4eac461
Protect: React Query
nateweller Aug 20, 2024
d5a02c8
Protect: React Query
nateweller Aug 20, 2024
25b5a39
Merge base
dkmyta Aug 28, 2024
29bfbd3
Merge base
dkmyta Aug 28, 2024
26c3d28
Fix merge errors
dkmyta Aug 28, 2024
a054033
Ensure fixer status polling occurs when in_progress fixers exist
dkmyta Aug 28, 2024
3501471
Protect: React Query
nateweller Aug 20, 2024
06ce482
Merge base
dkmyta Aug 28, 2024
6ca566f
Invalidate scan status query on fixer status query success
dkmyta Aug 28, 2024
a36715f
Protect: React Query
nateweller Aug 20, 2024
1e71db5
Merge base
dkmyta Aug 28, 2024
3e4e594
Provide useFixersQuery threatIds default value
dkmyta Aug 28, 2024
78f9445
Protect: React Query
nateweller Aug 20, 2024
6dbd810
Merge base
dkmyta Aug 29, 2024
423d69f
Reorder
dkmyta Aug 29, 2024
a66ea68
Account for fixerStatus being false in useFixers hook
dkmyta Aug 29, 2024
517e486
Protect: React Query
nateweller Aug 20, 2024
ab98802
Temporarily disable optimistically setting fixer status
dkmyta Aug 29, 2024
d4a3275
Merge base
dkmyta Aug 29, 2024
4ac4cb7
Protect: React Query
nateweller Aug 20, 2024
d96c395
Fix conflicts
dkmyta Aug 29, 2024
7008ddf
Simplify QUERY_FIXERS_KEY, and update setQueryData return formatting
dkmyta Aug 29, 2024
696be85
Fixes and improvements
dkmyta Aug 29, 2024
9a9d7c8
Protect: React Query
nateweller Aug 20, 2024
13fa583
Rebase, fix conflicts
dkmyta Aug 30, 2024
80be81a
Update fixerInProgress logic
dkmyta Aug 30, 2024
59accac
Conflict corrections
dkmyta Aug 30, 2024
17a4927
Fix fixInProgressThreatIds logic
dkmyta Aug 30, 2024
0aa61cd
Fix fixable_threat_ids type
dkmyta Aug 30, 2024
774d5a5
Update property name
dkmyta Aug 30, 2024
09cb682
Fix useFixersQuery cachedData check logic
dkmyta Aug 30, 2024
0f9c56b
Protect: React Query
nateweller Aug 20, 2024
cc09189
Merge base, fix conflicts
dkmyta Aug 30, 2024
ca111cf
Protect: React Query
nateweller Aug 20, 2024
030c5e0
Fix conflicts
dkmyta Aug 31, 2024
160323a
Protect: React Query
nateweller Aug 20, 2024
20cf5d8
Merge base, fix conflicts
dkmyta Sep 3, 2024
3e9a641
Handle fixer status optimistically
dkmyta Sep 3, 2024
bbc404b
Add removed comment
dkmyta Sep 3, 2024
63ed7b3
Remove file
dkmyta Sep 3, 2024
eba64a8
Fix types
dkmyta Sep 3, 2024
f958d78
Fix docblocks
dkmyta Sep 4, 2024
a098021
Revert unintended changes
dkmyta Sep 5, 2024
a294482
Protect: React Query
nateweller Aug 20, 2024
da226ee
Merge base, fix conflicts
dkmyta Sep 6, 2024
ee9f0d5
Merge trunk
dkmyta Sep 9, 2024
118821a
changelog
dkmyta Sep 9, 2024
a82f79a
Handle long running fixers
dkmyta Sep 9, 2024
c44e4be
Improve setting fixer status optimistically
dkmyta Sep 9, 2024
7992a92
Handle possible API returns
dkmyta Sep 9, 2024
3f11a04
Merge base, fix conflicts
dkmyta Sep 9, 2024
708dff0
Handle statuses for nonexistent fixers
dkmyta Sep 10, 2024
f2ec84a
Filter fixable threats list for fix all threats modal
dkmyta Sep 10, 2024
cd8f814
Fixes and improvements to existing code
dkmyta Sep 10, 2024
3a26f7a
Disable threat actions when fixer is stale
dkmyta Sep 10, 2024
d29f8e6
Merge branch 'trunk' into add/protect-fixer-status-to-initial-state
dkmyta Sep 10, 2024
7b8f9ac
Merge branch 'add/protect-fixer-status-to-initial-state' into update/…
dkmyta Sep 10, 2024
3ea6bc9
Changelog entry
dkmyta Sep 10, 2024
593d1cb
Revert fixers mutation update
dkmyta Sep 11, 2024
77c1d50
Improve use fixers query error handling
dkmyta Sep 11, 2024
2e5be46
Update notice message
dkmyta Sep 11, 2024
4465ec7
Merge base, fix conflicts
dkmyta Sep 11, 2024
12df4fe
Readd removed comment
dkmyta Sep 11, 2024
f10dbeb
Merge branch 'add/protect-fixer-status-to-initial-state' into update/…
dkmyta Sep 11, 2024
843e039
Fix naming
dkmyta Sep 11, 2024
5b4bd22
Merge branch 'trunk' into add/protect-fixer-status-to-initial-state
dkmyta Sep 11, 2024
4997ef6
Merge branch 'add/protect-fixer-status-to-initial-state' into update/…
dkmyta Sep 11, 2024
6ad1341
Update initial state default
dkmyta Sep 12, 2024
9ec082c
Update initial state default
dkmyta Sep 12, 2024
c0b098c
Ensure FixerStatus type matches response structure
dkmyta Sep 12, 2024
3693fd0
Fix typo
dkmyta Sep 12, 2024
0e6549f
Fix logic - fixer cannot be active and stale
dkmyta Sep 12, 2024
a41d994
Improvements
dkmyta Sep 12, 2024
3123e52
Improve useFixersQuery
dkmyta Sep 12, 2024
aac8e33
Add comments
dkmyta Sep 12, 2024
a9ddd99
Merge branch 'trunk' into add/protect-fixer-status-to-initial-state
dkmyta Sep 12, 2024
02d5c32
Merge base, fix conflicts
dkmyta Sep 12, 2024
f74f645
Apply dummy arg to avoid bad minification issues
dkmyta Sep 12, 2024
06928d3
Merge remote-tracking branch 'origin/trunk' into update/protect-fixer…
nateweller Sep 16, 2024
dbbe4a9
Use clsx for conditional class names
nateweller Sep 16, 2024
bf25e5b
Use memoized value for fixableList
nateweller Sep 16, 2024
7b18e5c
Remove memoization of date
nateweller Sep 16, 2024
6d3298d
Remove memoization of initial query data from window
nateweller Sep 16, 2024
cdff7fd
Centralize fixer logic and attempt to simplify the hook implementation
nateweller Sep 16, 2024
5c14dab
Merge remote-tracking branch 'origin/trunk' into update/protect-fixer…
nateweller Sep 17, 2024
060f17e
Fix syntax errors
nateweller Sep 17, 2024
9474763
Move stale fixer check to top of renderFixerStatus logic
dkmyta Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds handling for long running fixers
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
Button,
Status,
} from '@automattic/jetpack-components';
import { Spinner, Popover } from '@wordpress/components';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Icon, help } from '@wordpress/icons';
import React, { useState, useCallback } from 'react';
import { help } from '@wordpress/icons';
import React, { useCallback } from 'react';
import useAnalyticsTracks from '../../hooks/use-analytics-tracks';
import usePlan from '../../hooks/use-plan';
import useWafData from '../../hooks/use-waf-data';
import IconTooltip from '../icon-tooltip';
import styles from './styles.module.scss';

const UpgradePrompt = () => {
Expand Down Expand Up @@ -44,51 +45,21 @@ const UpgradePrompt = () => {
);
};

const FirewallSubheadingPopover = ( {
children = __(
'The free version of the firewall does not receive updates to automatic security rules.',
'jetpack-protect'
),
} ) => {
const [ showPopover, setShowPopover ] = useState( false );

const handleEnter = useCallback( () => {
setShowPopover( true );
}, [] );

const handleOut = useCallback( () => {
setShowPopover( false );
}, [] );

return (
<div
className={ styles[ 'icon-popover' ] }
onMouseLeave={ handleOut }
onMouseEnter={ handleEnter }
onClick={ handleEnter }
onFocus={ handleEnter }
onBlur={ handleOut }
role="presentation"
>
<Icon icon={ help } />
{ showPopover && (
<Popover noArrow={ false } offset={ 5 } inline={ true }>
<Text className={ styles[ 'popover-text' ] } variant={ 'body-small' }>
{ children }
</Text>
</Popover>
) }
</div>
);
};

const FirewallSubheadingContent = ( { className, text = '', popover = false, children } ) => {
const FirewallSubheadingContent = ( { className, text = '', popover = false } ) => {
return (
<div className={ styles[ 'firewall-subheading__content' ] }>
<Text className={ styles[ className ] } weight={ 600 }>
{ text }
</Text>
{ popover && <FirewallSubheadingPopover children={ children } /> }
{ popover && (
<IconTooltip
icon={ help }
text={ __(
'The free version of the firewall does not receive updates to automatic security rules.',
'jetpack-protect'
) }
/>
) }
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ svg.spinner {

&__content {
display: flex;

> .icon-popover {
display: flex;
margin-left: calc( var( --spacing-base ) / 2 ); // 4px
fill: var( --jp-gray-20 );
}
}
}

Expand All @@ -47,11 +41,6 @@ svg.spinner {
}
}

.popover-text {
width: 250px;
padding: calc( var( --spacing-base ) * 2 ); // 16px
}

.loading-text {
font-size: 18px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ const FixAllThreatsModal = ( { threatList = [] } ) => {

const [ threatIds, setThreatIds ] = useState( threatList.map( ( { id } ) => parseInt( id ) ) );

const handleCancelClick = useCallback( () => {
return event => {
const handleCancelClick = useCallback(
event => {
event.preventDefault();
setModal( { type: null } );
};
}, [ setModal ] );
},
[ setModal ]
);

const handleFixClick = useCallback( () => {
return async event => {
const handleFixClick = useCallback(
async event => {
event.preventDefault();

await fixThreats( threatIds );
setModal( { type: null } );
};
}, [ fixThreats, setModal, threatIds ] );
},
[ fixThreats, setModal, threatIds ]
);

const handleCheckboxClick = useCallback(
( checked, threat ) => {
Expand Down Expand Up @@ -63,12 +65,12 @@ const FixAllThreatsModal = ( { threatList = [] } ) => {
</div>

<div className={ styles.footer }>
<Button variant="secondary" onClick={ handleCancelClick() }>
<Button variant="secondary" onClick={ handleCancelClick }>
{ __( 'Cancel', 'jetpack-protect' ) }
</Button>
<Button
isLoading={ isFixersLoading }
onClick={ handleFixClick() }
onClick={ handleFixClick }
disabled={ ! threatIds.length }
>
{ __( 'Fix all threats', 'jetpack-protect' ) }
Expand Down
51 changes: 51 additions & 0 deletions projects/plugins/protect/src/js/components/icon-tooltip/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Text } from '@automattic/jetpack-components';
import { Icon, Popover } from '@wordpress/components';
import React, { useCallback, useState } from 'react';
import styles from './styles.module.scss';

const IconTooltip = ( { icon, iconClassName, iconSize, popoverPosition = 'top', text } ) => {
const [ showPopover, setShowPopover ] = useState( false );
const [ timeoutId, setTimeoutId ] = useState( null );

const handleEnter = useCallback( () => {
// Clear any existing timeout if user hovers back quickly
if ( timeoutId ) {
clearTimeout( timeoutId );
setTimeoutId( null );
}
setShowPopover( true );
}, [ timeoutId ] );

const handleOut = useCallback( () => {
// Set a timeout to delay the hiding of the popover
const id = setTimeout( () => {
setShowPopover( false );
setTimeoutId( null ); // Clear the timeout ID after the popover is hidden
}, 100 );

setTimeoutId( id );
}, [] );

return (
<div
className={ styles[ 'icon-popover' ] }
onMouseLeave={ handleOut }
onMouseEnter={ handleEnter }
onClick={ handleEnter }
onFocus={ handleEnter }
onBlur={ handleOut }
role="presentation"
>
<Icon className={ iconClassName } icon={ icon } size={ iconSize } />
{ showPopover && (
<Popover noArrow={ false } offset={ 5 } inline={ true } position={ popoverPosition }>
<Text className={ styles[ 'popover-text' ] } variant={ 'body-small' }>
{ text }
</Text>
</Popover>
) }
</div>
);
};

export default IconTooltip;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.icon-popover {
display: flex;
margin-left: calc( var( --spacing-base ) / 2 ); // 4px
fill: var( --jp-gray-20 );
}

.popover-text {
width: 250px;
padding: calc( var( --spacing-base ) * 2 ); // 16px
cursor: default;
}
Loading