Skip to content

Commit

Permalink
Merge pull request #55 from newfold-labs/release/v2.3.0
Browse files Browse the repository at this point in the history
Release/v2.3.0
  • Loading branch information
arunshenoy99 authored Jan 8, 2025
2 parents a0922f1 + 682d951 commit ffa6285
Show file tree
Hide file tree
Showing 26 changed files with 1,020 additions and 184 deletions.
2 changes: 2 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ function ( $features ) {
}

new PerformanceFeatureHooks();

require_once __DIR__ . '/includes/BurstSafetyMode/init.php';
2 changes: 1 addition & 1 deletion components/advancedSettings/JetpackBoost/SingleOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const SingleOption = ( { params, isChild, methods, constants } ) => {
! NewfoldRuntime.sdk.performance
.jetpack_boost_premium_is_active && (
<FeatureUpsell
cardText="Upgrade to Unlock"
cardText={ constants.text.upgradeModule }
cardLink={ option.premiumUrl }
>
<ToggleField
Expand Down
89 changes: 89 additions & 0 deletions components/cacheExclusion/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
Button,
Container,
TextareaField,
} from '@newfold/ui-component-library';

const CacheExclusion = ( { methods, constants } ) => {
const [ isEdited, setIsEdited ] = methods.useState( false );
const [ isError, setIsError ] = methods.useState( false );
const [ isSaved, setIsSaved ] = methods.useState( false );
const [ currentValue, setCurrentValue ] = methods.useState(
methods.NewfoldRuntime.sdk.cacheExclusion
);
const [ cacheExclusion, setCacheExclusion ] = methods.useState(
methods.NewfoldRuntime.sdk.cacheExclusion
);
const apiUrl = methods.NewfoldRuntime.createApiUrl(
'/newfold-performance/v1/cache-exclusion/update'
);

const handleCacheExclusionChange = ( e ) => {
if ( e.target.value !== currentValue ) {
setIsEdited( true );
} else {
setIsEdited( false );
}
setCurrentValue( e.target.value );
};

const handlingSaveButton = () => {
methods
.apiFetch( {
url: apiUrl,
method: 'POST',
data: { cacheExclusion: currentValue },
} )
.then( () => {
setIsSaved( true );
setCacheExclusion( currentValue );
setIsEdited( false );
} )
.catch( ( error ) => {
setIsError( error.message );
} );
};

methods.useUpdateEffect( () => {
methods.setStore( {
...constants.store,
CacheExclusion: cacheExclusion,
} );

methods.makeNotice(
'cache-exlusion-notice',
constants.text.cacheExclusionTitle,
! isError ? constants.text.cacheExclusionSaved : isError,
! isError ? 'success' : 'error',
5000
);
}, [ isSaved, isError ] );

return (
<Container.SettingsField
title={ constants.text.cacheExclusionTitle }
description={ constants.text.cacheExclusionDescription }
>
<TextareaField
id="cache-exclusion"
name="cache-exclusion"
onChange={ handleCacheExclusionChange }
value={ currentValue }
rows="1"
label={ constants.text.cacheExclusionTitle }
/>
{ isEdited && (
<Button
variant="secondary"
className="save-cache-exclusion-button"
disabled={ isEdited ? false : true }
onClick={ handlingSaveButton }
>
{ constants.text.cacheExclusionSaveButton }
</Button>
) }
</Container.SettingsField>
);
};

export default CacheExclusion;
197 changes: 106 additions & 91 deletions components/cacheSettings/index.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,115 @@
import { Container, RadioGroup } from "@newfold/ui-component-library";
// Newfold
import { Container, RadioGroup } from '@newfold/ui-component-library';

const CacheSettings = ({ methods, constants, Components }) => {
const [ cacheLevel, setCacheLevel ] = methods.useState(constants.store.cacheLevel);
const CacheSettings = ( { methods, constants, Components } ) => {
const [ cacheLevel, setCacheLevel ] = methods.useState(
constants.store.cacheLevel
);

const cacheOptions = [
{
label: constants.text.cacheLevel0Label,
description: constants.text.cacheLevel0Description + constants.text.cacheLevel0Recommendation,
value: 0,
notice: constants.text.cacheLevel0NoticeText,
},
{
label: constants.text.cacheLevel1Label,
description: constants.text.cacheLevel1Description + constants.text.cacheLevel1Recommendation,
value: 1,
notice: constants.text.cacheLevel1NoticeText,
},
{
label: constants.text.cacheLevel2Label,
description: constants.text.cacheLevel2Description + constants.text.cacheLevel2Recommendation,
value: 2,
notice: constants.text.cacheLevel2NoticeText,
},
{
label: constants.text.cacheLevel3Label,
description: constants.text.cacheLevel3Description + constants.text.cacheLevel3Recommendation,
value: 3,
notice: constants.text.cacheLevel3NoticeText,
},
];
const cacheOptions = [
{
label: constants.text.cacheLevel0Label,
description:
constants.text.cacheLevel0Description +
constants.text.cacheLevel0Recommendation,
value: 0,
notice: constants.text.cacheLevel0NoticeText,
},
{
label: constants.text.cacheLevel1Label,
description:
constants.text.cacheLevel1Description +
constants.text.cacheLevel1Recommendation,
value: 1,
notice: constants.text.cacheLevel1NoticeText,
},
{
label: constants.text.cacheLevel2Label,
description:
constants.text.cacheLevel2Description +
constants.text.cacheLevel2Recommendation,
value: 2,
notice: constants.text.cacheLevel2NoticeText,
},
{
label: constants.text.cacheLevel3Label,
description:
constants.text.cacheLevel3Description +
constants.text.cacheLevel3Recommendation,
value: 3,
notice: constants.text.cacheLevel3NoticeText,
},
];

const getCacheLevelNoticeTitle = () => {
return constants.text.cacheLevelNoticeTitle;
};
const getCacheLevelNoticeTitle = () => {
return constants.text.cacheLevelNoticeTitle;
};

const getCacheLevelNoticeText = () => {
return cacheOptions[cacheLevel].notice;
};
const getCacheLevelNoticeText = () => {
return cacheOptions[ cacheLevel ].notice;
};

const handleCacheLevelChange = (e) => {
methods.newfoldSettingsApiFetch(
{ cacheLevel: parseInt(e.target.value) },
methods.setError, (response) => {
setCacheLevel(parseInt(e.target.value));
}
);
};
const handleCacheLevelChange = ( e ) => {
methods.newfoldSettingsApiFetch(
{ cacheLevel: parseInt( e.target.value ) },
methods.setError,
() => {
setCacheLevel( parseInt( e.target.value ) );
}
);
};

methods.useUpdateEffect(() => {
methods.setStore({
...constants.store,
cacheLevel,
});
methods.useUpdateEffect( () => {
methods.setStore( {
...constants.store,
cacheLevel,
} );

methods.makeNotice(
"cache-level-change-notice",
getCacheLevelNoticeTitle(),
getCacheLevelNoticeText(),
"success",
5000
);
}, [cacheLevel]);
methods.makeNotice(
'cache-level-change-notice',
getCacheLevelNoticeTitle(),
getCacheLevelNoticeText(),
'success',
5000
);
}, [ cacheLevel ] );

return (
<>
<Container.SettingsField
title={constants.text.cacheLevelTitle}
description={constants.text.cacheLevelDescription}
>
<RadioGroup
className="cache-options"
id="cache-type"
name="cache-level"
value=""
>
{cacheOptions.map((option) => {
return (
<Components.Fragment key={option.value}>
<RadioGroup.Radio
defaultChecked={option.value === constants.store.cacheLevel}
id={'cache-level-' + option.value}
label={option.label}
value={option.value}
name="cache-level"
onChange={handleCacheLevelChange}
/>
<div className="nfd-radio__description">
{option.description}
</div>
</Components.Fragment>
);
})}
</RadioGroup>
</Container.SettingsField>
</>
);
}
return (
<>
<Container.SettingsField
title={ constants.text.cacheLevelTitle }
description={ constants.text.cacheLevelDescription }
>
<RadioGroup
className="cache-options"
id="cache-type"
name="cache-level"
value=""
>
{ cacheOptions.map( ( option ) => {
return (
<Components.Fragment key={ option.value }>
<RadioGroup.Radio
defaultChecked={
option.value ===
constants.store.cacheLevel
}
id={ 'cache-level-' + option.value }
label={ option.label }
value={ option.value }
name="cache-level"
onChange={ handleCacheLevelChange }
/>
<div className="nfd-radio__description">
{ option.description }
</div>
</Components.Fragment>
);
} ) }
</RadioGroup>
</Container.SettingsField>
</>
);
};

export default CacheSettings;
export default CacheSettings;
70 changes: 34 additions & 36 deletions components/clearCache/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
import { Button, Container } from "@newfold/ui-component-library";
import { Button, Container } from '@newfold/ui-component-library';

const ClearCache = ({ methods, constants }) => {
const ClearCache = ( { methods, constants } ) => {
const clearCache = () => {
methods.newfoldPurgeCacheApiFetch(
{},
methods.setError,
( response ) => {
methods.makeNotice(
'disable-old-posts-comments-notice',
constants.text.clearCacheNoticeTitle,
null,
'success',
5000
);
}
);
};

const clearCache = () => {
methods.newfoldPurgeCacheApiFetch(
{},
methods.setError,
(response) => {
methods.makeNotice(
"disable-old-posts-comments-notice",
constants.text.clearCacheNoticeTitle,
null,
"success",
5000
);
}
);
};
return (
<Container.SettingsField
title={ constants.text.clearCacheTitle }
description={ constants.text.clearCacheDescription }
>
<Button
variant="secondary"
className="clear-cache-button"
disabled={ constants.store.cacheLevel > 0 ? false : true }
onClick={ clearCache }
>
{ constants.text.clearCacheButton }
</Button>
</Container.SettingsField>
);
};

return (
<Container.SettingsField
title={constants.text.clearCacheTitle}
description={constants.text.clearCacheDescription}
>
<Button
variant="secondary"
className="clear-cache-button"
disabled={constants.store.cacheLevel > 0 ? false : true}
onClick={clearCache}
>
{constants.text.clearCacheButton}
</Button>
</Container.SettingsField>

);
;}

export default ClearCache;
export default ClearCache;
Loading

0 comments on commit ffa6285

Please sign in to comment.