Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4c95bfe
Init project branch
nateweller Nov 14, 2024
91ce2ed
Protect: Refactor AdminSectionHero (#40516)
nateweller Dec 9, 2024
35cd0cf
Restore history header
dkmyta Dec 10, 2024
5ad53b7
Pass status filter presets to consumer
dkmyta Dec 10, 2024
e21bb59
Restore early return
dkmyta Dec 10, 2024
50a5849
Add plan level restrictions
dkmyta Dec 10, 2024
d738a65
Init project branch
nateweller Nov 14, 2024
b93cfa2
Protect: Integrate ThreatsDataViews Component (#40076)
nateweller Dec 5, 2024
19bc943
Separate scan and history DataViews
dkmyta Jan 3, 2025
561ab57
Reapply history routes
dkmyta Jan 3, 2025
13ec8a0
Add filters
dkmyta Jan 3, 2025
996649a
Add toggle group control
dkmyta Jan 3, 2025
5a0871e
Add historic flag
dkmyta Jan 3, 2025
939263c
Update stories
dkmyta Jan 3, 2025
a34d4bd
Remove unneeded filter handling
dkmyta Jan 3, 2025
84a2ebc
Revert unnecessary threats data views updates
dkmyta Jan 3, 2025
1d3733f
Fix import
dkmyta Jan 3, 2025
61ee84d
Include fixer action as label in list view action dropdown
dkmyta Jan 3, 2025
a847325
Add field constants
dkmyta Jan 3, 2025
23b791f
Reorg
dkmyta Jan 3, 2025
9cd5469
Add initialFields prop, update active to current where applicable
dkmyta Jan 6, 2025
ad201c2
Init project branch
nateweller Nov 14, 2024
8960ec6
Fix exports and imports
dkmyta Jan 7, 2025
ec33096
Move default values to function params
nateweller Jan 12, 2025
5ccae12
Fix ts warning
nateweller Jan 12, 2025
dcb2887
minor adjustment to definition of initial filters
nateweller Jan 12, 2025
c8cd20e
Add tsc-expect-error to dummy arg for minification cases
nateweller Jan 12, 2025
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
Prev Previous commit
Next Next commit
Reapply history routes
  • Loading branch information
dkmyta authored and nateweller committed Jan 12, 2025
commit 561ab57bc775081cae899a842edb5534c8942f94
5 changes: 3 additions & 2 deletions projects/plugins/protect/src/js/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CheckoutProvider } from './hooks/use-plan';
import FirewallRoute from './routes/firewall';
import HomeRoute from './routes/home';
import ScanRoute from './routes/scan';
import HistoryRoute from './routes/scan/history';
import SetupRoute from './routes/setup';
import './styles.module.scss';

Expand Down Expand Up @@ -63,15 +64,15 @@ function render() {
path="/scan/history"
element={
<PaidPlanGate>
<ScanRoute />
<HistoryRoute />
</PaidPlanGate>
}
/>
<Route
path="/scan/history/:filter"
element={
<PaidPlanGate>
<ScanRoute />
<HistoryRoute />
</PaidPlanGate>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dateI18n } from '@wordpress/date';
import { __, sprintf } from '@wordpress/i18n';
import clsx from 'clsx';
import { useMemo } from 'react';
import AdminSectionHero from '../../components/admin-section-hero';
import ErrorAdminSectionHero from '../../components/error-admin-section-hero';
import useHistoryQuery from '../../data/scan/use-history-query';
import AdminSectionHero from '../../../components/admin-section-hero';
import ErrorAdminSectionHero from '../../../components/error-admin-section-hero';
import useHistoryQuery from '../../../data/scan/use-history-query';
import styles from './styles.module.scss';

const HistoryAdminSectionHero: React.FC = ( {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { ThreatsDataViews } from '@automattic/jetpack-components';
import { Threat } from '@automattic/jetpack-scan';
import { type Threat } from '@automattic/jetpack-scan';
import { useCallback } from 'react';
import useHistoryQuery from '../../data/scan/use-history-query';
import useModal from '../../hooks/use-modal';
import useHistoryQuery from '../../../data/scan/use-history-query';
import useModal from '../../../hooks/use-modal';

/**
* Scan History Data View
* Scan Results Data View
*
* @param {object} props - Component props.
* @param {JSX.Element} props.header - Header component.
*
* @return {JSX.Element} ScanHistoryDataView component.
* @return {JSX.Element} ScanResultDataView component.
*/
export default function ScanHistoryDataView( { header }: { header: JSX.Element } ) {
const { setModal } = useModal();

export default function HistoryDataViews( { header }: { header?: JSX.Element } ) {
const { data: history } = useHistoryQuery();

const { setModal } = useModal();

const onUnignoreThreats = useCallback(
( threats: Threat[] ) => {
setModal( { type: 'UNIGNORE_THREAT', props: { threat: threats[ 0 ] } } );
Expand All @@ -27,7 +27,6 @@ export default function ScanHistoryDataView( { header }: { header: JSX.Element }
return (
<ThreatsDataViews
data={ history ? history.threats : [] }
filters={ [] }
onUnignoreThreats={ onUnignoreThreats }
header={ header }
/>
Expand Down
46 changes: 46 additions & 0 deletions projects/plugins/protect/src/js/routes/scan/history/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AdminSection, Container, Col } from '@automattic/jetpack-components';
import AdminPage from '../../../components/admin-page';
import useHistoryQuery from '../../../data/scan/use-history-query';
import useScanStatusQuery from '../../../data/scan/use-scan-status-query';
import HistoryAdminSectionHero from './history-admin-section-hero';
import HistoryDataViews from './history-data-views';
// import StatusToggleGroupControl from './status-toggle-group-control';
import styles from './styles.module.scss';

/**
* History Page
*
* The entry point for the History page.
*
* @return {Component} The root component for the scan page.
*/
const HistoryPage = () => {
const { data: status } = useScanStatusQuery();
const { data: history } = useHistoryQuery();

const hasActiveThreats = status && status.threats.length;
const hasHistory = history && history.threats.length;
const showResults = hasActiveThreats || hasHistory;

return (
<AdminPage>
<HistoryAdminSectionHero size={ hasHistory ? 'normal' : 'large' } />
{ showResults && (
<AdminSection>
<Container
className={ styles[ 'history-container' ] }
horizontalSpacing={ 5 }
horizontalGap={ 4 }
>
<Col>
{ /* TODO: Pass header */ }
<HistoryDataViews />
</Col>
</Container>
</AdminSection>
) }
</AdminPage>
);
};

export default HistoryPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.hero-main {
max-width: 550px;
}

.hero-main--large {
flex: 1 auto;
align-content: center;
height: calc( 100vh - 408px );
}

.history-container {
padding-left: 0;
padding-right: 0;
overflow: hidden;

> * {
margin-left: calc( var( --spacing-base ) * -3 ); // -24px
margin-right: calc( var( --spacing-base ) * -3 ); // -24px
}
}
25 changes: 1 addition & 24 deletions projects/plugins/protect/src/js/routes/scan/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AdminSection, Container, Col } from '@automattic/jetpack-components';
import { useMemo, useState } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import { useState } from 'react';
import AdminPage from '../../components/admin-page';
import OnboardingPopover from '../../components/onboarding-popover';
import useHistoryQuery from '../../data/scan/use-history-query';
Expand All @@ -22,8 +21,6 @@ import styles from './styles.module.scss';
*/
const ScanPage = () => {
const { hasPlan } = usePlan();
const location = useLocation();
const { filter } = useParams();
const { data: status } = useScanStatusQuery( { usePolling: true } );
const { data: history } = useHistoryQuery();

Expand All @@ -42,26 +39,6 @@ const ScanPage = () => {
const hasHistory = history && history.threats.length;
const showResults = hasActiveThreats || hasHistory;

const filters = useMemo( () => {
if ( location.pathname.includes( '/scan/history' ) ) {
return [
{
field: 'status',
value: filter ? [ filter ] : [ 'fixed', 'ignored' ],
operator: 'isAny',
},
];
}

return [
{
field: 'status',
value: [ 'current' ],
operator: 'isAny',
},
];
}, [ filter, location.pathname ] );

// Track view for Protect admin page.
useAnalyticsTracks( {
pageViewEventName: 'protect_admin',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ThreatsDataViews } from '@automattic/jetpack-components';
import { type Threat } from '@automattic/jetpack-scan';
import { useCallback } from 'react';
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
import useModal from '../../hooks/use-modal';

/**
* Scan Results Data View
*
* @param {object} props - Component props.
* @param {JSX.Element} props.header - Header component.
*
* @return {JSX.Element} ScanResultDataView component.
*/
export default function ScanResultsDataViews( { header }: { header: JSX.Element } ) {
const { data: status } = useScanStatusQuery( { usePolling: true } );

const { setModal } = useModal();

const onFixThreats = useCallback(
( threats: Threat[] ) => {
setModal( { type: 'FIX_THREAT', props: { threat: threats[ 0 ] } } );
},
[ setModal ]
);

const onIgnoreThreats = useCallback(
( threats: Threat[] ) => {
setModal( { type: 'IGNORE_THREAT', props: { threat: threats[ 0 ] } } );
},
[ setModal ]
);

return (
<ThreatsDataViews
data={ status ? status.threats : [] }
onFixThreats={ onFixThreats }
onIgnoreThreats={ onIgnoreThreats }
header={ header }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption, // eslint-disable-line @wordpress/no-unsafe-wp-apis
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import useHistoryQuery from '../../data/scan/use-history-query';
import useScanStatusQuery from '../../data/scan/use-scan-status-query';
import styles from './styles.module.scss';

/**
* ToggleGroupControl component for filtering threats by status.
* @param {object} props - Component props.
* @param {number} props.activeThreatsCount - Count of active threats.
* @param {number} props.historicThreatsCount - Count of historic threats.
* @param {string} props.selectedValue - The selected value.
* @param {boolean} props.viewingHistory - Whether the user is viewing the history.
* @param {Function} props.onStatusFilterChange - Callback function to handle status filter changes.
*
* @return {JSX.Element|null} The component or null.
*/
export default function StatusToggleGroupControl( {
activeThreatsCount = 1,
historicThreatsCount = 1,
selectedValue = 'active',
viewingHistory = true,
onStatusFilterChange,
}: {
activeThreatsCount?: number;
historicThreatsCount?: number;
selectedValue?: string;
viewingHistory?: boolean;
onStatusFilterChange?: ( newStatus: string ) => void;
} ): JSX.Element {
if ( ! ( activeThreatsCount + historicThreatsCount ) ) {
const { data: status } = useScanStatusQuery();
const { data: history } = useHistoryQuery();
const numActiveThreats = status ? status.threats.length : 0;
const numHistoricThreats = history ? history.threats.length : 0;

if ( ! ( numHistoricThreats + numActiveThreats ) ) {
return null;
}

const selectedValue = viewingHistory === true ? 'historic' : 'active';

try {
return (
<div>
Expand All @@ -49,15 +52,15 @@ export default function StatusToggleGroupControl( {
'Active threats (%d)',
'jetpack-protect'
),
activeThreatsCount
numActiveThreats
) }
/>
<ToggleGroupControlOption
value={ 'historic' }
label={ sprintf(
/* translators: %d: number of historic threats */
__( 'History (%d)', 'jetpack-protect' ),
historicThreatsCount
numHistoricThreats
) }
/>
</ToggleGroupControl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.hero-main {
max-width: 512px;
max-width: 550px;
}

.hero-main--large {
Expand Down