Preview buttons can be static

When the current page does not contain any edit-fields for the current APM preview button, it enters “static” mode. Static buttons ignore most update requests, and render as they were defined during page load
This commit is contained in:
Philipp Stracker 2024-06-07 21:14:12 +02:00
parent 93f3e4e7ac
commit 6f73e82d3e
No known key found for this signature in database
4 changed files with 131 additions and 100 deletions

View file

@ -20,19 +20,10 @@ const buttonManager = () => {
*/
class GooglePayPreviewButtonManager extends PreviewButtonManager {
constructor() {
const defaultButton = {
style: {
type: 'pay',
color: 'black',
language: 'en'
}
};
const args = {
methodName: 'GooglePay',
buttonConfig: window.wc_ppcp_googlepay_admin,
widgetBuilder,
defaultAttributes: {button: defaultButton}
widgetBuilder
};
super(args);
@ -64,8 +55,7 @@ class GooglePayPreviewButtonManager extends PreviewButtonManager {
createButtonInst(wrapperId) {
return new GooglePayPreviewButton({
selector: wrapperId,
configResponse: this.configResponse,
defaultAttributes: this.defaultAttributes
apiConfig: this.apiConfig
});
}
}
@ -79,6 +69,15 @@ class GooglePayPreviewButton extends PreviewButton {
super(args);
this.selector = `${args.selector}GooglePay`
this.defaultAttributes = {
button: {
style: {
type: 'pay',
color: 'black',
language: 'en'
}
}
};
}
createNewWrapper() {
@ -88,26 +87,25 @@ class GooglePayPreviewButton extends PreviewButton {
return element;
}
createButton() {
createButton(buttonConfig) {
const button = new GooglepayButton(
'preview',
null,
this.buttonConfig,
buttonConfig,
this.ppcpConfig,
);
button.init(this.configResponse);
button.init(this.apiConfig);
}
/**
* Some style details need to be copied from the ppcpConfig object to buttonConfig.
*
* - ppcpConfig: Generated by JS, containing the current form values.
* - buttonConfig: Generated on server side, contains the full (saved) button details.
* Merge form details into the config object for preview.
* Mutates the previewConfig object; no return value.
*/
applyPreviewConfig() {
if (this.ppcpConfig && this.buttonConfig) {
this.buttonConfig.button.style = this.ppcpConfig.button.style;
dynamicPreviewConfig(buttonConfig, ppcpConfig) {
// Merge the current form-values into the preview-button configuration.
if (ppcpConfig.button && buttonConfig.button) {
Object.assign(buttonConfig.button.style, ppcpConfig.button.style);
}
}
}