mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
🧑💻 Improve debug tools
This commit is contained in:
parent
fe0f17a9ce
commit
512574a9ad
1 changed files with 74 additions and 20 deletions
|
@ -18,6 +18,11 @@ export const addDebugTools = ( context, modules ) => {
|
||||||
if ( ! context.debug ) { return }
|
if ( ! context.debug ) { return }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const describe = ( fnName, fnInfo ) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log( `\n%c${ fnName }:`, 'font-weight:bold', fnInfo, '\n\n' );
|
||||||
|
};
|
||||||
|
|
||||||
const debugApi = ( window.ppcpDebugger = window.ppcpDebugger || {} );
|
const debugApi = ( window.ppcpDebugger = window.ppcpDebugger || {} );
|
||||||
|
|
||||||
// Dump the current state of all our Redux stores.
|
// Dump the current state of all our Redux stores.
|
||||||
|
@ -51,45 +56,89 @@ export const addDebugTools = ( context, modules ) => {
|
||||||
// Reset all Redux stores to their initial state.
|
// Reset all Redux stores to their initial state.
|
||||||
debugApi.resetStore = () => {
|
debugApi.resetStore = () => {
|
||||||
const stores = [];
|
const stores = [];
|
||||||
const { isConnected } = wp.data.select( CommonStoreName ).merchant();
|
|
||||||
|
|
||||||
if ( isConnected ) {
|
describe(
|
||||||
// Make sure the Onboarding wizard is "completed".
|
'resetStore',
|
||||||
const onboarding = wp.data.dispatch( OnboardingStoreName );
|
'Reset all Redux stores to their DEFAULT state, without changing any server-side data. The default state is defined in the JS code.'
|
||||||
onboarding.setPersistent( 'completed', true );
|
);
|
||||||
onboarding.persist();
|
|
||||||
|
|
||||||
// Reset all stores, except for the onboarding store.
|
const { completed } = wp.data
|
||||||
stores.push( CommonStoreName );
|
.select( OnboardingStoreName )
|
||||||
stores.push( PaymentStoreName );
|
.persistentData();
|
||||||
stores.push( SettingsStoreName );
|
|
||||||
stores.push( StylingStoreName );
|
// Reset all stores, except for the onboarding store.
|
||||||
stores.push( TodosStoreName );
|
stores.push( CommonStoreName );
|
||||||
} else {
|
stores.push( PaymentStoreName );
|
||||||
// Only reset the common & onboarding stores to restart the onboarding wizard.
|
stores.push( SettingsStoreName );
|
||||||
stores.push( CommonStoreName );
|
stores.push( StylingStoreName );
|
||||||
|
stores.push( TodosStoreName );
|
||||||
|
|
||||||
|
// Only reset the onboarding store when the wizard is not completed.
|
||||||
|
if ( ! completed ) {
|
||||||
stores.push( OnboardingStoreName );
|
stores.push( OnboardingStoreName );
|
||||||
}
|
}
|
||||||
|
|
||||||
stores.forEach( ( storeName ) => {
|
stores.forEach( ( storeName ) => {
|
||||||
const store = wp.data.dispatch( storeName );
|
const store = wp.data.dispatch( storeName );
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log( `Reset store: ${ storeName }...` );
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store.reset();
|
store.reset();
|
||||||
store.persist();
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log( `Done: Store '${ storeName }' reset` );
|
||||||
} catch ( error ) {
|
} catch ( error ) {
|
||||||
console.error( ' ... Reset failed, skipping this store' );
|
console.error(
|
||||||
|
`Failed: Could not reset store '${ storeName }'`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log( '---- Complete ----\n\n' );
|
||||||
|
};
|
||||||
|
|
||||||
|
debugApi.refreshStore = () => {
|
||||||
|
const stores = [];
|
||||||
|
|
||||||
|
describe(
|
||||||
|
'refreshStore',
|
||||||
|
'Refreshes all Redux details with details provided by the server. This has a similar effect as reloading the page without saving'
|
||||||
|
);
|
||||||
|
|
||||||
|
stores.push( CommonStoreName );
|
||||||
|
stores.push( PaymentStoreName );
|
||||||
|
stores.push( SettingsStoreName );
|
||||||
|
stores.push( StylingStoreName );
|
||||||
|
stores.push( TodosStoreName );
|
||||||
|
stores.push( OnboardingStoreName );
|
||||||
|
|
||||||
|
stores.forEach( ( storeName ) => {
|
||||||
|
const store = wp.data.dispatch( storeName );
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.refresh();
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(
|
||||||
|
`Done: Store '${ storeName }' refreshed from REST`
|
||||||
|
);
|
||||||
|
} catch ( error ) {
|
||||||
|
console.error(
|
||||||
|
`Failed: Could not refresh store '${ storeName }' from REST`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log( '---- Complete ----\n\n' );
|
||||||
};
|
};
|
||||||
|
|
||||||
// Disconnect the merchant and display the onboarding wizard.
|
// Disconnect the merchant and display the onboarding wizard.
|
||||||
debugApi.disconnect = () => {
|
debugApi.disconnect = () => {
|
||||||
const common = wp.data.dispatch( CommonStoreName );
|
const common = wp.data.dispatch( CommonStoreName );
|
||||||
|
|
||||||
|
describe();
|
||||||
|
|
||||||
common.disconnectMerchant();
|
common.disconnectMerchant();
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
@ -102,6 +151,11 @@ export const addDebugTools = ( context, modules ) => {
|
||||||
debugApi.onboardingMode = ( state ) => {
|
debugApi.onboardingMode = ( state ) => {
|
||||||
const onboarding = wp.data.dispatch( OnboardingStoreName );
|
const onboarding = wp.data.dispatch( OnboardingStoreName );
|
||||||
|
|
||||||
|
describe(
|
||||||
|
'onboardingMode',
|
||||||
|
'Toggle between onboarding wizard and the settings screen.'
|
||||||
|
);
|
||||||
|
|
||||||
onboarding.setPersistent( 'completed', ! state );
|
onboarding.setPersistent( 'completed', ! state );
|
||||||
onboarding.persist();
|
onboarding.persist();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue