* Move getAdminLink to wc-admin-settings.

* Add changelog entries.

* Look for `getAdminLink()` in @woocommerce/settings first.
This commit is contained in:
Jeff Stieler 2019-11-22 12:07:26 -05:00 committed by GitHub
parent 52cb35f4de
commit c2020507e3
26 changed files with 66 additions and 60 deletions

View File

@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { EmptyContent } from '@woocommerce/components'; import { EmptyContent } from '@woocommerce/components';
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Component to render when there is an error in a report component due to data * Component to render when there is an error in a report component due to data

View File

@ -13,7 +13,7 @@ import { defaultTableDateFormat } from '@woocommerce/date';
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format'; import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format';
import { Date, Link } from '@woocommerce/components'; import { Date, Link } from '@woocommerce/components';
import { formatValue } from 'lib/number-format'; import { formatValue } from 'lib/number-format';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
const { countries } = getSetting( 'dataEndpoints', { countries: {} } ); const { countries } = getSetting( 'dataEndpoints', { countries: {} } );
@ -128,7 +128,7 @@ export default class CustomersReportTable extends Component {
const countryName = this.getCountryName( country ); const countryName = this.getCountryName( country );
const customerNameLink = user_id ? ( const customerNameLink = user_id ? (
<Link href={ 'user-edit.php?user_id=' + user_id } type="wp-admin"> <Link href={ getAdminLink( 'user-edit.php?user_id=' + user_id ) } type="wp-admin">
{ name } { name }
</Link> </Link>
) : ( ) : (

View File

@ -14,6 +14,7 @@ import { defaultTableDateFormat, getCurrentDates } from '@woocommerce/date';
import { Date, Link } from '@woocommerce/components'; import { Date, Link } from '@woocommerce/components';
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation'; import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
import { formatValue } from 'lib/number-format'; import { formatValue } from 'lib/number-format';
import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -111,7 +112,10 @@ export default class CouponsReportTable extends Component {
}, },
{ {
display: ( display: (
<Link href={ `post.php?post=${ order_id }&action=edit` } type="wp-admin"> <Link
href={ getAdminLink( `post.php?post=${ order_id }&action=edit` ) }
type="wp-admin"
>
{ order_number } { order_number }
</Link> </Link>
), ),

View File

@ -13,7 +13,7 @@ import { Link } from '@woocommerce/components';
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format'; import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format';
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation'; import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
import { formatValue } from 'lib/number-format'; import { formatValue } from 'lib/number-format';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -97,7 +97,7 @@ export default class VariationsReportTable extends Component {
filter: 'advanced', filter: 'advanced',
product_includes: query.products, product_includes: query.products,
} ); } );
const editPostLink = `post.php?post=${ product_id }&action=edit`; const editPostLink = getAdminLink( `post.php?post=${ product_id }&action=edit` );
return [ return [
{ {

View File

@ -14,7 +14,7 @@ import { formatCurrency, getCurrencyFormatDecimal, renderCurrency } from 'lib/cu
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation'; import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
import { Link, Tag } from '@woocommerce/components'; import { Link, Tag } from '@woocommerce/components';
import { formatValue } from 'lib/number-format'; import { formatValue } from 'lib/number-format';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -131,7 +131,7 @@ class ProductsReportTable extends Component {
[]; [];
const stockStatus = isLowStock( stock_status, stock_quantity, low_stock_amount ) ? ( const stockStatus = isLowStock( stock_status, stock_quantity, low_stock_amount ) ? (
<Link href={ 'post.php?action=edit&post=' + product_id } type="wp-admin"> <Link href={ getAdminLink( 'post.php?action=edit&post=' + product_id ) } type="wp-admin">
{ _x( 'Low', 'Indication of a low quantity', 'woocommerce-admin' ) } { _x( 'Low', 'Indication of a low quantity', 'woocommerce-admin' ) }
</Link> </Link>
) : ( ) : (

View File

@ -11,7 +11,7 @@ import { Component } from '@wordpress/element';
import { Link } from '@woocommerce/components'; import { Link } from '@woocommerce/components';
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation'; import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
import { formatValue } from 'lib/number-format'; import { formatValue } from 'lib/number-format';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -85,12 +85,13 @@ export default class StockReportTable extends Component {
</Link> </Link>
); );
const editProductLink = getAdminLink( 'post.php?action=edit&post=' + ( parent_id || id ) );
const stockStatusLink = isLowStock( stock_status, stock_quantity, low_stock_amount ) ? ( const stockStatusLink = isLowStock( stock_status, stock_quantity, low_stock_amount ) ? (
<Link href={ 'post.php?action=edit&post=' + ( parent_id || id ) } type="wp-admin"> <Link href={ editProductLink } type="wp-admin">
{ _x( 'Low', 'Indication of a low quantity', 'woocommerce-admin' ) } { _x( 'Low', 'Indication of a low quantity', 'woocommerce-admin' ) }
</Link> </Link>
) : ( ) : (
<Link href={ 'post.php?action=edit&post=' + ( parent_id || id ) } type="wp-admin"> <Link href={ editProductLink } type="wp-admin">
{ stockStatuses[ stock_status ] } { stockStatuses[ stock_status ] }
</Link> </Link>
); );

View File

@ -10,7 +10,8 @@ import { __, sprintf } from '@wordpress/i18n';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Card } from '@woocommerce/components'; import { Card } from '@woocommerce/components';
import { getAdminLink, getHistory, getNewPath, getPersistedQuery } from '@woocommerce/navigation'; import { getHistory, getNewPath, getPersistedQuery } from '@woocommerce/navigation';
import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -13,8 +13,8 @@ import { withDispatch } from '@wordpress/data';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { H, Stepper, Card } from '@woocommerce/components'; import { H, Stepper, Card } from '@woocommerce/components';
import { getNewPath, updateQueryString, getAdminLink } from '@woocommerce/navigation'; import { getNewPath, updateQueryString } from '@woocommerce/navigation';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -9,7 +9,6 @@ import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose'; import { compose } from '@wordpress/compose';
import { decodeEntities } from '@wordpress/html-entities'; import { decodeEntities } from '@wordpress/html-entities';
import { get } from 'lodash'; import { get } from 'lodash';
import { getAdminLink } from '@woocommerce/navigation';
import Gridicon from 'gridicons'; import Gridicon from 'gridicons';
import { TabPanel, Tooltip } from '@wordpress/components'; import { TabPanel, Tooltip } from '@wordpress/components';
import { withDispatch } from '@wordpress/data'; import { withDispatch } from '@wordpress/data';
@ -18,7 +17,7 @@ import { withDispatch } from '@wordpress/data';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Card, H } from '@woocommerce/components'; import { Card, H } from '@woocommerce/components';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -11,8 +11,8 @@ import { get } from 'lodash';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
import { updateQueryString, getAdminLink } from '@woocommerce/navigation'; import { updateQueryString } from '@woocommerce/navigation';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -15,8 +15,12 @@ import { withDispatch } from '@wordpress/data';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Form, Card, Stepper, TextControl, List } from '@woocommerce/components'; import { Form, Card, Stepper, TextControl, List } from '@woocommerce/components';
import { getAdminLink, getHistory, getNewPath } from '@woocommerce/navigation'; import { getHistory, getNewPath } from '@woocommerce/navigation';
import { WC_ASSET_URL as wcAssetUrl, getSetting } from '@woocommerce/wc-admin-settings'; import {
WC_ASSET_URL as wcAssetUrl,
getAdminLink,
getSetting,
} from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -9,7 +9,7 @@ import { Component, Fragment } from '@wordpress/element';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Card, List } from '@woocommerce/components'; import { Card, List } from '@woocommerce/components';
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -14,8 +14,8 @@ import { withDispatch } from '@wordpress/data';
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Card, H, Link, Stepper } from '@woocommerce/components'; import { Card, H, Link, Stepper } from '@woocommerce/components';
import { getAdminLink, getHistory, getNewPath } from '@woocommerce/navigation'; import { getHistory, getNewPath } from '@woocommerce/navigation';
import { getSetting, setSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting, setSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -16,8 +16,8 @@ import { keyBy, map, merge } from 'lodash';
*/ */
import { EmptyContent, Flag, Link, OrderStatus, Section } from '@woocommerce/components'; import { EmptyContent, Flag, Link, OrderStatus, Section } from '@woocommerce/components';
import { formatCurrency } from 'lib/currency-format'; import { formatCurrency } from 'lib/currency-format';
import { getAdminLink, getNewPath } from '@woocommerce/navigation'; import { getNewPath } from '@woocommerce/navigation';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -119,7 +119,12 @@ class OrdersPanel extends Component {
} }
), ),
components: { components: {
orderLink: <Link href={ 'post.php?action=edit&post=' + order_id } type="wp-admin" />, orderLink: (
<Link
href={ getAdminLink( 'post.php?action=edit&post=' + order_id ) }
type="wp-admin"
/>
),
destinationFlag: customer.country ? ( destinationFlag: customer.country ? (
<Flag code={ customer.country } round={ false } /> <Flag code={ customer.country } round={ false } />
) : null, ) : null,

View File

@ -22,7 +22,7 @@ import {
ReviewRating, ReviewRating,
Section, Section,
} from '@woocommerce/components'; } from '@woocommerce/components';
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -13,7 +13,7 @@ import PropTypes from 'prop-types';
*/ */
import { getNewPath } from '@woocommerce/navigation'; import { getNewPath } from '@woocommerce/navigation';
import { Link } from '@woocommerce/components'; import { Link } from '@woocommerce/components';
import { getSetting } from '@woocommerce/wc-admin-settings'; import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -88,12 +88,14 @@ class Header extends Component {
'is-scrolled': isScrolled, 'is-scrolled': isScrolled,
} ); } );
const firstBreadCrumbPath = 'admin.php?page=wc-admin';
return ( return (
<div className={ className }> <div className={ className }>
<h1 className="woocommerce-layout__header-breadcrumbs"> <h1 className="woocommerce-layout__header-breadcrumbs">
<span> <span>
<Link <Link
href={ 'admin.php?page=wc-admin' } href={ isEmbedded ? getAdminLink( firstBreadCrumbPath ) : firstBreadCrumbPath }
type={ isEmbedded ? 'wp-admin' : 'wc-admin' } type={ isEmbedded ? 'wp-admin' : 'wc-admin' }
onClick={ this.trackLinkClick } onClick={ this.trackLinkClick }
> >
@ -103,7 +105,9 @@ class Header extends Component {
{ _sections.map( ( section, i ) => { { _sections.map( ( section, i ) => {
const sectionPiece = Array.isArray( section ) ? ( const sectionPiece = Array.isArray( section ) ? (
<Link <Link
href={ isEmbedded ? section[ 0 ] : getNewPath( {}, section[ 0 ], {} ) } href={
isEmbedded ? getAdminLink( section[ 0 ] ) : getNewPath( {}, section[ 0 ], {} )
}
type={ isEmbedded ? 'wp-admin' : 'wc-admin' } type={ isEmbedded ? 'wp-admin' : 'wc-admin' }
onClick={ this.trackLinkClick } onClick={ this.trackLinkClick }
> >

View File

@ -89,3 +89,13 @@ export function getSetting( name, fallback = false, filter = val => val ) {
export function setSetting( name, value, filter = val => val ) { export function setSetting( name, value, filter = val => val ) {
allSettings[ name ] = filter( value ); allSettings[ name ] = filter( value );
} }
/**
* 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 function getAdminLink( path ) {
return ( ADMIN_URL || '' ) + path;
}

View File

@ -26,3 +26,4 @@ export const DEFAULT_DATE_RANGE = SOURCE.DEFAULT_DATE_RANGE;
export const getSetting = SOURCE.getSetting; export const getSetting = SOURCE.getSetting;
export const setSetting = SOURCE.setSetting; export const setSetting = SOURCE.setSetting;
export const getAdminLink = SOURCE.getAdminLink;

View File

@ -10,7 +10,7 @@ import domReady from '@wordpress/dom-ready';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies

View File

@ -9,7 +9,7 @@ import domReady from '@wordpress/dom-ready';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Displays a notice after product creation. * Displays a notice after product creation.

View File

@ -9,7 +9,7 @@ import domReady from '@wordpress/dom-ready';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { getAdminLink } from '@woocommerce/navigation'; import { getAdminLink } from '@woocommerce/wc-admin-settings';
/** /**
* Returns a promise and resolves when the loader overlay no longer exists. * Returns a promise and resolves when the loader overlay no longer exists.

View File

@ -6,6 +6,7 @@
- Export the `<CompareButton />` component. - Export the `<CompareButton />` component.
- Add `<TextControl />` component. - Add `<TextControl />` component.
- Require `currency` prop in `<AdvancedFilters />` component. - Require `currency` prop in `<AdvancedFilters />` component.
- Remove call to `getAdminLink()` inside the `<Link />` component.
# 4.0.0 # 4.0.0
- Added a new `<ScrollTo />` component. - Added a new `<ScrollTo />` component.

View File

@ -9,7 +9,7 @@ import { partial } from 'lodash';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { getAdminLink, getHistory } from '@woocommerce/navigation'; import { getHistory } from '@woocommerce/navigation';
/** /**
* Use `Link` to create a link to another resource. It accepts a type to automatically * Use `Link` to create a link to another resource. It accepts a type to automatically
@ -36,13 +36,6 @@ class Link extends Component {
render() { render() {
const { children, href, type, ...props } = this.props; const { children, href, type, ...props } = this.props;
let path;
if ( 'wp-admin' === type ) {
path = getAdminLink( href );
} else {
path = href;
}
const passProps = { const passProps = {
...props, ...props,
'data-link-type': type, 'data-link-type': type,
@ -53,7 +46,7 @@ class Link extends Component {
} }
return ( return (
<a href={ path } { ...passProps }> <a href={ href } { ...passProps }>
{ children } { children }
</a> </a>
); );

View File

@ -5,6 +5,7 @@
- `stringifyQuery` method is no longer available, instead use `addQueryArgs` from `@wordpress/url` package. - `stringifyQuery` method is no longer available, instead use `addQueryArgs` from `@wordpress/url` package.
- Added a new `<Form />` component. - Added a new `<Form />` component.
- Stepper component: Add new `content` and `description` props. - Stepper component: Add new `content` and `description` props.
- Remove `getAdminLink()` and dependency on global settings object.
# 2.1.1 # 2.1.1

View File

@ -28,15 +28,6 @@ render() {
} }
``` ```
### getAdminLink(path) ⇒ <code>String</code>
Returns a string with the site's wp-admin URL appended. JS version of `admin_url`. This relies on a global object `wcSettings` with a property `adminUrl` set.
**Returns**: <code>String</code> - Full admin URL.
| Param | Type | Description |
| --- | --- | --- |
| path | <code>String</code> | Relative path. |
### getPath() ⇒ <code>String</code> ### getPath() ⇒ <code>String</code>
Get the current path from history. Get the current path from history.

View File

@ -5,7 +5,6 @@
import { addQueryArgs } from '@wordpress/url'; import { addQueryArgs } from '@wordpress/url';
import { parse } from 'qs'; import { parse } from 'qs';
import { pick, uniq } from 'lodash'; import { pick, uniq } from 'lodash';
import { getSetting } from '@woocommerce/wc-admin-settings';
/** /**
* Internal dependencies * Internal dependencies
@ -24,14 +23,6 @@ export * from './filters';
// Import the module into itself. Functions consumed from this import can be mocked in tests. // Import the module into itself. Functions consumed from this import can be mocked in tests.
import * as navUtils from './index'; import * as navUtils from './index';
/**
* 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;
/** /**
* Get the current path from history. * Get the current path from history.
* *