-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from newfold-labs/release/v2.3.0
Release/v2.3.0
- Loading branch information
Showing
26 changed files
with
1,020 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.