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

Add "Beta" badge in FPM toggle #9811

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 19 additions & 10 deletions assets/js/components/first-party-mode/FirstPartyModeToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useMount } from 'react-use';
/**
* WordPress dependencies
*/
import { useCallback } from '@wordpress/element';
import { Fragment, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -34,6 +34,7 @@ import { __ } from '@wordpress/i18n';
import { ProgressBar, Switch } from 'googlesitekit-components';
import { useDispatch, useSelect } from 'googlesitekit-data';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import Badge from '../Badge';
import SubtleNotification from '../notifications/SubtleNotification';

export default function FirstPartyModeToggle( { className } ) {
Expand Down Expand Up @@ -73,15 +74,23 @@ export default function FirstPartyModeToggle( { className } ) {
/>
) }
{ ! isLoading && (
<Switch
label={ __( 'First-party mode', 'google-site-kit' ) }
checked={
!! isFirstPartyModeEnabled && hasMetServerRequirements
}
disabled={ ! hasMetServerRequirements }
onClick={ handleClick }
hideLabel={ false }
/>
<Fragment>
<Switch
label={ __( 'First-party mode', 'google-site-kit' ) }
checked={
!! isFirstPartyModeEnabled &&
hasMetServerRequirements
}
disabled={ ! hasMetServerRequirements }
onClick={ handleClick }
hideLabel={ false }
/>
<Badge
className="googlesitekit-badge--beta"
hasLeftSpacing
label={ __( 'Beta', 'google-site-kit' ) }
/>
</Fragment>
) }
<p className="googlesitekit-module-settings-group__helper-text">
{ __(
Expand Down
25 changes: 25 additions & 0 deletions assets/js/components/first-party-mode/FirstPartyModeToggle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,29 @@ describe( 'FirstPartyModeToggle', () => {
false
);
} );

it( 'should render a "Beta" badge', async () => {
fetchMock.getOnce( serverRequirementStatusEndpoint, {
body: {
isEnabled: null,
isFPMHealthy: true,
isScriptAccessEnabled: true,
},
status: 200,
} );

const { container, waitForRegistry } = render(
<FirstPartyModeToggle />,
{
registry,
}
);

await waitForRegistry();

const badgeElement = container.querySelector( '.googlesitekit-badge' );

expect( badgeElement ).toBeInTheDocument();
expect( badgeElement ).toHaveTextContent( 'Beta' );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ exports[`FirstPartyModeToggle should render in default state 1`] = `
>
First-party mode
</label>
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
Beta
</span>
<p
class="googlesitekit-module-settings-group__helper-text"
>
Expand Down Expand Up @@ -86,6 +91,11 @@ exports[`FirstPartyModeToggle should render in disabled state if server requirem
>
First-party mode
</label>
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
Beta
</span>
<p
class="googlesitekit-module-settings-group__helper-text"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@
padding: 14px $grid-gap-desktop;
}
}

.googlesitekit-badge {
margin-left: 6px;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading