Skip to content

Commit 61b5561

Browse files
dkmytanateweller
andauthored
Protect: Restore HistoryAdminSectionHero (#40551)
* Init project branch * Protect: Add Go to Cloud and Scan now button to Protect primary header (#40057) Co-authored-by: Nate Weller <[email protected]> * Protect: Update Scan and History headers (#40058) * Update Scan and History section header structure/content * changelog * Update projects/plugins/protect/src/js/routes/scan/scan-admin-section-hero.tsx Co-authored-by: Nate Weller <[email protected]> --------- Co-authored-by: Nate Weller <[email protected]> * Protect: de-emphasize cloud link by using link variant (#40211) * Protect: add ShieldIcon component * Protect: Add ShieldIcon Component (#40402) * Protect: Integrate ThreatsDataViews Component (#40076) * Components: Add ScanReport (#40419) * Fix type errors Protect: add HMR support Revert "Protect: add HMR support" This reverts commit 06497a0. * Protect: Refactor AdminSectionHero (#40516) * Restore history header * Pass status filter presets to consumer * Restore early return * Add plan level restrictions * Remove unneeded filter handling * Revert unnecessary threats data views updates * Fix import * Add size prop --------- Co-authored-by: Nate Weller <[email protected]> Co-authored-by: Nate Weller <[email protected]>
1 parent f672f0a commit 61b5561

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

projects/js-packages/components/components/threats-data-views/threats-status-toggle-group-control.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import styles from './styles.module.scss';
1414
* @param { Threat[]} props.data - Threats data.
1515
* @param { View } props.view - The current view.
1616
* @param { Function } props.onChangeView - Callback function to handle view changes.
17+
*
1718
* @return {JSX.Element|null} The component or null.
1819
*/
1920
export default function ThreatsStatusToggleGroupControl( {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Text } from '@automattic/jetpack-components';
2+
import { dateI18n } from '@wordpress/date';
3+
import { __, sprintf } from '@wordpress/i18n';
4+
import clsx from 'clsx';
5+
import { useMemo } from 'react';
6+
import AdminSectionHero from '../../components/admin-section-hero';
7+
import ErrorAdminSectionHero from '../../components/error-admin-section-hero';
8+
import useHistoryQuery from '../../data/scan/use-history-query';
9+
import styles from './styles.module.scss';
10+
11+
const HistoryAdminSectionHero: React.FC = ( {
12+
size = 'normal',
13+
}: {
14+
size?: 'normal' | 'large';
15+
} ) => {
16+
const { data: history } = useHistoryQuery();
17+
const numThreats = history ? history.threats.length : 0;
18+
19+
const oldestFirstDetected = useMemo( () => {
20+
if ( ! history ) {
21+
return null;
22+
}
23+
24+
return history.threats.reduce( ( oldest, current ) => {
25+
return new Date( current.firstDetected ) < new Date( oldest.firstDetected )
26+
? current
27+
: oldest;
28+
} ).firstDetected;
29+
}, [ history ] );
30+
31+
if ( history && history.error ) {
32+
return (
33+
<ErrorAdminSectionHero
34+
baseErrorMessage={ __( 'We are having problems loading your history.', 'jetpack-protect' ) }
35+
errorMessage={ history.errorMessage }
36+
errorCode={ history.errorMessage }
37+
/>
38+
);
39+
}
40+
41+
return (
42+
<AdminSectionHero>
43+
<AdminSectionHero.Main
44+
className={ clsx( styles[ 'hero-main' ], {
45+
[ styles[ 'hero-main--large' ] ]: size === 'large',
46+
} ) }
47+
>
48+
{ ' ' }
49+
<Text mb={ 2 }>
50+
{ oldestFirstDetected ? (
51+
<span className={ styles[ 'subheading-content' ] }>
52+
{ sprintf(
53+
/* translators: %s: Oldest first detected date */
54+
__( '%s - Today', 'jetpack-protect' ),
55+
dateI18n( 'F jS g:i A', oldestFirstDetected, false )
56+
) }
57+
</span>
58+
) : (
59+
__( 'Most recent results', 'jetpack-protect' )
60+
) }
61+
</Text>
62+
<AdminSectionHero.Heading icon={ numThreats > 0 ? 'error' : 'success' }>
63+
{ numThreats > 0
64+
? sprintf(
65+
/* translators: %s: Total number of threats */
66+
__( '%1$s previously active %2$s', 'jetpack-protect' ),
67+
numThreats,
68+
numThreats === 1 ? 'threat' : 'threats'
69+
)
70+
: __( 'No previously active threats', 'jetpack-protect' ) }
71+
</AdminSectionHero.Heading>
72+
<Text>{ __( 'Here you can view all of your threats to date.', 'jetpack-protect' ) }</Text>
73+
</AdminSectionHero.Main>
74+
</AdminSectionHero>
75+
);
76+
};
77+
78+
export default HistoryAdminSectionHero;

0 commit comments

Comments
 (0)