woocommerce/plugins/woocommerce-admin/client/index.js

173 lines
4.9 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import '@wordpress/notices';
import { render, createRoot } from '@wordpress/element';
import { CustomerEffortScoreTracksContainer } from '@woocommerce/customer-effort-score';
import {
withCurrentUserHydration,
withSettingsHydration,
} from '@woocommerce/data';
/**
* Internal dependencies
*/
import './stylesheets/_index.scss';
import { getAdminSetting } from '~/utils/admin-settings';
import { PageLayout, EmbedLayout, PrimaryLayout as NoticeArea } from './layout';
import { EmbeddedBodyLayout } from './embedded-body-layout';
import './xstate.js';
2023-09-20 02:47:05 +00:00
import { deriveWpAdminBackgroundColours } from './utils/derive-wp-admin-background-colours';
import { possiblyRenderSettingsSlots } from './settings/settings-slots';
import { registerTaxSettingsConflictErrorFill } from './settings/conflict-error-slotfill';
import { registerPaymentsSettingsBannerFill } from './payments/payments-settings-banner-slotfill';
import { registerSiteVisibilitySlotFill } from './launch-your-store';
add: render react placeholders for offline and woocommerce_payments settings sections (#50008) * Added a whitelist of sections to render an alternative output in the WC_Settings_Payment_Gateways_React class. * Renamed constant and updated its contents to only include 'offline' * Added a branch in the `output()` method to output an appropriate div with an id if the current section is in the whitelist. * Added "experimental" prefix to payment settings div ID. * Replicated the render for the offline section similar to the main payments settings. * Added a new settings-payments-offline screen to the WooCommerce admin plugin. * Implemented new offline settings page component. * Removed the ErrorBoundary components from the SettingsPaymentsMainWrapper and SettingsPaymentsOfflineWrapper. * Added a new SettingsPaymentsOfflineWrapper component and its corresponding SCSS styles. * Implemented the WooCommerce Payments section in the settings page. * Removed WooCommerce Payments settings logic and replaced with a placeholder. * Added a placeholder for the offline payments screen. * Added 'main' to the REACTIFY_RENDER_SECTIONS array and refactored the output method to improve readability and maintainability. * Renamed `render_gateway_section` method to `render_classic_gateway_settings_page` in the `class-wc-settings-payment-gateways-react.php` file. * Added a filter for the REACTIFY_RENDER_SECTIONS so that plugins can modify this list. * Added inline documentation for the filter in the `get_reactify_render_sections` method. * changelog * Matched the CSS styles for the WooCommerce Payments section to the offline section. * Removed unnecessary Card component and placeholder text from WooCommerce Payments settings. * Linted the `class-wc-settings-payment-gateways-react.php` file, addressing the reported linting issues. * Refactored the payment settings UI to use React components and lazy loading. * lint * Nit: Removed unnecessary comment and moved a small code * Update name to experimental * Fix save button missing from section pages * Fix saving sections --------- Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2024-07-26 12:55:19 +00:00
import {
SettingsPaymentsMainWrapper,
SettingsPaymentsOfflineWrapper,
SettingsPaymentsWooCommercePaymentsWrapper,
} from './settings-payments';
import { ErrorBoundary } from './error-boundary';
const appRoot = document.getElementById( 'root' );
const embeddedRoot = document.getElementById( 'woocommerce-embedded-root' );
wp.data Settings refactor add data store for settings using wp.data add use-select-with-refresh example replace fresh-data usage with new settings data store for settings page Add data package move to packages Fix isDirty after save Add isBusy to primary button when saving update Readme remove comment readme to use useSelect Revert "update Readme" This reverts commit 7402fd49b8f384fde5878e0bee0616f0a87bb4f6. Data Layer: Settings page to use Settings store (https://github.com/woocommerce/woocommerce-admin/pull/3430) * Data Layer: Settings store as source of truth for settings page This reverts commit 7402fd49b8f384fde5878e0bee0616f0a87bb4f6. * fixup * save on reset * non mutable constants * add set/getSettings * save using setSettings * separate HOC * cleanup * remove settingsToData * withHydration * remove withSettings HOC * renmove useSettins for now * withSettingsHydration updates * Revert "withSettingsHydration updates" This reverts commit f2adf108fbe19b574978fea5925a1a18e7ed3007. * rename withSettingsHydration * redo withSettingsHydration simplification * restore * useSettings * render using useSettings * handleInputChange working * get setIsDirty working * saving works * reset and cleanup * cleanup * use snake case on hook files * use clearIsDirty * Avoid mutation on setting update * remove @todo * persiting -> isPersisting * better reducer ternaries * add wcSettings as arg to withSettingsHydration reset package-lock Settings: split out mutable wcAdminSettings (https://github.com/woocommerce/woocommerce-admin/pull/3675) Settings: handle async settings groups (https://github.com/woocommerce/woocommerce-admin/pull/3707)
2020-03-25 03:20:17 +00:00
const settingsGroup = 'wc_admin';
const hydrateUser = getAdminSetting( 'currentUserData' );
2023-09-20 02:47:05 +00:00
deriveWpAdminBackgroundColours();
if ( appRoot ) {
let HydratedPageLayout = withSettingsHydration(
settingsGroup,
window.wcSettings.admin
)( PageLayout );
const preloadSettings = window.wcSettings.admin
? window.wcSettings.admin.preloadSettings
: false;
const hydrateSettings = preloadSettings && preloadSettings.general;
if ( hydrateSettings ) {
HydratedPageLayout = withSettingsHydration( 'general', {
general: preloadSettings.general,
} )( HydratedPageLayout );
}
Migrate user store to wp.data (https://github.com/woocommerce/woocommerce-admin/pull/4505) * Initial user preferences custom hook (wc meta). * Organize dependencies. * Specify dependencies in useSelect() call. * Remove specifying preference keys. There's currently no performance benefit to be had. * Add HoC for hydrating current user data. * Add user prefs update method. * Export user prefs hook and HoC in data package. * Handle error condition when updating user preferences. * Use closure to get user ID for prefs update. * Refactor analytics dashboard to use new user hook. * Refactor ReportTable component to use new user hook. * Move prop access to top of function component. * Add todo for potential manual resolution logic. * Refactor DashboardCharts component to use new user preferences hook. * Move code out of functional component where possible. * Fix chart interval query property. * Refactor Leaderboards component to use new user preferences hook. * Move code out of functional component where possible. * Refactor Inbox panel to use user prefs hook. @todo - updating last read isn't working. * Use user prefs hook in StatsOverview component. * Export user preferences store name. * Use new store for unread inbox indicator. * Hydrate current user data higher up in the app. * Update "last read" timestamp in inbox panel. * Fix StatsOverview test. * Remove unused dispatch method from StorePerformance component. * Remove now defunct user methods from wc-api spec. * Add tests for isRequesting. * JSON decode WC meta on updated user object. * Test user prefs retrieval and save. * Remove todo comment. * Use user prefs hook in Jetpack install CTA on homepage.
2020-06-10 16:46:46 +00:00
if ( hydrateUser ) {
HydratedPageLayout =
withCurrentUserHydration( hydrateUser )( HydratedPageLayout );
Migrate user store to wp.data (https://github.com/woocommerce/woocommerce-admin/pull/4505) * Initial user preferences custom hook (wc meta). * Organize dependencies. * Specify dependencies in useSelect() call. * Remove specifying preference keys. There's currently no performance benefit to be had. * Add HoC for hydrating current user data. * Add user prefs update method. * Export user prefs hook and HoC in data package. * Handle error condition when updating user preferences. * Use closure to get user ID for prefs update. * Refactor analytics dashboard to use new user hook. * Refactor ReportTable component to use new user hook. * Move prop access to top of function component. * Add todo for potential manual resolution logic. * Refactor DashboardCharts component to use new user preferences hook. * Move code out of functional component where possible. * Fix chart interval query property. * Refactor Leaderboards component to use new user preferences hook. * Move code out of functional component where possible. * Refactor Inbox panel to use user prefs hook. @todo - updating last read isn't working. * Use user prefs hook in StatsOverview component. * Export user preferences store name. * Use new store for unread inbox indicator. * Hydrate current user data higher up in the app. * Update "last read" timestamp in inbox panel. * Fix StatsOverview test. * Remove unused dispatch method from StorePerformance component. * Remove now defunct user methods from wc-api spec. * Add tests for isRequesting. * JSON decode WC meta on updated user object. * Test user prefs retrieval and save. * Remove todo comment. * Use user prefs hook in Jetpack install CTA on homepage.
2020-06-10 16:46:46 +00:00
}
render(
<ErrorBoundary>
<HydratedPageLayout />
</ErrorBoundary>,
appRoot
);
} else if ( embeddedRoot ) {
let HydratedEmbedLayout = withSettingsHydration(
settingsGroup,
window.wcSettings.admin
)( EmbedLayout );
Migrate user store to wp.data (https://github.com/woocommerce/woocommerce-admin/pull/4505) * Initial user preferences custom hook (wc meta). * Organize dependencies. * Specify dependencies in useSelect() call. * Remove specifying preference keys. There's currently no performance benefit to be had. * Add HoC for hydrating current user data. * Add user prefs update method. * Export user prefs hook and HoC in data package. * Handle error condition when updating user preferences. * Use closure to get user ID for prefs update. * Refactor analytics dashboard to use new user hook. * Refactor ReportTable component to use new user hook. * Move prop access to top of function component. * Add todo for potential manual resolution logic. * Refactor DashboardCharts component to use new user preferences hook. * Move code out of functional component where possible. * Fix chart interval query property. * Refactor Leaderboards component to use new user preferences hook. * Move code out of functional component where possible. * Refactor Inbox panel to use user prefs hook. @todo - updating last read isn't working. * Use user prefs hook in StatsOverview component. * Export user preferences store name. * Use new store for unread inbox indicator. * Hydrate current user data higher up in the app. * Update "last read" timestamp in inbox panel. * Fix StatsOverview test. * Remove unused dispatch method from StorePerformance component. * Remove now defunct user methods from wc-api spec. * Add tests for isRequesting. * JSON decode WC meta on updated user object. * Test user prefs retrieval and save. * Remove todo comment. * Use user prefs hook in Jetpack install CTA on homepage.
2020-06-10 16:46:46 +00:00
if ( hydrateUser ) {
HydratedEmbedLayout =
withCurrentUserHydration( hydrateUser )( HydratedEmbedLayout );
Migrate user store to wp.data (https://github.com/woocommerce/woocommerce-admin/pull/4505) * Initial user preferences custom hook (wc meta). * Organize dependencies. * Specify dependencies in useSelect() call. * Remove specifying preference keys. There's currently no performance benefit to be had. * Add HoC for hydrating current user data. * Add user prefs update method. * Export user prefs hook and HoC in data package. * Handle error condition when updating user preferences. * Use closure to get user ID for prefs update. * Refactor analytics dashboard to use new user hook. * Refactor ReportTable component to use new user hook. * Move prop access to top of function component. * Add todo for potential manual resolution logic. * Refactor DashboardCharts component to use new user preferences hook. * Move code out of functional component where possible. * Fix chart interval query property. * Refactor Leaderboards component to use new user preferences hook. * Move code out of functional component where possible. * Refactor Inbox panel to use user prefs hook. @todo - updating last read isn't working. * Use user prefs hook in StatsOverview component. * Export user preferences store name. * Use new store for unread inbox indicator. * Hydrate current user data higher up in the app. * Update "last read" timestamp in inbox panel. * Fix StatsOverview test. * Remove unused dispatch method from StorePerformance component. * Remove now defunct user methods from wc-api spec. * Add tests for isRequesting. * JSON decode WC meta on updated user object. * Test user prefs retrieval and save. * Remove todo comment. * Use user prefs hook in Jetpack install CTA on homepage.
2020-06-10 16:46:46 +00:00
}
// Render the header.
wp.data Settings refactor add data store for settings using wp.data add use-select-with-refresh example replace fresh-data usage with new settings data store for settings page Add data package move to packages Fix isDirty after save Add isBusy to primary button when saving update Readme remove comment readme to use useSelect Revert "update Readme" This reverts commit 7402fd49b8f384fde5878e0bee0616f0a87bb4f6. Data Layer: Settings page to use Settings store (https://github.com/woocommerce/woocommerce-admin/pull/3430) * Data Layer: Settings store as source of truth for settings page This reverts commit 7402fd49b8f384fde5878e0bee0616f0a87bb4f6. * fixup * save on reset * non mutable constants * add set/getSettings * save using setSettings * separate HOC * cleanup * remove settingsToData * withHydration * remove withSettings HOC * renmove useSettins for now * withSettingsHydration updates * Revert "withSettingsHydration updates" This reverts commit f2adf108fbe19b574978fea5925a1a18e7ed3007. * rename withSettingsHydration * redo withSettingsHydration simplification * restore * useSettings * render using useSettings * handleInputChange working * get setIsDirty working * saving works * reset and cleanup * cleanup * use snake case on hook files * use clearIsDirty * Avoid mutation on setting update * remove @todo * persiting -> isPersisting * better reducer ternaries * add wcSettings as arg to withSettingsHydration reset package-lock Settings: split out mutable wcAdminSettings (https://github.com/woocommerce/woocommerce-admin/pull/3675) Settings: handle async settings groups (https://github.com/woocommerce/woocommerce-admin/pull/3707)
2020-03-25 03:20:17 +00:00
render( <HydratedEmbedLayout />, embeddedRoot );
embeddedRoot.classList.remove( 'is-embed-loading' );
// Render notices just above the WP content div.
const wpBody = document.getElementById( 'wpbody-content' );
const wrap =
wpBody.querySelector( '.wrap.woocommerce' ) ||
document.querySelector( '#wpbody-content > .woocommerce' ) ||
wpBody.querySelector( '.wrap' );
const noticeContainer = document.createElement( 'div' );
2022-04-06 16:38:38 +00:00
render(
<div className="woocommerce-layout">
<NoticeArea />
</div>,
wpBody.insertBefore( noticeContainer, wrap )
);
const embeddedBodyContainer = document.createElement( 'div' );
render(
<EmbeddedBodyLayout />,
wpBody.insertBefore( embeddedBodyContainer, wrap.nextSibling )
);
possiblyRenderSettingsSlots();
registerTaxSettingsConflictErrorFill();
registerPaymentsSettingsBannerFill();
if (
window.wcAdminFeatures &&
window.wcAdminFeatures[ 'launch-your-store' ] === true
) {
registerSiteVisibilitySlotFill();
}
}
// Render the CustomerEffortScoreTracksContainer only if
// the feature flag is enabled.
if (
window.wcAdminFeatures &&
window.wcAdminFeatures[ 'customer-effort-score-tracks' ] === true
) {
// Set up customer effort score survey.
( function () {
const root = appRoot || embeddedRoot;
render(
<CustomerEffortScoreTracksContainer />,
root.insertBefore( document.createElement( 'div' ), null )
);
} )();
}
// Render the payment settings components only if
// the feature flag is enabled.
if (
window.wcAdminFeatures &&
window.wcAdminFeatures[ 'reactify-classic-payments-settings' ] === true
) {
( function () {
const paymentsMainRoot = document.getElementById(
'experimental_wc_settings_payments_main'
);
add: render react placeholders for offline and woocommerce_payments settings sections (#50008) * Added a whitelist of sections to render an alternative output in the WC_Settings_Payment_Gateways_React class. * Renamed constant and updated its contents to only include 'offline' * Added a branch in the `output()` method to output an appropriate div with an id if the current section is in the whitelist. * Added "experimental" prefix to payment settings div ID. * Replicated the render for the offline section similar to the main payments settings. * Added a new settings-payments-offline screen to the WooCommerce admin plugin. * Implemented new offline settings page component. * Removed the ErrorBoundary components from the SettingsPaymentsMainWrapper and SettingsPaymentsOfflineWrapper. * Added a new SettingsPaymentsOfflineWrapper component and its corresponding SCSS styles. * Implemented the WooCommerce Payments section in the settings page. * Removed WooCommerce Payments settings logic and replaced with a placeholder. * Added a placeholder for the offline payments screen. * Added 'main' to the REACTIFY_RENDER_SECTIONS array and refactored the output method to improve readability and maintainability. * Renamed `render_gateway_section` method to `render_classic_gateway_settings_page` in the `class-wc-settings-payment-gateways-react.php` file. * Added a filter for the REACTIFY_RENDER_SECTIONS so that plugins can modify this list. * Added inline documentation for the filter in the `get_reactify_render_sections` method. * changelog * Matched the CSS styles for the WooCommerce Payments section to the offline section. * Removed unnecessary Card component and placeholder text from WooCommerce Payments settings. * Linted the `class-wc-settings-payment-gateways-react.php` file, addressing the reported linting issues. * Refactored the payment settings UI to use React components and lazy loading. * lint * Nit: Removed unnecessary comment and moved a small code * Update name to experimental * Fix save button missing from section pages * Fix saving sections --------- Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2024-07-26 12:55:19 +00:00
const paymentsOfflineRoot = document.getElementById(
'experimental_wc_settings_payments_offline'
);
const paymentsWooCommercePaymentsRoot = document.getElementById(
'experimental_wc_settings_payments_woocommerce_payments'
);
if ( paymentsMainRoot ) {
createRoot(
paymentsMainRoot.insertBefore(
document.createElement( 'div' ),
null
)
).render( <SettingsPaymentsMainWrapper /> );
}
add: render react placeholders for offline and woocommerce_payments settings sections (#50008) * Added a whitelist of sections to render an alternative output in the WC_Settings_Payment_Gateways_React class. * Renamed constant and updated its contents to only include 'offline' * Added a branch in the `output()` method to output an appropriate div with an id if the current section is in the whitelist. * Added "experimental" prefix to payment settings div ID. * Replicated the render for the offline section similar to the main payments settings. * Added a new settings-payments-offline screen to the WooCommerce admin plugin. * Implemented new offline settings page component. * Removed the ErrorBoundary components from the SettingsPaymentsMainWrapper and SettingsPaymentsOfflineWrapper. * Added a new SettingsPaymentsOfflineWrapper component and its corresponding SCSS styles. * Implemented the WooCommerce Payments section in the settings page. * Removed WooCommerce Payments settings logic and replaced with a placeholder. * Added a placeholder for the offline payments screen. * Added 'main' to the REACTIFY_RENDER_SECTIONS array and refactored the output method to improve readability and maintainability. * Renamed `render_gateway_section` method to `render_classic_gateway_settings_page` in the `class-wc-settings-payment-gateways-react.php` file. * Added a filter for the REACTIFY_RENDER_SECTIONS so that plugins can modify this list. * Added inline documentation for the filter in the `get_reactify_render_sections` method. * changelog * Matched the CSS styles for the WooCommerce Payments section to the offline section. * Removed unnecessary Card component and placeholder text from WooCommerce Payments settings. * Linted the `class-wc-settings-payment-gateways-react.php` file, addressing the reported linting issues. * Refactored the payment settings UI to use React components and lazy loading. * lint * Nit: Removed unnecessary comment and moved a small code * Update name to experimental * Fix save button missing from section pages * Fix saving sections --------- Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2024-07-26 12:55:19 +00:00
if ( paymentsOfflineRoot ) {
createRoot(
paymentsOfflineRoot.insertBefore(
document.createElement( 'div' ),
null
)
).render( <SettingsPaymentsOfflineWrapper /> );
}
if ( paymentsWooCommercePaymentsRoot ) {
createRoot(
paymentsWooCommercePaymentsRoot.insertBefore(
document.createElement( 'div' ),
null
)
).render( <SettingsPaymentsWooCommercePaymentsWrapper /> );
}
} )();
}