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

Boost: Add notices to settings page when modules/settings changed #40593

Merged
merged 25 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c5f1c82
Add notice when C CSS is enabled
donnchawp Dec 12, 2024
609d4be
changelog
donnchawp Dec 12, 2024
09e4d82
Add notification when enabling/disabling modules
dilirity Dec 16, 2024
48544d6
Change text to activate/deactivate module
donnchawp Dec 16, 2024
bc9d4a0
Add notice when concatentate settings saved
donnchawp Dec 16, 2024
96e9609
Add notices on Cornerstone save and defaults
donnchawp Dec 17, 2024
4fd28d8
Merge branch 'trunk' into update/boost/add-notices-to-settings-page
donnchawp Dec 17, 2024
ebe1eeb
The linter complained of an extra line
donnchawp Dec 17, 2024
b6f4eeb
Merge branch 'trunk' into update/boost/add-notices-to-settings-page
donnchawp Dec 17, 2024
228cc89
Fix optimizer breaking translations
dilirity Dec 17, 2024
44db1bf
Fix notice when saving minify settings
dilirity Dec 17, 2024
9f91197
Remove useEffect
dilirity Dec 17, 2024
b44ad75
Add "default handles loaded" notice on minify modules
donnchawp Dec 17, 2024
dcc1f53
Remove the full stop from this notice
donnchawp Dec 17, 2024
1f0443e
Add notification when toggling LIAR
dilirity Dec 17, 2024
fc7033b
Add notification when editing quality settings
dilirity Dec 17, 2024
d1ca285
Remove unnecessary useEffect usage
dilirity Dec 17, 2024
dec8f5f
Remove this C CSS notice, not needed
donnchawp Dec 17, 2024
a6b6561
Revert "Remove unnecessary useEffect usage"
dilirity Dec 17, 2024
e6f78df
Update snackbar notifications to disappear after 2 instead of 5 seconds
dilirity Dec 17, 2024
4edca13
Refactor translation declaration
dilirity Dec 17, 2024
d821fec
Update changelog message
dilirity Dec 17, 2024
0229f20
Move saved notice to success callback of saving function
donnchawp Dec 19, 2024
0e48840
Remove the "default pages loaded" notice
donnchawp Dec 19, 2024
d270c62
Remove the "default handles loaded" message based on feedback
donnchawp Dec 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { usePremiumFeatures } from '$lib/stores/premium-features';
import { useRegenerateCriticalCssAction } from '$features/critical-css/lib/stores/critical-css-state';
import { isSameSiteUrl } from '$lib/utils/is-same-site-url';
import UpgradeCTA from '$features/upgrade-cta/upgrade-cta';

