woocommerce/plugins/woocommerce-blocks/assets/js/settings/shared/index.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import compareVersions from 'compare-versions';
/**
* Internal dependencies
*/
import { getSetting } from './get-setting';
Implement PHP DI container and refactor. Also implements new Asset data interface for extendable settings passed to js. (https://github.com/woocommerce/woocommerce-blocks/pull/956) * Add dependency injection container for blocks * Add new Pacakge and Bootstrap classes. - Bootstrap for bootstrapping the plugin. - Package will replace `src/Package` and added as a dependency for any classes needing package info. * Introduce AssetsDataRegistry for managing asset data * refactor existing classes to use new DIC and Asset Data Registry - this is the bare minimum needed to make this pull viable. - further refactors will be done in more atomic smaller pulls for easier review. * add new settings handling and export `@woocommerce/settings` as an alias to wc.wcSettings - the export is exposed php side on the `wc-settings` handle. * Remove unnecessary concatenation * Fix typos and improve doc blocks * fix php linting issue * Use better escaping function. * improve jsdoc spacing * improve test assertion * use fully qualified class names in bootstrap * improve comment block to account for dynamic version string replace on build * handle exceptions a bit differently * correct dependency reference in webpack config * remove blank lines * fix doc block comment alignment * Various doc/grammar/spacing fixes from code review. Co-Authored-By: Albert Juhé Lluveras <contact@albertjuhe.com> * improve naming, documentation and logic of filter callbacks While this is intended for sanitization/validation, the callback ultimately provides flexibility for filtering the value before returning or setting in state so `filter` is a better name for this.
2019-09-23 18:07:13 +00:00
export * from './default-constants';
export { setSetting } from './set-setting';
import './exclude-draft-status-from-analytics';
/**
* Note: this attempts to coerce the wpVersion to a semver for comparison
* This will result in dropping any beta/rc values.
*
* `5.3-beta1-4252` would get converted to `5.3.0-rc.4252`
* `5.3-beta1` would get converted to `5.3.0-rc`.
* `5.3` would not be touched.
*
* For the purpose of these comparisons all pre-release versions are normalized
* to `rc`.
*
* @param {string} version Version to compare.
Use store-themed set password form for checkout signup (https://github.com/woocommerce/woocommerce-blocks/pull/3236) * use my-account/lost-password endpoint url for set password (tbd): - companion for working on https://github.com/woocommerce/woocommerce/issues/27754 * use more appropriate (new) set-password endpoint * add version check - use new woo core endpoint if woo version is new enough * use my-account/lost-password for setting password in checkout signup: - this has been available forever - no need for a version check - page will show `Lost password`; looking at options for overriding that * use more explicit `newaccount` action for set password url if available * tweak feature gating for checkout signup: - only available in dev builds (will change soon) - only available if Woo core 4.7 or newer - checkout signup relies on fixes in 4.7+ (tbc) to my-account/lost-password endpoint for setting initial password - standardise feature gate logic so is consistent, ensure feature is disabled in API/backend, hide editor option, and disable front end - add new setting `wcVersion` to allow feature gating on woo version * fix woo-version feature gate of checkout signup: - fixed version logic, explicit 4.7.0 reference version - refactor version compare routine so can be used for woo or WP version * revamp Woo 4.7+ logic so PHPunit tests aren't dependent on Woo version: - Woo-version feature gating is implemented at integration layer: - checkout REST API - register/override new account email handler
2020-10-15 01:13:49 +00:00
* @param {string} setting Setting name (e.g. wpVersion or wcVersion).
* @param {string} operator Comparison operator.
*/
Use store-themed set password form for checkout signup (https://github.com/woocommerce/woocommerce-blocks/pull/3236) * use my-account/lost-password endpoint url for set password (tbd): - companion for working on https://github.com/woocommerce/woocommerce/issues/27754 * use more appropriate (new) set-password endpoint * add version check - use new woo core endpoint if woo version is new enough * use my-account/lost-password for setting password in checkout signup: - this has been available forever - no need for a version check - page will show `Lost password`; looking at options for overriding that * use more explicit `newaccount` action for set password url if available * tweak feature gating for checkout signup: - only available in dev builds (will change soon) - only available if Woo core 4.7 or newer - checkout signup relies on fixes in 4.7+ (tbc) to my-account/lost-password endpoint for setting initial password - standardise feature gate logic so is consistent, ensure feature is disabled in API/backend, hide editor option, and disable front end - add new setting `wcVersion` to allow feature gating on woo version * fix woo-version feature gate of checkout signup: - fixed version logic, explicit 4.7.0 reference version - refactor version compare routine so can be used for woo or WP version * revamp Woo 4.7+ logic so PHPunit tests aren't dependent on Woo version: - Woo-version feature gating is implemented at integration layer: - checkout REST API - register/override new account email handler
2020-10-15 01:13:49 +00:00
const compareVersionSettingIgnorePrerelease = (
version,
setting,
operator
) => {
let replacement = getSetting( setting, '' ).replace(
/-[a-zA-Z0-9]*[\-]*/,
'.0-rc.'
);
replacement = replacement.endsWith( '.' )
? replacement.substring( 0, replacement.length - 1 )
: replacement;
return compareVersions.compare( version, replacement, operator );
};
Use store-themed set password form for checkout signup (https://github.com/woocommerce/woocommerce-blocks/pull/3236) * use my-account/lost-password endpoint url for set password (tbd): - companion for working on https://github.com/woocommerce/woocommerce/issues/27754 * use more appropriate (new) set-password endpoint * add version check - use new woo core endpoint if woo version is new enough * use my-account/lost-password for setting password in checkout signup: - this has been available forever - no need for a version check - page will show `Lost password`; looking at options for overriding that * use more explicit `newaccount` action for set password url if available * tweak feature gating for checkout signup: - only available in dev builds (will change soon) - only available if Woo core 4.7 or newer - checkout signup relies on fixes in 4.7+ (tbc) to my-account/lost-password endpoint for setting initial password - standardise feature gate logic so is consistent, ensure feature is disabled in API/backend, hide editor option, and disable front end - add new setting `wcVersion` to allow feature gating on woo version * fix woo-version feature gate of checkout signup: - fixed version logic, explicit 4.7.0 reference version - refactor version compare routine so can be used for woo or WP version * revamp Woo 4.7+ logic so PHPunit tests aren't dependent on Woo version: - Woo-version feature gating is implemented at integration layer: - checkout REST API - register/override new account email handler
2020-10-15 01:13:49 +00:00
export const compareWithWpVersion = ( version, operator ) => {
return compareVersionSettingIgnorePrerelease(
version,
'wpVersion',
operator
);
};
export const compareWithWooVersion = ( version, operator ) => {
return compareVersionSettingIgnorePrerelease(
version,
'wcVersion',
operator
);
};
export { compareVersions, getSetting };
/**
* Returns a string with the site's wp-admin URL appended. JS version of `admin_url`.
*
* @param {string} path Relative path.
* @return {string} Full admin URL.
*/
export const getAdminLink = ( path ) => getSetting( 'adminUrl' ) + path;