-
Notifications
You must be signed in to change notification settings - Fork 800
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 card: Add the Scan/Threats status column (with tooltip) #38165
Merged
Merged
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
a16fe28
Protect card: Add the Last scan time (with tooltip) based on plugin s…
elliottprogrammer 85b9f14
Fix "Lern more" typo in comment, per feedback.
elliottprogrammer 751cdda
Add defaults to destructured var, per feedback.
elliottprogrammer 91fe0eb
Use React "FC" type, per feedback.
elliottprogrammer a40f71d
Fix snake case naming & state naming, per feedback.
elliottprogrammer e43589c
CSS style fixes/updates, per feedback.
elliottprogrammer 88ab09f
Show dynamic data in tooltips, per feedback; And cleanup/refactor.
elliottprogrammer 410b999
Close tooltip/popover when outside focus, per feedback.
elliottprogrammer 21df889
Fix tooltip close fires twice when tooltip focus switches to button c…
elliottprogrammer 9e9fb38
Fix responsiveness, per feedback.
elliottprogrammer 389b0fe
Only show "Last scan:" if value available, per feedback.
elliottprogrammer a207481
Merge branch 'trunk' into add/mj-protect-card-last-scan-time
elliottprogrammer 3203c4a
Add cursor: pointer to tooltip button, per feedback.
elliottprogrammer 831bf8a
Use --font-body-extra-small & fix comment typo, per feedback.
elliottprogrammer 35726a1
Only show "Plugins & Themes" when scan data availavle, per feedback.
elliottprogrammer 667b057
Fixup project versions.
elliottprogrammer db6d6be
Merge branch 'trunk' into add/mj-protect-card-last-scan-time
elliottprogrammer 994ea2e
Merge branch 'trunk' into add/mj-protect-card-last-scan-time
elliottprogrammer bab0c5a
Allow for singular/plural in translations.
elliottprogrammer 10e0b39
Move Popover into its own InfoTooltip component.
elliottprogrammer 4385062
Protect card: Add the Scan/Threats status column (with tooltip)
elliottprogrammer e4213b6
Critical threats, tooltip tracking, & additional styles.
elliottprogrammer c26a73e
Fix core.threats not iterable error.
elliottprogrammer 3a03548
Merge branch 'trunk' into add/mj-protect-card-last-scan-time
elliottprogrammer e00c6c6
Merge branch 'add/mj-protect-card-last-scan-time' into add/my-protect…
elliottprogrammer ab96aad
changelog.
elliottprogrammer 4df8c71
Scan status "Off" when site not connected.
elliottprogrammer 158ccaa
Remove unnecessary non-breaking space.
elliottprogrammer 95c92c7
Remove unnecessary icon width & height properties is scss.
elliottprogrammer c3e054a
Combine singular/plural translations into one translated string, per …
elliottprogrammer 162ccdf
Split up scan-threats into smaller components for readability, per fe…
elliottprogrammer 0e9d04c
Hide Protect card description, per feedback.
elliottprogrammer b38310c
Show "Upgrade" button & secondary "View" button when no paid plan.
elliottprogrammer 1855b08
Define Threat object in global.d.ts, per feedback.
elliottprogrammer 1010f7c
Add scss comment explaining specific letter-spacing, per feedback
elliottprogrammer 9f75120
scss, use --spacing-base where possible.
elliottprogrammer 386f824
Add comment about removing the <ProductCard /> Description, per feedb…
elliottprogrammer 60cbe2f
Split if condition into multiple lines, per feedback.
elliottprogrammer c5eb3db
Remove ternary & split into 2 returns instead, per feedback.
elliottprogrammer c6643cb
Merge branch 'trunk' into add/my-protect-card-scan-threats
elliottprogrammer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
projects/packages/my-jetpack/_inc/components/product-cards-section/protect-card.jsx
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...etpack/_inc/components/product-cards-section/protect-card/assets/shield-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
...ck/_inc/components/product-cards-section/protect-card/assets/shield-partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
...ck/_inc/components/product-cards-section/protect-card/assets/shield-success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions
50
projects/packages/my-jetpack/_inc/components/product-cards-section/protect-card/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useCallback, type FC } from 'react'; | ||
import useProduct from '../../../data/products/use-product'; | ||
import useAnalytics from '../../../hooks/use-analytics'; | ||
import ProductCard from '../../connected-product-card'; | ||
import ProtectValueSection from './protect-value-section'; | ||
|
||
const ProtectCard: FC< { admin: boolean } > = ( { admin } ) => { | ||
const { recordEvent } = useAnalytics(); | ||
const slug = 'protect'; | ||
const { detail } = useProduct( slug ); | ||
const { hasPaidPlanForProduct: hasProtectPaidPlan } = detail; | ||
|
||
/** | ||
* Called when secondary "View" button is clicked. | ||
*/ | ||
const onViewButtonClick = useCallback( () => { | ||
recordEvent( 'jetpack_myjetpack_product_card_manage_click', { | ||
product: slug, | ||
} ); | ||
}, [ recordEvent ] ); | ||
|
||
const shouldShowSecondaryButton = useCallback( | ||
() => ! hasProtectPaidPlan, | ||
[ hasProtectPaidPlan ] | ||
); | ||
|
||
const viewButton = { | ||
href: 'admin.php?page=jetpack-protect', | ||
label: __( 'View', 'jetpack-my-jetpack' ), | ||
onClick: onViewButtonClick, | ||
shouldShowButton: shouldShowSecondaryButton, | ||
}; | ||
|
||
const noDescription = useCallback( () => null, [] ); | ||
|
||
return ( | ||
<ProductCard | ||
admin={ admin } | ||
slug={ slug } | ||
upgradeInInterstitial={ true } | ||
secondaryAction={ viewButton } | ||
Description={ noDescription } | ||
> | ||
<ProtectValueSection /> | ||
</ProductCard> | ||
); | ||
}; | ||
|
||
export default ProtectCard; |
71 changes: 71 additions & 0 deletions
71
...ages/my-jetpack/_inc/components/product-cards-section/protect-card/info-tooltip/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Gridicon } from '@automattic/jetpack-components'; | ||
import { Popover } from '@wordpress/components'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { useState, useCallback, useRef } from 'react'; | ||
import useAnalytics from '../../../../hooks/use-analytics'; | ||
import type { FC, ReactNode } from 'react'; | ||
|
||
import './style.scss'; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
icon?: string; | ||
iconSize?: number; | ||
tracksEventName?: string; | ||
tracksEventProps?: { [ key: string ]: string | boolean | number }; | ||
}; | ||
|
||
export const InfoTooltip: FC< Props > = ( { | ||
children, | ||
icon = 'info-outline', | ||
iconSize = 14, | ||
tracksEventName, | ||
tracksEventProps = {}, | ||
} ) => { | ||
const { recordEvent } = useAnalytics(); | ||
const useTooltipRef = useRef< HTMLButtonElement >(); | ||
const isMobileViewport: boolean = useViewportMatch( 'medium', '<' ); | ||
const [ isPopoverVisible, setIsPopoverVisible ] = useState( false ); | ||
|
||
const toggleTooltip = useCallback( | ||
() => | ||
setIsPopoverVisible( prevState => { | ||
if ( ! prevState === true && tracksEventName ) { | ||
recordEvent( `jetpack_${ tracksEventName }`, { | ||
page: 'my-jetpack', | ||
feature: 'jetpack-protect', | ||
...tracksEventProps, | ||
} ); | ||
} | ||
return ! prevState; | ||
} ), | ||
[ recordEvent, tracksEventName, tracksEventProps ] | ||
); | ||
|
||
const hideTooltip = useCallback( () => { | ||
// Don't hide the tooltip here if it's the tooltip button that was clicked (the button | ||
// becoming the document's activeElement). Instead let toggleTooltip() handle the closing. | ||
if ( useTooltipRef.current && ! useTooltipRef.current.contains( document.activeElement ) ) { | ||
setIsPopoverVisible( false ); | ||
} | ||
}, [ setIsPopoverVisible, useTooltipRef ] ); | ||
|
||
return ( | ||
<span> | ||
<button className="info-tooltip__button" onClick={ toggleTooltip } ref={ useTooltipRef }> | ||
<Gridicon icon={ icon } size={ iconSize } /> | ||
</button> | ||
{ isPopoverVisible && ( | ||
<Popover | ||
placement={ isMobileViewport ? 'top-end' : 'right' } | ||
noArrow={ false } | ||
offset={ 10 } | ||
focusOnMount={ 'container' } | ||
onClose={ hideTooltip } | ||
> | ||
{ children } | ||
</Popover> | ||
) } | ||
</span> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...ges/my-jetpack/_inc/components/product-cards-section/protect-card/info-tooltip/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.info-tooltip__button { | ||
display: flex; | ||
align-items: center; | ||
background: transparent; | ||
border: none; | ||
color: var(--jp-gray-50); | ||
padding: 2px; | ||
cursor: pointer; | ||
svg { | ||
margin: 0 auto; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...s/my-jetpack/_inc/components/product-cards-section/protect-card/protect-value-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { __, _n, sprintf } from '@wordpress/i18n'; | ||
import { useMemo } from 'react'; | ||
import useProduct from '../../../data/products/use-product'; | ||
import { getMyJetpackWindowInitialState } from '../../../data/utils/get-my-jetpack-window-state'; | ||
import { timeSince } from '../../../utils/time-since'; | ||
import { InfoTooltip } from './info-tooltip'; | ||
import { ScanAndThreatStatus } from './scan-threats'; | ||
import { useProtectTooltipCopy } from './use-protect-tooltip-copy'; | ||
import type { TooltipContent } from './use-protect-tooltip-copy'; | ||
import type { FC } from 'react'; | ||
|
||
import './style.scss'; | ||
|
||
const ProtectValueSection = () => { | ||
const slug = 'protect'; | ||
const { detail } = useProduct( slug ); | ||
const { isPluginActive = false } = detail || {}; | ||
const { plugins, themes, scanData } = getMyJetpackWindowInitialState(); | ||
const { | ||
plugins: fromScanPlugins, | ||
themes: fromScanThemes, | ||
num_threats: numThreats = 0, | ||
last_checked: lastScanTime = null, | ||
} = scanData; | ||
|
||
const pluginsCount = fromScanPlugins.length || Object.keys( plugins ).length; | ||
const themesCount = fromScanThemes.length || Object.keys( themes ).length; | ||
|
||
const timeSinceLastScan = lastScanTime ? timeSince( Date.parse( lastScanTime ) ) : false; | ||
const lastScanText = useMemo( () => { | ||
if ( isPluginActive ) { | ||
if ( timeSinceLastScan ) { | ||
return sprintf( | ||
/* translators: %s is how long ago since the last scan took place, i.e.- "17 hours ago" */ | ||
__( 'Last scan: %s', 'jetpack-my-jetpack' ), | ||
timeSinceLastScan | ||
); | ||
} | ||
return null; | ||
} | ||
return ( | ||
sprintf( | ||
/* translators: %d is the number of plugins installed on the site. */ | ||
_n( '%d plugin', '%d plugins', pluginsCount, 'jetpack-my-jetpack' ), | ||
pluginsCount | ||
) + | ||
' ' + | ||
/* translators: The ampersand symbol here (&) is meaning "and". */ | ||
__( '&', 'jetpack-my-jetpack' ) + | ||
'\xa0' + // `\xa0` is a non-breaking space. | ||
sprintf( | ||
/* translators: %d is the number of themes installed on the site. */ | ||
_n( '%d theme', '%d themes', themesCount, 'jetpack-my-jetpack' ).replace( ' ', '\xa0' ), // `\xa0` is a non-breaking space. | ||
themesCount | ||
) | ||
); | ||
}, [ isPluginActive, timeSinceLastScan, pluginsCount, themesCount ] ); | ||
|
||
const tooltipContent = useProtectTooltipCopy( { pluginsCount, themesCount, numThreats } ); | ||
|
||
return ( | ||
<ValueSection | ||
isProtectActive={ isPluginActive } | ||
lastScanText={ lastScanText } | ||
tooltipContent={ tooltipContent } | ||
/> | ||
); | ||
}; | ||
|
||
export default ProtectValueSection; | ||
|
||
const ValueSection: FC< { | ||
isProtectActive: boolean; | ||
lastScanText?: string; | ||
tooltipContent: TooltipContent; | ||
} > = ( { isProtectActive, lastScanText, tooltipContent } ) => { | ||
const { pluginsThemesTooltip } = tooltipContent; | ||
|
||
return ( | ||
<> | ||
<div className="value-section__last-scan"> | ||
{ lastScanText && <div>{ lastScanText }</div> } | ||
{ ! isProtectActive && ( | ||
<InfoTooltip | ||
tracksEventName={ 'protect_card_tooltip_open' } | ||
tracksEventProps={ { | ||
location: 'plugins&themes', | ||
status: 'inactive', | ||
} } | ||
> | ||
<> | ||
<h3 className="value-section__tooltip-heading">{ pluginsThemesTooltip.title }</h3> | ||
<p className="value-section__tooltip-content">{ pluginsThemesTooltip.text }</p> | ||
elliottprogrammer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</> | ||
</InfoTooltip> | ||
) } | ||
</div> | ||
<div className="value-section"> | ||
<div className="value-section__scan-threats"> | ||
<ScanAndThreatStatus /> | ||
</div> | ||
<div className="value-section__auto-firewall"> | ||
<div className="value-section__heading">Auto-Firewall</div> | ||
<div></div> | ||
</div> | ||
<div className="value-section__logins-blocked"> | ||
<div className="value-section__heading">Logins Blocked</div> | ||
<div></div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can leave a comment for the future reference that if we gonna remove description to more cards, we should consider extending
<ProductCard />
functionality to support that.Clever workaround here though! 🙌