Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Protect: add home page
Rebase on admin hero section refactor

Revert accidental type changes

Remove testing code

Init project branch

Protect: Add ShieldIcon Component (#40402)

Refactor AdminSectionHero component
  • Loading branch information
Dean Kmyta authored and nateweller committed Dec 10, 2024
commit 941941d0cc5675dc8acfdb93f84ed984e1c282d0
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(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes stats available regardless of plan

'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,52 @@
import { Text, Button } from '@automattic/jetpack-components';
import { __, sprintf } 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>
{ sprintf(
// translators: %s is replaced with "threats" or "vulnerabilities" depending on the user's plan.
__( 'We stay ahead of security %s to keep your site protected.', 'jetpack-protect' ),
hasPlan
? __( 'threats', 'jetpack-protect' )
: __(
'vulnerabilities',
'jetpack-protect',
/* dummy arg to avoid bad minification */ 0
)
) }
</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
Loading