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

Snapshot shared presets #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
358 changes: 149 additions & 209 deletions packages/shared-notifications/dist/shared-notifications.cjs.js

Large diffs are not rendered by default.

360 changes: 150 additions & 210 deletions packages/shared-notifications/dist/shared-notifications.esm.js

Large diffs are not rendered by default.

194 changes: 156 additions & 38 deletions packages/shared-presets/dist/shared-presets.cjs.js

Large diffs are not rendered by default.

194 changes: 156 additions & 38 deletions packages/shared-presets/dist/shared-presets.esm.js

Large diffs are not rendered by default.

63 changes: 57 additions & 6 deletions packages/shared-presets/lib/components/apply-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,59 @@ import { Modal } from '@wpmudev/react-modal';
import { ButtonIcon } from '@wpmudev/react-button-icon';
import { Button } from '@wpmudev/react-button';

const ApplyModal = ({ setOpen, config, save, strings = {} }) => {
const ApplyModal = ({ setOpen, config, save, strings = {}, callback = null }) => {
const {
closeIcon = 'Close this dialog window',
title = 'Apply Config',
description = 'Are you sure you want to apply the {configName} config to this site? We recommend you have a backup available as your existing settings configuration will be overridden.',
notice = 'The storage region in the selected config doesn\'t match the storage region in your current settings. All existing backups will be deleted after applying this config.',
cancelButton = 'Cancel',
actionButton = 'Apply',
} = strings;

const [ isSaving, setIsSaving ] = React.useState( false );
let extraClass = "sui-box";

const applyLoader = (
<React.Fragment>
<span className="sui-icon-loader sui-loading" aria-hidden="true"></span>
</React.Fragment>
);

const [ isSaving, setIsSaving ] = React.useState( true );
const [ wrapper, setWrapper] = React.useState(extraClass);
const [ desc, setDesc ] = React.useState(description);

React.useEffect( () => {
if ( null !== callback ) {
let className = extraClass;
const result = window[callback](config);
result
.then(data => {
className += ' region-loaded ' + data.status;
setWrapper(className);
setIsSaving(false);
if ( 'description' in data ) {
setDesc(data.description);
}
})
.catch(err => {
className += ' region-loaded ' + err.status;
setWrapper(className);
setIsSaving(false);
if ( 'description' in err ) {
setDesc(err.description);
}
});
}
}, []);

const doAction = () => {
setIsSaving( true );
save();
};

const modalContent = () => (
<div className="sui-box">
<div className={wrapper}>
<div className="sui-box-header sui-flatten sui-content-center sui-spacing-top--60">
<ButtonIcon
label={ closeIcon }
Expand All @@ -39,10 +74,25 @@ const ApplyModal = ({ setOpen, config, save, strings = {} }) => {
<h2 id="sui-config-edit-title">
{ title }
</h2>
<p className="sui-description">
{ description.replace( '{configName}', config.name) }
</p>

<div className="apply-loader">
{ applyLoader }
</div>
<div className="region-match">
{ desc.replace('{configName}', config.name) }
</div>
</div>
<div className="sui-box-body region-mismatch">
<div id="sui-apply-modal-warning" className="sui-notice sui-active sui-notice-warning">
<div className="sui-notice-content">
<div className="sui-notice-message">
<span className="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></span>
<p>{ notice }</p>
</div>
</div>
</div>
</div>

<div className="sui-box-footer sui-content-center sui-flatten sui-spacing-top--0 sui-spacing-bottom--60">
<Button
design="ghost"
Expand All @@ -55,6 +105,7 @@ const ApplyModal = ({ setOpen, config, save, strings = {} }) => {
label={ actionButton }
onClick={ doAction }
loading={ isSaving }
className="sui-config-apply"
/>
</div>
</div>
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions packages/shared-presets/lib/requests-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,17 @@ export default class RequestHandler {
const xhr = new XMLHttpRequest();
xhr.open( verb, url, true );

xhr.addEventListener( 'load', () => {
if ( 'ajax_callback' in this.pluginRequests ) {
const fn = this.pluginRequests.ajax_callback;
window[fn](url, data, xhr);
}
});

for ( const header in headers ) {
xhr.setRequestHeader( header, headers[ header ] );
}

xhr.onload = () => {
if ( xhr.status >= 200 && xhr.status < 300 ) {
resolve( JSON.parse( xhr.response ) );
Expand Down
79 changes: 68 additions & 11 deletions packages/shared-presets/lib/shared-presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,72 @@ export const Presets = ( {
message = 'Error. Please check the browser console';
}

window.SUI.openNotice(
'sui-configs-floating-notice', `<p>${ message }</p>`,
{
type: 'error',
icon: 'info',
dismiss: {
show: true,
label: lang.notificationDismiss,
},
}
);
if ( undefined !== message ) {
window.SUI.openNotice(
'sui-configs-floating-notice', `<p>${ message }</p>`,
{
type: 'error',
icon: 'info',
dismiss: {
show: true,
label: lang.notificationDismiss
},
}
)
}
};
// End of notifications.

const tableImage = !isWhitelabel ? urls.accordionImg : null;
const Pagination = (
<React.Fragment>
<div className="sui-pagination-wrap">

<span className="sui-pagination-results">25 results</span>

<ul className="sui-pagination">

<li>
<a href="" disabled="">
<span className="sui-icon-arrow-skip-back" aria-hidden="true"></span>
<span className="sui-screen-reader-text">Go to first page</span>
</a>
</li>

<li>
<a href="" disabled="">
<span className="sui-icon-chevron-left" aria-hidden="true"></span>
<span className="sui-screen-reader-text">Previous page</span>
</a>
</li>

<li className="sui-active">
<a href="">1</a>
</li>
<li><a href="">2</a></li>
<li><a href="">3</a></li>
<li><a href="">4</a></li>
<li><a href="">5</a></li>

<li>
<a href="">
<span className="sui-icon-chevron-right" aria-hidden="true"></span>
<span className="sui-screen-reader-text">Next page</span>
</a>
</li>

<li>
<a href="">
<span className="sui-icon-arrow-skip-forward" aria-hidden="true"></span>
<span className="sui-screen-reader-text">Go to last page</span>
</a>
</li>

</ul>

</div>
</React.Fragment>
);
const Table = (
<React.Fragment>
{ !isEmpty && (
Expand Down Expand Up @@ -367,7 +418,11 @@ export const Presets = ( {
</PresetsAccordionItem>
) ) }
</div>


)}

{ Pagination }
</React.Fragment>
);

Expand Down Expand Up @@ -504,6 +559,7 @@ export const Presets = ( {
<LoadingContent>
<LoadingWrap aria-hidden="true">
{ Table }

{ getFooter() }
</LoadingWrap>
<LoadingMask>
Expand Down Expand Up @@ -534,6 +590,7 @@ export const Presets = ( {
config={ currentConfig }
save={ handleApply }
strings={ lang.applyAction }
callback={ requestsData.pluginRequests.callback }
/>
) }
{ isDeleteOpen && (
Expand Down