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: Integrate ScanReport #40420

Merged
merged 159 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
997e0b1
Init project branch
nateweller Nov 14, 2024
c6c82a9
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
fc04ac5
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
fb3582e
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
ad120a9
Add home tab, page and stat cards
dkmyta Nov 22, 2024
d210012
Fixes and improvements
dkmyta Nov 22, 2024
b07220c
Add Tooltips
dkmyta Nov 22, 2024
3613c64
Fix translations
dkmyta Nov 22, 2024
f95141c
Reorg
dkmyta Nov 22, 2024
88b0977
Fix typo
dkmyta Nov 22, 2024
7840094
Add errorMessage flag to StatCard, make WAF stats free
dkmyta Nov 26, 2024
0a5ba31
changelog
dkmyta Nov 26, 2024
0b17531
Add icon labels
dkmyta Nov 27, 2024
3ab4126
Remove error class
dkmyta Nov 27, 2024
1b12f91
Use ToggleControl
dkmyta Nov 27, 2024
b425656
Remove imports
dkmyta Nov 27, 2024
93295fe
Improve responsiveness of header and stat cards
dkmyta Nov 27, 2024
5ab6db3
Fix subheading text wrap
dkmyta Nov 27, 2024
c636037
Add StatCard error flag
dkmyta Nov 27, 2024
3c928b2
Fix WAF settings toggles
dkmyta Nov 27, 2024
4a870d1
Optimizations
dkmyta Nov 27, 2024
2eb89b4
Centralize localTimestamp
dkmyta Nov 27, 2024
621b15c
Add scanning card state
dkmyta Nov 27, 2024
b908e37
Fix styling
dkmyta Nov 27, 2024
95d2e1e
Update scanning card state
dkmyta Nov 28, 2024
fd712cc
Init project branch
nateweller Nov 14, 2024
01c637d
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
b0a9819
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
05bae76
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
b9a2980
Update scanning card tooltip
dkmyta Nov 29, 2024
b168a3d
Reorg
dkmyta Nov 29, 2024
a095354
Reorg, optimize
dkmyta Nov 29, 2024
401e50b
Rebase
dkmyta Nov 29, 2024
7b5e017
Remove count when feature disabled
dkmyta Nov 29, 2024
0b632bf
Optimize
dkmyta Nov 29, 2024
28c954d
Update messaging
dkmyta Nov 29, 2024
0d51b1a
Fix blocklist textarea
dkmyta Nov 29, 2024
0ea782e
Add dummy args for translations
dkmyta Nov 29, 2024
73df67d
Init project branch
nateweller Nov 14, 2024
70e3f03
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
b44b37a
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
7515dcb
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
5656dbe
Protect: add ShieldIcon component
nateweller Nov 30, 2024
22712db
Add ScanReport component
dkmyta Dec 2, 2024
274ada6
Add icons and tooltips
dkmyta Dec 2, 2024
4d20b9b
Add ShieldCheckIcon and ShieldAlertIcon
dkmyta Dec 2, 2024
35a9baf
Fix icons
dkmyta Dec 2, 2024
28636c8
Simplify
dkmyta Dec 2, 2024
9154ff7
changelog
dkmyta Dec 2, 2024
8b64c2b
Remove file type
dkmyta Dec 2, 2024
52c71e4
Add dedicated components for shield icons
dkmyta Dec 2, 2024
aa2cb4b
Merge branch 'components/add-scan-report' into update/protect/add-sca…
dkmyta Dec 2, 2024
554b037
Add ScanReport to Protect
dkmyta Dec 2, 2024
0c006ac
Update extension field
dkmyta Dec 2, 2024
0834d9f
Fix constants
dkmyta Dec 2, 2024
1d3ca0c
Match icons
dkmyta Dec 2, 2024
36ac533
Add files threats
dkmyta Dec 2, 2024
8d8bf24
Remove changelogs
dkmyta Dec 2, 2024
b299e52
Remove unintended additions
dkmyta Dec 2, 2024
c521812
Merge branch 'trunk' into add/protect/core
dkmyta Dec 2, 2024
7c20ea9
Rebase
dkmyta Dec 2, 2024
bbd97bb
Rebase
dkmyta Dec 2, 2024
ee3289f
Revert prior commit
dkmyta Dec 2, 2024
58bef98
Revert "Remove changelogs"
dkmyta Dec 2, 2024
8849fe4
Remove changelogs
dkmyta Dec 2, 2024
a3cbe99
Fix file icon in list view
dkmyta Dec 2, 2024
b85f4c8
Add file threat signature for version
dkmyta Dec 2, 2024
bc0ca43
Add changelog
dkmyta Dec 2, 2024
44e3336
Merge branch 'add/protect/home' into update/protect/add-scan-report-t…
dkmyta Dec 2, 2024
dafa629
Fix text domains
dkmyta Dec 2, 2024
f1e2a9b
Changelog
dkmyta Dec 2, 2024
2dde812
Optimize, simplify
dkmyta Dec 3, 2024
412568d
Add dummy arg to fix build errors
dkmyta Dec 3, 2024
cffb72b
Merge branch 'add/protect/home' into update/protect/add-scan-report-t…
dkmyta Dec 3, 2024
5700f54
Remove unintentionally added import
dkmyta Dec 3, 2024
9a1fd3e
Set unique ID first
dkmyta Dec 3, 2024
a4c84f2
Update scan card title when scanning
dkmyta Dec 3, 2024
ac24f95
Update scan card title when scanning
dkmyta Dec 3, 2024
e192194
Add and use shared icons
dkmyta Dec 3, 2024
69e52eb
Rebase
dkmyta Dec 3, 2024
5adbf1b
Fix build issues
dkmyta Dec 3, 2024
25bdb1f
Fix build issues
dkmyta Dec 3, 2024
3fa3538
Fix dummy arg placement
dkmyta Dec 3, 2024
5a4b60e
Fix dummy arg placement
dkmyta Dec 3, 2024
809484e
Use dynamic ShieldIcon
dkmyta Dec 4, 2024
5ece8cf
Fix variants
dkmyta Dec 4, 2024
fac6ce1
Update Protect shield icon uses to use package versions
dkmyta Dec 4, 2024
ee3bc6e
Add info variant
dkmyta Dec 5, 2024
3a17f97
Init project branch
nateweller Nov 14, 2024
f4820b9
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
a240e20
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
b9bfed3
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
f02081f
Protect: add ShieldIcon component
nateweller Nov 30, 2024
6c73d5a
Protect: Add ShieldIcon Component (#40402)
nateweller Dec 5, 2024
1118627
Protect: Integrate ThreatsDataViews Component (#40076)
nateweller Dec 5, 2024
5ba7582
Components: Add ScanReport (#40419)
dkmyta Dec 5, 2024
638dd26
Rebase, fix conflicts
dkmyta Dec 5, 2024
f7115cb
Update changelog
dkmyta Dec 5, 2024
10c278e
Rebase, fix conflicts
dkmyta Dec 5, 2024
0021ecf
Update status label
dkmyta Dec 5, 2024
8e06701
Use status query
dkmyta Dec 5, 2024
4fb5f6a
Remove files default
dkmyta Dec 5, 2024
7dda24c
Fix scanning header alignment
dkmyta Dec 5, 2024
d7fcc29
Redirect to scan page after checkout
dkmyta Dec 5, 2024
9e3fa27
Update card text to push all messages to two lines
dkmyta Dec 5, 2024
831b376
Update scanning card message
dkmyta Dec 6, 2024
68976b7
Fixes and improvements
dkmyta Dec 6, 2024
a4825e4
Reorg
dkmyta Dec 6, 2024
1889685
Rebase
dkmyta Dec 6, 2024
46c808b
Sort list by status
dkmyta Dec 6, 2024
2193ed5
Remove default sorting in favour of filter use
dkmyta Dec 6, 2024
b2e59af
Update tooltips to use conditional content
dkmyta Dec 6, 2024
30c43dc
Don't use ternaries for translations in components to avoid build issues
dkmyta Dec 6, 2024
420e1ec
Init project branch
nateweller Nov 14, 2024
49cf36c
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
bdb1df4
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
2362d8f
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
28f4d2e
Protect: add ShieldIcon component
nateweller Nov 30, 2024
db7998d
Protect: Add ShieldIcon Component (#40402)
nateweller Dec 5, 2024
2d1181a
Protect: Integrate ThreatsDataViews Component (#40076)
nateweller Dec 5, 2024
57eda8f
Components: Add ScanReport (#40419)
dkmyta Dec 5, 2024
a4ebd3e
Fix type errors
nateweller Dec 6, 2024
46ebdaa
Protect: add home page
Dec 7, 2024
4dd60b7
Init project branch
nateweller Nov 14, 2024
ff92d88
Protect: Add Go to Cloud and Scan now button to Protect primary heade…
dkmyta Nov 14, 2024
39e4094
Protect: Update Scan and History headers (#40058)
dkmyta Nov 14, 2024
9fec011
Protect: de-emphasize cloud link by using link variant (#40211)
nateweller Nov 18, 2024
af172c9
Protect: add ShieldIcon component
nateweller Nov 30, 2024
00283bc
Protect: Add ShieldIcon Component (#40402)
nateweller Dec 5, 2024
f580ace
Protect: Integrate ThreatsDataViews Component (#40076)
nateweller Dec 5, 2024
c384d69
Components: Add ScanReport (#40419)
dkmyta Dec 5, 2024
68569f2
Fix type errors
nateweller Dec 6, 2024
ae3af3b
Init project branch
nateweller Nov 14, 2024
4b2a5d4
Protect: Add ShieldIcon Component (#40402)
nateweller Dec 5, 2024
cd16668
Refactor AdminSectionHero component
nateweller Dec 8, 2024
4c8f590
Rebase
dkmyta Dec 9, 2024
a84ee42
Rebase on admin hero section refactor
dkmyta Dec 9, 2024
24e7118
Revert accidental type changes
dkmyta Dec 9, 2024
ea745ca
Remove testing code
dkmyta Dec 9, 2024
0158632
Use custom class name for status spacing style
nateweller Dec 9, 2024
a0d303d
Avoid translated string concat
nateweller Dec 9, 2024
758cd89
Rebase, fix conflicts
dkmyta Dec 9, 2024
06550f1
Fix concatenating string translations
dkmyta Dec 9, 2024
03dd6b3
Use _n for threat/threats vulnerability/vulnerabilities in header
nateweller Dec 9, 2024
6aefc2e
Rebase
dkmyta Dec 9, 2024
26ce0a5
Rebase
dkmyta Dec 9, 2024
d3774c7
Fix FirewallSubheading console errors
dkmyta Dec 9, 2024
ceaaecc
Add hasPlan prop for string creation checks
dkmyta Dec 9, 2024
62dff2e
Don't use ternaries for translation strings
dkmyta Dec 9, 2024
325cc97
Rebase
dkmyta Dec 10, 2024
3af206a
Remove extra changelog
dkmyta Dec 10, 2024
649f57c
Reapply changelog
dkmyta Dec 10, 2024
d948ca9
Add unknown to threat types constant
dkmyta Dec 10, 2024
d5ad640
Fix
dkmyta Dec 10, 2024
f3f96f5
Use dataSource over hasPlan
dkmyta Dec 10, 2024
a30c28d
Use _n for plural translations
dkmyta Dec 10, 2024
a3b2541
Add dummy arg for translation to fix build errors
dkmyta Dec 10, 2024
de776fa
Disable version sorting
dkmyta Dec 11, 2024
113a25b
Update HomePage container styling to match ScanPage
dkmyta Dec 11, 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
Expand Up @@ -7,6 +7,12 @@ import {
wordpress as coreIcon,
} from '@wordpress/icons';

export const STATUS_TYPES = [
{ value: 'checked', label: __( 'Checked', 'jetpack-components' ) },
{ value: 'unchecked', label: __( 'Unchecked', 'jetpack-components' ) },
{ value: 'threat', label: __( 'Threat', 'jetpack-components' ) },
];

export const TYPES = [
{ value: 'core', label: __( 'WordPress', 'jetpack-components' ) },
{ value: 'plugins', label: __( 'Plugin', 'jetpack-components' ) },
Expand Down
47 changes: 42 additions & 5 deletions projects/js-packages/components/components/scan-report/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DataViews,
filterSortAndPaginate,
} from '@wordpress/dataviews';
import { __ } from '@wordpress/i18n';
import { __, _n } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useCallback, useMemo, useState } from 'react';
import ShieldIcon from '../shield-icon';
Expand All @@ -17,6 +17,7 @@ import {
FIELD_ICON,
FIELD_STATUS,
FIELD_TYPE,
STATUS_TYPES,
TYPES,
ICONS,
} from './constants';
Expand All @@ -26,12 +27,13 @@ import styles from './styles.module.scss';
* DataViews component for displaying a scan report.
*
* @param {object} props - Component props.
* @param {string} props.dataSource - Data source.
* @param {Array} props.data - Scan report data.
* @param {Function} props.onChangeSelection - Callback function run when an item is selected.
*
* @return {JSX.Element} The ScanReport component.
*/
export default function ScanReport( { data, onChangeSelection } ): JSX.Element {
export default function ScanReport( { dataSource, data, onChangeSelection } ): JSX.Element {
const baseView = {
search: '',
filters: [],
Expand Down Expand Up @@ -84,8 +86,19 @@ export default function ScanReport( { data, onChangeSelection } ): JSX.Element {
const result: Field< ScanReportExtension >[] = [
{
id: FIELD_STATUS,
elements: STATUS_TYPES,
label: __( 'Status', 'jetpack-components' ),
getValue( { item } ) {
if ( item.checked ) {
if ( item.threats.length > 0 ) {
return 'threat';
}
return 'checked';
}
return 'unchecked';
},
render( { item }: { item: ScanReportExtension } ) {
const scanApi = 'scan_api' === dataSource;
let variant: 'info' | 'warning' | 'success' = 'info';
let text = __(
'This item was added to your site after the most recent scan. We will check for threats during the next scheduled one.',
Expand All @@ -95,10 +108,34 @@ export default function ScanReport( { data, onChangeSelection } ): JSX.Element {
if ( item.checked ) {
if ( item.threats.length > 0 ) {
variant = 'warning';
text = __( 'Threat detected.', 'jetpack-components' );
text = _n(
'Vulnerability detected.',
'Vulnerabilities detected.',
item.threats.length,
'jetpack-components'
);

if ( scanApi ) {
text = _n(
'Threat detected.',
'Threats detected.',
item.threats.length,
'jetpack-components'
);
}
} else {
variant = 'success';
text = __( 'No known threats found that affect this version.', 'jetpack-components' );
text = __(
'No known vulnerabilities found that affect this version.',
'jetpack-components'
);

if ( scanApi ) {
text = __(
'No known threats found that affect this version.',
'jetpack-components'
);
}
}
}

Expand Down Expand Up @@ -155,7 +192,7 @@ export default function ScanReport( { data, onChangeSelection } ): JSX.Element {
];

return result;
}, [ view ] );
}, [ view, dataSource ] );

/**
* Apply the view settings (i.e. filters, sorting, pagination) to the dataset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {

export const Default = args => <ScanReport { ...args } />;
Default.args = {
dataSource: 'scan_api',
data: [
{
id: 1,
Expand Down Expand Up @@ -64,6 +65,12 @@ Default.args = {
title: 'Malicious code found in file: jptt_eicar.php',
severity: 1,
},
{
id: 198352407,
signature: 'EICAR_AV_Test_Suspicious',
title: 'Malicious code found in file: jptt_eicar.php',
severity: 1,
},
],
checked: true,
type: 'files',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const THREAT_TYPES = [
{ value: 'themes', label: __( 'Theme', 'jetpack-components' ) },
{ value: 'core', label: __( 'WordPress', 'jetpack-components' ) },
{ value: 'file', label: __( 'File', 'jetpack-components' ) },
{ value: '', label: __( 'Unknown', 'jetpack-components' ) },
];

export const THREAT_ICONS = {
Expand Down
nateweller marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,7 @@ export default function ThreatsDataViews( {
label: __( 'Type', 'jetpack-components' ),
elements: THREAT_TYPES,
getValue( { item }: { item: Threat } ) {
switch ( getThreatType( item ) ) {
case 'core':
return __( 'WordPress', 'jetpack-components' );
case 'plugins':
return __( 'Plugin', 'jetpack-components' );
case 'themes':
return __( 'Theme', 'jetpack-components' );
case 'file':
return __( 'File', 'jetpack-components' );
default:
return __( 'Unknown', 'jetpack-components' );
}
return getThreatType( item ) ?? '';
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds ScanReport to HomeRoute
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ const FirewallAdminSectionHero = () => {
<AdminSectionHero>
<AdminSectionHero.Main>
<Status
className={ styles.status }
status={ 'on' === status ? 'active' : 'inactive' }
label={ statusLabel }
className={ styles.status }
/>
<AdminSectionHero.Heading>{ heading }</AdminSectionHero.Heading>
<Text>{ subheading }</Text>
{ subheading }
</AdminSectionHero.Main>
{ wafSupported && (
<AdminSectionHero.Aside>
Expand Down
nateweller marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Text, useBreakpointMatch, StatCard } from '@automattic/jetpack-components';
import { useBreakpointMatch, StatCard } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, shield, chartBar } from '@wordpress/icons';
import { useCallback, useMemo } from 'react';
import usePlan from '../../hooks/use-plan';
import useWafData from '../../hooks/use-waf-data';
import styles from './styles.module.scss';

const FirewallStatCards = () => {
const { hasPlan } = usePlan();
const {
config: { bruteForceProtection: isBruteForceModuleEnabled },
isEnabled: isWafModuleEnabled,
Expand All @@ -22,26 +20,22 @@ const FirewallStatCards = () => {
const { currentDay: currentDayBlockCount, thirtyDays: thirtyDayBlockCounts } = stats
? stats.blockedRequests
: { currentDay: 0, thirtyDays: 0 };
const isFeatureDisabled = ! isSupportedWafFeatureEnabled || ! hasPlan;

const defaultArgs = useMemo(
() => ( {
className: isFeatureDisabled ? styles.disabled : styles.active,
className: ! isSupportedWafFeatureEnabled ? styles.disabled : styles.active,
variant: isSmall ? 'horizontal' : 'square',
} ),
[ isFeatureDisabled, isSmall ]
[ isSupportedWafFeatureEnabled, isSmall ]
);

const StatCardIcon = useCallback(
( { icon } ) => (
<span className={ styles[ 'stat-card-icon' ] }>
<Icon icon={ icon } />
{ ! isSmall && ! hasPlan && (
<Text variant="label">{ __( 'Paid feature', 'jetpack-protect' ) }</Text>
) }
</span>
),
[ isSmall, hasPlan ]
[]
);

const StatCardLabel = useCallback(
Expand Down Expand Up @@ -77,19 +71,19 @@ const FirewallStatCards = () => {
...defaultArgs,
icon: <StatCardIcon icon={ shield } />,
label: <StatCardLabel period={ 24 } units="hours" />,
value: isFeatureDisabled ? 0 : currentDayBlockCount,
value: ! isSupportedWafFeatureEnabled ? 0 : currentDayBlockCount,
} ),
[ defaultArgs, StatCardIcon, StatCardLabel, isFeatureDisabled, currentDayBlockCount ]
[ defaultArgs, StatCardIcon, StatCardLabel, isSupportedWafFeatureEnabled, currentDayBlockCount ]
);

const thirtyDaysArgs = useMemo(
() => ( {
...defaultArgs,
icon: <StatCardIcon icon={ chartBar } />,
label: <StatCardLabel period={ 30 } units="days" />,
value: isFeatureDisabled ? 0 : thirtyDayBlockCounts,
value: ! isSupportedWafFeatureEnabled ? 0 : thirtyDayBlockCounts,
} ),
[ defaultArgs, StatCardIcon, StatCardLabel, isFeatureDisabled, thirtyDayBlockCounts ]
[ defaultArgs, StatCardIcon, StatCardLabel, isSupportedWafFeatureEnabled, thirtyDayBlockCounts ]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const HomeAdminSectionHero: React.FC = () => {
)
: __(
'We stay ahead of security vulnerabilities to keep your site protected.',
'jetpack-protect'
'jetpack-protect',
/* dummy arg to avoid bad minification */ 0
) }
</Text>
<Button
Expand Down
19 changes: 17 additions & 2 deletions projects/plugins/protect/src/js/routes/home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AdminSection, Container, Col } from '@automattic/jetpack-components';
import { AdminSection, Container, Col, ScanReport } from '@automattic/jetpack-components';
import AdminPage from '../../components/admin-page';
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
import HomeAdminSectionHero from './home-admin-section-hero';

/**
Expand All @@ -10,12 +11,26 @@ import HomeAdminSectionHero from './home-admin-section-hero';
* @return {Component} The root component for the scan page.
*/
const HomePage = () => {
const { data: status } = useScanStatusQuery( { usePolling: true } );
const { core, plugins, themes, files } = status;

const data = [
core,
...plugins,
...themes,
{ checked: true, threats: files, type: 'files' },
].map( ( item, index ) => {
return { id: index + 1, ...item };
} );

return (
<AdminPage>
<HomeAdminSectionHero />
<AdminSection>
<Container horizontalSpacing={ 7 } horizontalGap={ 4 }>
<Col>{ /* TODO: Add ScanReport component here */ }</Col>
<Col>
<ScanReport dataSource={ status.dataSource } data={ data } />
</Col>
</Container>
</AdminSection>
</AdminPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
text-align: left;
}


@media ( max-width: 599px ) {
.stat-cards-wrapper {
flex-direction: column;
Expand Down
Loading