import { useNotices } from '$features/notice/context';
const Meta = () => {
const cornerstonePagesSupportLink = getRedirectUrl( 'jetpack-boost-cornerstone-pages' );
const [ cornerstonePages, setCornerstonePages ] = useCornerstonePages();
Expand Down Expand Up @@ -151,7 +151,7 @@ const List: React.FC< ListProps > = ( {
const premiumFeatures = usePremiumFeatures();
const isPremium = premiumFeatures.includes( 'cornerstone-10-pages' );
const cornerstonePagesProperties = useCornerstonePagesProperties();

const { setNotice } = useNotices();
const validateInputValue = ( value: string ) => {
setInputValue( value );
try {
Expand Down Expand Up @@ -215,11 +215,21 @@ const List: React.FC< ListProps > = ( {
recordBoostEvent( 'cornerstone_pages_save', {
list_length: inputValue.split( '\n' ).length,
} );
setNotice( {
id: 'cornerstone-pages-save',
type: 'success',
message: __( 'Cornerstone pages saved', 'jetpack-boost' ),
} );
donnchawp marked this conversation as resolved.
Show resolved Hide resolved
}

function loadDefaultValue() {
validateInputValue( defaultValue );
recordBoostEvent( 'cornerstone_pages_load_default', {} );
setNotice( {
id: 'cornerstone-pages-load-default',
type: 'success',
message: __( 'Default pages loaded', 'jetpack-boost' ),
} );
donnchawp marked this conversation as resolved.
Show resolved Hide resolved
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styles from './image-cdn-liar.module.scss';
import ModuleSubsection from '$features/ui/module-subsection/module-subsection';
import { recordBoostEvent } from '$lib/utils/analytics';
import Pill from '$features/ui/pill/pill';
import { useMutationNotice } from '$features/ui/mutation-notice/mutation-notice';

type ImageCdnLiarProps = {
isPremium: boolean;
Expand All @@ -22,6 +23,12 @@ export default function ImageCdnLiar( { isPremium }: ImageCdnLiarProps ) {
z.boolean().catch( false )
);

const enabledMessage = __( 'Auto-resize enabled.', 'jetpack-boost' );
const disabledMessage = __( 'Auto-resize disabled.', 'jetpack-boost' );
useMutationNotice( 'image-cdn-liar', setImageCdnLiar, {
successMessage: imageCdnLiar.data ? enabledMessage : disabledMessage,
} );

const handleToggle = ( value: boolean ) => {
setImageCdnLiar.mutate( value );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QualityControl from '../quality-control/quality-control';
import { imageCdnSettingsSchema, useImageCdnQuality } from '../lib/stores';
import { z } from 'zod';
import ModuleSubsection from '$features/ui/module-subsection/module-subsection';
import { useMutationNotice } from '$features/ui/mutation-notice/mutation-notice';

type QualitySettingsProps = {
isPremium: boolean;
Expand All @@ -20,6 +21,8 @@ const QualitySettings = ( { isPremium }: QualitySettingsProps ) => {
const imageCdnQuality = query?.data;
const setImageCdnQuality = mutation.mutate;

useMutationNotice( 'image-cdn-quality', mutation );

const setQuality = ( format: 'jpg' | 'png' | 'webp', newValue: number ) => {
if ( ! setImageCdnQuality || ! imageCdnQuality ) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { Button } from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import { type Props, useMetaQuery } from '$lib/stores/minify';
import { recordBoostEvent } from '$lib/utils/analytics';
import styles from './minify-meta.module.scss';
import CollapsibleMeta from '$features/ui/collapsible-meta/collapsible-meta';
import { useNotices } from '$features/notice/context';
import { useMinifyDefaults } from './lib/stores';

const MetaComponent = ( { buttonText, placeholder, datasyncKey }: Props ) => {
const [ values, updateValues ] = useMetaQuery( datasyncKey );
const noticeId = `minify-meta-${ datasyncKey }`;

const [ values, updateValues ] = useMetaQuery( datasyncKey, newState => {
setInputValue( newState.join( ', ' ) );
setNotice( {
id: noticeId,
type: 'success',
message: __( 'Changes saved', 'jetpack-boost' ),
} );
} );
const [ inputValue, setInputValue ] = useState( () => values.join( ', ' ) );
const { setNotice } = useNotices();
const minifyDefaults = useMinifyDefaults( datasyncKey );

const concatenateType = datasyncKey === 'minify_js_excludes' ? 'js' : 'css';
Expand All @@ -20,10 +31,6 @@ const MetaComponent = ( { buttonText, placeholder, datasyncKey }: Props ) => {
defaultValue = minifyDefaults.join( ', ' );
}

useEffect( () => {
setInputValue( values.join( ', ' ) );
}, [ values ] );

const onToggleHandler = ( isExpanded: boolean ) => {
if ( ! isExpanded ) {
setInputValue( values.join( ', ' ) );
Expand All @@ -38,6 +45,13 @@ const MetaComponent = ( { buttonText, placeholder, datasyncKey }: Props ) => {
*/
recordBoostEvent( 'concatenate_' + concatenateType + '_exceptions_save_clicked', {} );

// Show saving notice
setNotice( {
id: noticeId,
type: 'pending',
message: __( 'Saving…', 'jetpack-boost' ),
} );

updateValues( inputValue );
}

Expand Down Expand Up @@ -65,6 +79,11 @@ const MetaComponent = ( { buttonText, placeholder, datasyncKey }: Props ) => {

function loadDefaultValue() {
setInputValue( defaultValue );
setNotice( {
id: 'minify_' + concatenateType + '_load_default',
type: 'success',
message: __( 'Default handles loaded', 'jetpack-boost' ),
} );
/*
donnchawp marked this conversation as resolved.
Show resolved Hide resolved
* Possible Events:
* minify_js_exceptions_load_default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styles from './module.module.scss';
import ErrorBoundary from '$features/error-boundary/error-boundary';
import { __ } from '@wordpress/i18n';
import { isWoaHosting } from '$lib/utils/hosting';
import { useNotices } from '$features/notice/context';

type ModuleProps = {
title: React.ReactNode;
Expand All @@ -29,7 +30,16 @@ const Module = ( {
onDisable,
onMountEnable,
}: ModuleProps ) => {
const { setNotice } = useNotices();
const [ status, setStatus ] = useSingleModuleState( slug, active => {
const activatedMessage = __( 'Module activated', 'jetpack-boost' );
const deactivatedMessage = __( 'Module deactivated', 'jetpack-boost' );

setNotice( {
id: 'update-module-state',
type: 'success',
message: active ? activatedMessage : deactivatedMessage,
} );
if ( active ) {
onEnable?.();
} else {
Expand All @@ -43,10 +53,20 @@ const Module = ( {
const isFakeActive = ! isModuleAvailable && isWoaHosting() && slug === 'page_cache';

const handleToggle = () => {
const newState = ! isModuleActive;
const deactivateMessage = __( 'Deactivating module', 'jetpack-boost' );
const activateMessage = __( 'Activating module', 'jetpack-boost' );

setNotice( {
id: 'update-module-state',
type: 'pending',
message: newState ? activateMessage : deactivateMessage,
} );

if ( onBeforeToggle ) {
onBeforeToggle( ! isModuleActive );
onBeforeToggle( newState );
}
setStatus( ! isModuleActive );
setStatus( newState );
};

useEffect( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Notice = ( { notice, onDismiss }: NoticeProps ) => {
if ( notice.type !== 'pending' ) {
onDismiss();
}
}, 5000 );
}, 2000 );

return () => clearTimeout( timer );
}, [ onDismiss, notice ] );
Expand Down
12 changes: 10 additions & 2 deletions projects/plugins/boost/app/assets/src/js/lib/stores/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ export interface Props {
placeholder: string;
}

export const useMetaQuery = ( key: MinifyMetaKeys ) => {
export const useMetaQuery = ( key: MinifyMetaKeys, onSuccess?: ( newState: string[] ) => void ) => {
const [ { data }, { mutate } ] = useDataSync( 'jetpack_boost_ds', key, z.array( z.string() ) );

function updateValues( text: string ) {
mutate( text.split( ',' ).map( item => item.trim() ) );
mutate(
text.split( ',' ).map( item => item.trim() ),
{
onSuccess: newState => {
// Run the passed on callbacks after the mutation has been applied
onSuccess?.( newState );
},
}
);
}

return [ data || [], updateValues ] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Index = () => {
const [ imageCdn ] = useSingleModuleState( 'image_cdn' );

const regenerateCssAction = useRegenerateCriticalCssAction();

const requestRegenerateCriticalCss = () => {
regenerateCssAction.mutate();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

UI: Add notifications when interacting with dashboard settings.
Loading