Skip to content

Commit

Permalink
Protect: Add Home page (#40317)
Browse files Browse the repository at this point in the history
* 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 home page

---------

Co-authored-by: Nate Weller <[email protected]>
Co-authored-by: Nate Weller <[email protected]>
Co-authored-by: Dean Kmyta <[email protected]>
  • Loading branch information
4 people committed Dec 11, 2024
1 parent b33c95a commit e13aa74
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Stat Card: add hideValue prop
13 changes: 10 additions & 3 deletions projects/js-packages/components/components/stat-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import type React from 'react';
* @param {StatCardProps} props - Component props.
* @return {React.ReactNode} - StatCard react component.
*/
const StatCard = ( { className, icon, label, value, variant = 'square' }: StatCardProps ) => {
const StatCard = ( {
className,
icon,
label,
value,
variant = 'square',
hideValue = false,
}: StatCardProps ) => {
const formattedValue = numberFormat( value );
const compactValue = numberFormat( value, {
notation: 'compact',
Expand All @@ -33,12 +40,12 @@ const StatCard = ( { className, icon, label, value, variant = 'square' }: StatCa
{ variant === 'square' ? (
<Tooltip text={ formattedValue } placement="top">
<Text variant="headline-small" className={ clsx( styles.value ) }>
{ compactValue }
{ hideValue ? '-' : compactValue }
</Text>
</Tooltip>
) : (
<Text variant="title-medium-semi-bold" className={ clsx( styles.value ) }>
{ formattedValue }
{ hideValue ? '-' : formattedValue }
</Text>
) }
</div>
Expand Down
5 changes: 5 additions & 0 deletions projects/js-packages/components/components/stat-card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export type StatCardProps = {
* @default 'square'
*/
variant?: 'square' | 'horizontal';

/**
* Whether to hide the value.
*/
hideValue?: boolean;
};
4 changes: 4 additions & 0 deletions projects/plugins/protect/changelog/add-protect-home
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds a Home page and StatCards
3 changes: 2 additions & 1 deletion projects/plugins/protect/src/class-jetpack-protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ public static function get_waf_stats() {
}

return array(
'blockedRequests' => Plan::has_required_plan() ? Waf_Stats::get_blocked_requests() : false,
'blockedRequests' => Waf_Stats::get_blocked_requests(),
'automaticRulesLastUpdated' => Waf_Stats::get_automatic_rules_last_updated(),
'blockedLogins' => (int) get_option( 'jetpack_protect_blocked_attempts', 0 ),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const AdminPage = ( { children } ) => {
{ notice && <Notice floating={ true } dismissable={ true } { ...notice } /> }
<Container horizontalSpacing={ 0 }>
<Tabs className={ styles.navigation }>
<Tab link="/" label={ __( 'Home', 'jetpack-protect' ) } />
<Tab
link="/scan"
label={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ConnectedPricingTable = () => {
const getProtectFree = useCallback( async () => {
recordEvent( 'jetpack_protect_connected_product_activated' );
await connectSiteMutation.mutateAsync();
navigate( '/scan' );
navigate( '/' );
}, [ connectSiteMutation, recordEvent, navigate ] );

const args = {
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion projects/plugins/protect/src/js/hooks/use-plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function usePlan( { redirectUrl }: { redirectUrl?: string } = {}

const { run: checkout } = useProductCheckoutWorkflow( {
productSlug: JETPACK_SCAN_SLUG,
redirectUrl: redirectUrl || adminUrl,
redirectUrl: redirectUrl || adminUrl + '#/scan',
siteProductAvailabilityHandler: API.checkPlan,
useBlogIdSuffix: true,
connectAfterCheckout: false,
Expand Down
4 changes: 3 additions & 1 deletion projects/plugins/protect/src/js/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NoticeProvider } from './hooks/use-notices';
import { OnboardingRenderedContextProvider } from './hooks/use-onboarding';
import { CheckoutProvider } from './hooks/use-plan';
import FirewallRoute from './routes/firewall';
import HomeRoute from './routes/home';
import ScanRoute from './routes/scan';
import SetupRoute from './routes/setup';
import './styles.module.scss';
Expand Down Expand Up @@ -56,6 +57,7 @@ function render() {
<ScrollToTop />
<Routes>
<Route path="/setup" element={ <SetupRoute /> } />
<Route path="/" element={ <HomeRoute /> } />
<Route path="/scan" element={ <ScanRoute /> } />
<Route
path="/scan/history"
Expand All @@ -74,7 +76,7 @@ function render() {
}
/>
<Route path="/firewall" element={ <FirewallRoute /> } />
<Route path="*" element={ <Navigate to="/scan" replace /> } />
<Route path="*" element={ <Navigate to="/" replace /> } />
</Routes>
</HashRouter>
<Modal />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Text, Button } from '@automattic/jetpack-components';
import { __ } from '@wordpress/i18n';
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import AdminSectionHero from '../../components/admin-section-hero';
import usePlan from '../../hooks/use-plan';
import HomeStatCards from './home-statcards';
import styles from './styles.module.scss';

const HomeAdminSectionHero: React.FC = () => {
const { hasPlan } = usePlan();
const navigate = useNavigate();
const handleScanReportClick = useCallback( () => {
navigate( '/scan' );
}, [ navigate ] );

return (
<AdminSectionHero>
<AdminSectionHero.Main>
<>
<AdminSectionHero.Heading>
{ __( 'Your site is safe with us', 'jetpack-protect' ) }
</AdminSectionHero.Heading>
<Text>
{ hasPlan
? __(
'We stay ahead of security threats to keep your site protected.',
'jetpack-protect'
)
: __(
'We stay ahead of security vulnerabilities to keep your site protected.',
'jetpack-protect'
) }
</Text>
<Button
className={ styles[ 'view-scan-report' ] }
variant="primary"
weight="regular"
onClick={ handleScanReportClick }
>
{ __( 'View scan report', 'jetpack-protect' ) }
</Button>
</>
</AdminSectionHero.Main>
<AdminSectionHero.Aside>{ <HomeStatCards /> }</AdminSectionHero.Aside>
</AdminSectionHero>
);
};

export default HomeAdminSectionHero;
Loading

0 comments on commit e13aa74

Please sign in to comment.