diff --git a/client/analytics/components/report-chart/index.js b/client/analytics/components/report-chart/index.js index 29d3b79cbbc..4343175780c 100644 --- a/client/analytics/components/report-chart/index.js +++ b/client/analytics/components/report-chart/index.js @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { format as formatDate } from '@wordpress/date'; +import { withSelect } from '@wordpress/data'; import { get, isEqual } from 'lodash'; import PropTypes from 'prop-types'; import { Chart } from '@woocommerce/components'; @@ -27,7 +28,6 @@ import { */ import { CurrencyContext } from '../../../lib/currency-context'; import ReportError from '../report-error'; -import withSelect from '../../../wc-api/with-select'; import { getChartMode, getSelectedFilter } from './utils'; /** diff --git a/client/analytics/components/report-summary/index.js b/client/analytics/components/report-summary/index.js index 10f895e26a9..7e0ca77a930 100644 --- a/client/analytics/components/report-summary/index.js +++ b/client/analytics/components/report-summary/index.js @@ -4,6 +4,7 @@ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; +import { withSelect } from '@wordpress/data'; import PropTypes from 'prop-types'; import { getNewPath } from '@woocommerce/navigation'; import { @@ -20,7 +21,6 @@ import { recordEvent } from '@woocommerce/tracks'; * Internal dependencies */ import ReportError from '../report-error'; -import withSelect from '../../../wc-api/with-select'; import { CurrencyContext } from '../../../lib/currency-context'; /** diff --git a/client/analytics/components/report-table/index.js b/client/analytics/components/report-table/index.js index 32bb3321e2c..7a611fd5f81 100644 --- a/client/analytics/components/report-table/index.js +++ b/client/analytics/components/report-table/index.js @@ -6,7 +6,7 @@ import { applyFilters } from '@wordpress/hooks'; import { Fragment, useRef, useState } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { focus } from '@wordpress/dom'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { get, noop, partial, uniq } from 'lodash'; import { __, sprintf } from '@wordpress/i18n'; import classnames from 'classnames'; @@ -29,6 +29,7 @@ import { EXPORT_STORE_NAME, SETTINGS_STORE_NAME, useUserPreferences, + QUERY_DEFAULTS, } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; @@ -37,8 +38,6 @@ import { recordEvent } from '@woocommerce/tracks'; */ import DownloadIcon from './download-icon'; import ReportError from '../report-error'; -import { QUERY_DEFAULTS } from '../../../wc-api/constants'; -import withSelect from '../../../wc-api/with-select'; import { extendTableData } from './utils'; import './style.scss'; @@ -476,7 +475,7 @@ ReportTable.propTypes = { */ endpoint: PropTypes.string, /** - * Name of the methods available via `select( 'wc-api' )` that will be used to + * Name of the methods available via `select` that will be used to * load more data for table items. If omitted, no call will be made and only * the data returned by the reports endpoint will be used. */ @@ -485,6 +484,10 @@ ReportTable.propTypes = { isRequesting: PropTypes.string, load: PropTypes.string, } ), + /** + * Name of store on which extendItemsMethodNames can be found. + */ + extendedItemsStoreName: PropTypes.string, /** * A function that returns the headers object to build the table. */ diff --git a/client/analytics/components/report-table/utils.js b/client/analytics/components/report-table/utils.js index aaba6915b22..c5a311db83b 100644 --- a/client/analytics/components/report-table/utils.js +++ b/client/analytics/components/report-table/utils.js @@ -4,7 +4,11 @@ import { first } from 'lodash'; export function extendTableData( select, props, queriedTableData ) { - const { extendItemsMethodNames, itemIdField } = props; + const { + extendItemsMethodNames, + extendedItemsStoreName, + itemIdField, + } = props; const itemsData = queriedTableData.items.data; if ( ! Array.isArray( itemsData ) || @@ -19,7 +23,7 @@ export function extendTableData( select, props, queriedTableData ) { [ extendItemsMethodNames.getError ]: getErrorMethod, [ extendItemsMethodNames.isRequesting ]: isRequestingMethod, [ extendItemsMethodNames.load ]: loadMethod, - } = select( 'wc-api' ); + } = select( extendedItemsStoreName ); const extendQuery = { include: itemsData.map( ( item ) => item[ itemIdField ] ).join( ',' ), per_page: itemsData.length, diff --git a/client/analytics/report/customers/config.js b/client/analytics/report/customers/config.js index 20997851433..0b8e0ecfacf 100644 --- a/client/analytics/report/customers/config.js +++ b/client/analytics/report/customers/config.js @@ -5,6 +5,7 @@ import { __, _x } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; import { applyFilters } from '@wordpress/hooks'; import { getSetting } from '@woocommerce/wc-admin-settings'; +import { NAMESPACE } from '@woocommerce/data'; const { countries } = getSetting( 'dataEndpoints', { countries: {} } ); @@ -15,7 +16,6 @@ import { getCustomerLabels, getRequestByIdString, } from '../../../lib/async-requests'; -import { NAMESPACE } from '../../../wc-api/constants'; const CUSTOMERS_REPORT_FILTERS_FILTER = 'woocommerce_admin_customers_report_filters'; diff --git a/client/analytics/report/revenue/table.js b/client/analytics/report/revenue/table.js index df53d689c70..a0b49ade3bf 100644 --- a/client/analytics/report/revenue/table.js +++ b/client/analytics/report/revenue/table.js @@ -4,6 +4,7 @@ import { __, _n } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { format as formatDate } from '@wordpress/date'; +import { withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; import { get } from 'lodash'; import { Date, Link } from '@woocommerce/components'; @@ -13,6 +14,7 @@ import { getReportTableQuery, REPORTS_STORE_NAME, SETTINGS_STORE_NAME, + QUERY_DEFAULTS, } from '@woocommerce/data'; import { appendTimestamp, @@ -23,9 +25,7 @@ import { /** * Internal dependencies */ -import { QUERY_DEFAULTS } from '../../../wc-api/constants'; import ReportTable from '../../components/report-table'; -import withSelect from '../../../wc-api/with-select'; import { CurrencyContext } from '../../../lib/currency-context'; class RevenueReportTable extends Component { diff --git a/client/analytics/report/taxes/config.js b/client/analytics/report/taxes/config.js index 3924a99f702..d86e1d6f813 100644 --- a/client/analytics/report/taxes/config.js +++ b/client/analytics/report/taxes/config.js @@ -3,13 +3,13 @@ */ import { __ } from '@wordpress/i18n'; import { applyFilters } from '@wordpress/hooks'; +import { NAMESPACE } from '@woocommerce/data'; /** * Internal dependencies */ import { getRequestByIdString } from '../../../lib/async-requests'; import { getTaxCode } from './utils'; -import { NAMESPACE } from '../../../wc-api/constants'; const TAXES_REPORT_CHARTS_FILTER = 'woocommerce_admin_taxes_report_charts'; const TAXES_REPORT_FILTERS_FILTER = 'woocommerce_admin_taxes_report_filters'; diff --git a/client/analytics/settings/historical-data/index.js b/client/analytics/settings/historical-data/index.js index 2b802436003..5a667aac7a2 100644 --- a/client/analytics/settings/historical-data/index.js +++ b/client/analytics/settings/historical-data/index.js @@ -8,10 +8,10 @@ import { IMPORT_STORE_NAME, NOTES_STORE_NAME, QUERY_DEFAULTS, + SECOND, } from '@woocommerce/data'; import { withDispatch, withSelect } from '@wordpress/data'; import { withSpokenMessages } from '@wordpress/components'; -import { SECOND } from '@fresh-data/framework'; /** * Internal dependencies diff --git a/client/dashboard/customizable.js b/client/dashboard/customizable.js index 1e3f6db1203..c80fcb3befd 100644 --- a/client/dashboard/customizable.js +++ b/client/dashboard/customizable.js @@ -8,6 +8,7 @@ import { partial } from 'lodash'; import { Dropdown, Button, Icon } from '@wordpress/components'; import { applyFilters } from '@wordpress/hooks'; import { Icon as WPIcon, plusCircleFilled } from '@wordpress/icons'; +import { withSelect } from '@wordpress/data'; import { H, Spinner } from '@woocommerce/components'; import { SETTINGS_STORE_NAME, @@ -28,7 +29,6 @@ import { recordEvent } from '@woocommerce/tracks'; import './style.scss'; import defaultSections from './default-sections'; import Section from './section'; -import withSelect from '../wc-api/with-select'; import ReportFilters from '../analytics/components/report-filters'; import { CurrencyContext, diff --git a/client/dashboard/store-performance/index.js b/client/dashboard/store-performance/index.js index cadae91c876..7d6266744ab 100644 --- a/client/dashboard/store-performance/index.js +++ b/client/dashboard/store-performance/index.js @@ -6,6 +6,7 @@ import { Component, Fragment } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { getPersistedQuery } from '@woocommerce/navigation'; import { getSetting } from '@woocommerce/wc-admin-settings'; +import { withSelect } from '@wordpress/data'; import { SETTINGS_STORE_NAME } from '@woocommerce/data'; import { EllipsisMenu, @@ -22,7 +23,6 @@ import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ -import withSelect from '../../wc-api/with-select'; import './style.scss'; import { CurrencyContext } from '../../lib/currency-context'; import { getIndicatorData, getIndicatorValues } from './utils'; diff --git a/client/header/activity-panel/index.js b/client/header/activity-panel/index.js index b0b241e615a..e0c01a865a4 100644 --- a/client/header/activity-panel/index.js +++ b/client/header/activity-panel/index.js @@ -6,7 +6,7 @@ import clickOutside from 'react-click-outside'; import { Component, lazy, Suspense } from '@wordpress/element'; import { Button } from '@wordpress/components'; import { compose } from '@wordpress/compose'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { uniqueId, find } from 'lodash'; import PagesIcon from 'gridicons/dist/pages'; import CrossIcon from 'gridicons/dist/cross-small'; @@ -29,7 +29,6 @@ import { getUnreadStock, } from './unread-indicators'; import { isWCAdmin } from '../../dashboard/utils'; -import withSelect from '../../wc-api/with-select'; import { Tabs } from './tabs'; import { SetupProgress } from './setup-progress'; diff --git a/client/header/activity-panel/panels/inbox/index.js b/client/header/activity-panel/panels/inbox/index.js index 6be7eb70e26..f2793082b4b 100644 --- a/client/header/activity-panel/panels/inbox/index.js +++ b/client/header/activity-panel/panels/inbox/index.js @@ -5,7 +5,12 @@ import { __ } from '@wordpress/i18n'; import { Fragment, useEffect } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { EmptyContent, Section } from '@woocommerce/components'; -import { NOTES_STORE_NAME, useUserPreferences } from '@woocommerce/data'; +import { + NOTES_STORE_NAME, + useUserPreferences, + QUERY_DEFAULTS, +} from '@woocommerce/data'; +import { withSelect } from '@wordpress/data'; /** * Internal dependencies @@ -14,8 +19,6 @@ import { ActivityCard } from '../../activity-card'; import InboxNotePlaceholder from './placeholder'; import ActivityHeader from '../../activity-header'; import InboxNoteCard from './card'; -import { QUERY_DEFAULTS } from '../../../../wc-api/constants'; -import withSelect from '../../../../wc-api/with-select'; import { getUnreadNotesCount, hasValidNotes } from './utils'; const renderEmptyCard = () => ( diff --git a/client/header/activity-panel/panels/reviews.js b/client/header/activity-panel/panels/reviews.js index 5ae40481670..952d98cef6a 100644 --- a/client/header/activity-panel/panels/reviews.js +++ b/client/header/activity-panel/panels/reviews.js @@ -4,6 +4,7 @@ import { __, sprintf } from '@wordpress/i18n'; import classnames from 'classnames'; import { Component, Fragment } from '@wordpress/element'; +import { withSelect } from '@wordpress/data'; import { Button } from '@wordpress/components'; import Gridicon from 'gridicons'; import interpolateComponents from 'interpolate-components'; @@ -19,7 +20,7 @@ import { Section, } from '@woocommerce/components'; import { getAdminLink } from '@woocommerce/wc-admin-settings'; -import { REVIEWS_STORE_NAME } from '@woocommerce/data'; +import { REVIEWS_STORE_NAME, QUERY_DEFAULTS } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; /** @@ -27,9 +28,7 @@ import { recordEvent } from '@woocommerce/tracks'; */ import { ActivityCard, ActivityCardPlaceholder } from '../activity-card'; import ActivityHeader from '../activity-header'; -import { QUERY_DEFAULTS } from '../../../wc-api/constants'; import sanitizeHTML from '../../../lib/sanitize-html'; -import withSelect from '../../../wc-api/with-select'; class ReviewsPanel extends Component { constructor() { diff --git a/client/homescreen/layout.js b/client/homescreen/layout.js index 3e7bdb6471d..708d21170c3 100644 --- a/client/homescreen/layout.js +++ b/client/homescreen/layout.js @@ -10,7 +10,7 @@ import { useEffect, } from '@wordpress/element'; import { compose } from '@wordpress/compose'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import { NOTES_STORE_NAME, OPTIONS_STORE_NAME } from '@woocommerce/data'; @@ -24,7 +24,6 @@ import './style.scss'; import '../dashboard/style.scss'; import TaskListPlaceholder from '../task-list/placeholder'; import InboxPanel from '../header/activity-panel/panels/inbox'; -import withWCApiSelect from '../wc-api/with-select'; import { WelcomeModal } from './welcome-modal'; const TaskList = lazy( () => @@ -161,7 +160,7 @@ Layout.propTypes = { }; export default compose( - withWCApiSelect( ( select ) => { + withSelect( ( select ) => { const { isNotesRequesting } = select( NOTES_STORE_NAME ); const { getOption, isResolving } = select( OPTIONS_STORE_NAME ); diff --git a/client/homescreen/stats-overview/stats-list.js b/client/homescreen/stats-overview/stats-list.js index 762e841b843..5b07842ffce 100644 --- a/client/homescreen/stats-overview/stats-list.js +++ b/client/homescreen/stats-overview/stats-list.js @@ -3,8 +3,8 @@ */ import { useContext } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { withSelect } from '@wordpress/data'; import classnames from 'classnames'; - import { SummaryNumber, SummaryNumberPlaceholder, @@ -15,7 +15,6 @@ import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ -import withSelect from '../../wc-api/with-select'; import { CurrencyContext } from '../../lib/currency-context'; import { getIndicatorData, diff --git a/client/index.js b/client/index.js index ceb96b9ce8b..8946cb38840 100644 --- a/client/index.js +++ b/client/index.js @@ -13,7 +13,6 @@ import { */ import './stylesheets/_index.scss'; import { PageLayout, EmbedLayout, PrimaryLayout as NoticeArea } from './layout'; -import './wc-api/wp-data-store'; // Modify webpack pubilcPath at runtime based on location of WordPress Plugin. // eslint-disable-next-line no-undef,camelcase diff --git a/client/layout/store-alerts/index.js b/client/layout/store-alerts/index.js index cde07d1b5b8..bc6035c8f2e 100644 --- a/client/layout/store-alerts/index.js +++ b/client/layout/store-alerts/index.js @@ -12,13 +12,12 @@ import moment from 'moment'; import { Icon, chevronLeft, chevronRight } from '@wordpress/icons'; import { Card } from '@woocommerce/components'; import { getSetting } from '@woocommerce/wc-admin-settings'; -import { NOTES_STORE_NAME } from '@woocommerce/data'; +import { NOTES_STORE_NAME, QUERY_DEFAULTS } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ -import { QUERY_DEFAULTS } from '../../wc-api/constants'; import sanitizeHTML from '../../lib/sanitize-html'; import StoreAlertsPlaceholder from './placeholder'; diff --git a/client/layout/transient-notices/index.js b/client/layout/transient-notices/index.js index 639e2f44d9a..ded39b0400c 100644 --- a/client/layout/transient-notices/index.js +++ b/client/layout/transient-notices/index.js @@ -6,13 +6,12 @@ import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import PropTypes from 'prop-types'; import { SnackbarList } from '@wordpress/components'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; /** * Internal dependencies */ import './style.scss'; -import withSelect from '../../wc-api/with-select'; class TransientNotices extends Component { render() { diff --git a/client/lib/async-requests/index.js b/client/lib/async-requests/index.js index f048353f399..3e9f7ae3f14 100644 --- a/client/lib/async-requests/index.js +++ b/client/lib/async-requests/index.js @@ -5,12 +5,12 @@ import { addQueryArgs } from '@wordpress/url'; import apiFetch from '@wordpress/api-fetch'; import { identity } from 'lodash'; import { getIdsFromQuery } from '@woocommerce/navigation'; +import { NAMESPACE } from '@woocommerce/data'; /** * Internal dependencies */ import { getTaxCode } from '../../analytics/report/taxes/utils'; -import { NAMESPACE } from '../../wc-api/constants'; /** * Get a function that accepts ids as they are found in url parameter and diff --git a/client/profile-wizard/index.js b/client/profile-wizard/index.js index 8eed7371837..f287cdd4f4f 100644 --- a/client/profile-wizard/index.js +++ b/client/profile-wizard/index.js @@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n'; import { Component, createElement, Fragment } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { identity, pick } from 'lodash'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { getHistory, getNewPath, @@ -17,6 +17,7 @@ import { OPTIONS_STORE_NAME, PLUGINS_STORE_NAME, withPluginsHydration, + QUERY_DEFAULTS, } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; @@ -28,10 +29,8 @@ import BusinessDetails from './steps/business-details'; import Industry from './steps/industry'; import ProductTypes from './steps/product-types'; import ProfileWizardHeader from './header'; -import { QUERY_DEFAULTS } from '../wc-api/constants'; import StoreDetails from './steps/store-details'; import Theme from './steps/theme'; -import withSelect from '../wc-api/with-select'; import './style.scss'; class ProfileWizard extends Component { diff --git a/client/profile-wizard/steps/industry.js b/client/profile-wizard/steps/industry.js index 433c97aba54..8e2e52a7b24 100644 --- a/client/profile-wizard/steps/industry.js +++ b/client/profile-wizard/steps/industry.js @@ -10,7 +10,7 @@ import { } from '@wordpress/components'; import { compose } from '@wordpress/compose'; import { filter, find, findIndex, get } from 'lodash'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { getSetting } from '@woocommerce/wc-admin-settings'; import { ONBOARDING_STORE_NAME, SETTINGS_STORE_NAME } from '@woocommerce/data'; import { Card, TextControl } from '@woocommerce/components'; @@ -20,7 +20,6 @@ import { recordEvent } from '@woocommerce/tracks'; * Internal dependencies */ import { getCurrencyRegion } from '../../dashboard/utils'; -import withSelect from '../../wc-api/with-select'; const onboarding = getSetting( 'onboarding', {} ); diff --git a/client/profile-wizard/steps/theme/index.js b/client/profile-wizard/steps/theme/index.js index 89daef59d22..eac94ae8457 100644 --- a/client/profile-wizard/steps/theme/index.js +++ b/client/profile-wizard/steps/theme/index.js @@ -13,7 +13,7 @@ import { Tooltip, __experimentalText as Text, } from '@wordpress/components'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { Card, H } from '@woocommerce/components'; import { getSetting, setSetting } from '@woocommerce/wc-admin-settings'; import { ONBOARDING_STORE_NAME } from '@woocommerce/data'; @@ -22,7 +22,6 @@ import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ -import withSelect from '../../../wc-api/with-select'; import './style.scss'; import ThemeUploader from './uploader'; import ThemePreview from './preview'; diff --git a/client/task-list/tasks/appearance.js b/client/task-list/tasks/appearance.js index 77f1c6a2170..ea9e3808966 100644 --- a/client/task-list/tasks/appearance.js +++ b/client/task-list/tasks/appearance.js @@ -16,14 +16,16 @@ import { ImageUpload, } from '@woocommerce/components'; import { getHistory, getNewPath } from '@woocommerce/navigation'; -import { OPTIONS_STORE_NAME, ONBOARDING_STORE_NAME } from '@woocommerce/data'; +import { + OPTIONS_STORE_NAME, + ONBOARDING_STORE_NAME, + WC_ADMIN_NAMESPACE, +} from '@woocommerce/data'; import { queueRecordEvent, recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ -import { WC_ADMIN_NAMESPACE } from '../../wc-api/constants'; - class Appearance extends Component { constructor( props ) { super( props ); diff --git a/client/task-list/tasks/connect.js b/client/task-list/tasks/connect.js index 050c2e8dd24..91cce3fbe3f 100644 --- a/client/task-list/tasks/connect.js +++ b/client/task-list/tasks/connect.js @@ -5,16 +5,10 @@ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import apiFetch from '@wordpress/api-fetch'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { omit } from 'lodash'; import { getHistory, getNewPath } from '@woocommerce/navigation'; -import { ONBOARDING_STORE_NAME } from '@woocommerce/data'; - -/** - * Internal dependencies - */ -import { WC_ADMIN_NAMESPACE } from '../../wc-api/constants'; -import withSelect from '../../wc-api/with-select'; +import { ONBOARDING_STORE_NAME, WC_ADMIN_NAMESPACE } from '@woocommerce/data'; class Connect extends Component { componentDidMount() { diff --git a/client/task-list/tasks/payments/index.js b/client/task-list/tasks/payments/index.js index f7a9313af5c..b20df01195d 100644 --- a/client/task-list/tasks/payments/index.js +++ b/client/task-list/tasks/payments/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; import { cloneElement, Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { Button, FormToggle } from '@wordpress/components'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { Card, H, Plugins } from '@woocommerce/components'; import { getHistory, @@ -27,7 +27,6 @@ import { recordEvent } from '@woocommerce/tracks'; */ import { createNoticesFromResponse } from '../../../lib/notices'; import { getCountryCode } from '../../../dashboard/utils'; -import withSelect from '../../../wc-api/with-select'; import { getPaymentMethods } from './methods'; class Payments extends Component { diff --git a/client/task-list/tasks/payments/methods.js b/client/task-list/tasks/payments/methods.js index 3bb61fd2a95..11fd6de4cfc 100644 --- a/client/task-list/tasks/payments/methods.js +++ b/client/task-list/tasks/payments/methods.js @@ -11,11 +11,7 @@ import { WC_ASSET_URL as wcAssetUrl, } from '@woocommerce/wc-admin-settings'; import { Link } from '@woocommerce/components'; - -/** - * Internal dependencies - */ -import { WC_ADMIN_NAMESPACE } from '../../../wc-api/constants'; +import { WC_ADMIN_NAMESPACE } from '@woocommerce/data'; /** * Internal dependencies diff --git a/client/task-list/tasks/payments/paypal.js b/client/task-list/tasks/payments/paypal.js index fd6697e1a53..50fdf72a108 100644 --- a/client/task-list/tasks/payments/paypal.js +++ b/client/task-list/tasks/payments/paypal.js @@ -11,12 +11,11 @@ import { withDispatch, withSelect } from '@wordpress/data'; import { isEmail } from '@wordpress/url'; import { Form, Link, Stepper, TextControl } from '@woocommerce/components'; import { getQuery } from '@woocommerce/navigation'; -import { PLUGINS_STORE_NAME, OPTIONS_STORE_NAME } from '@woocommerce/data'; - -/** - * Internal dependencies - */ -import { WC_ADMIN_NAMESPACE } from '../../../wc-api/constants'; +import { + PLUGINS_STORE_NAME, + OPTIONS_STORE_NAME, + WC_ADMIN_NAMESPACE, +} from '@woocommerce/data'; export class PayPal extends Component { constructor( props ) { diff --git a/client/task-list/tasks/payments/square.js b/client/task-list/tasks/payments/square.js index f5672b4b5a1..6b0154c3b5f 100644 --- a/client/task-list/tasks/payments/square.js +++ b/client/task-list/tasks/payments/square.js @@ -10,12 +10,7 @@ import { getQuery } from '@woocommerce/navigation'; import { compose } from '@wordpress/compose'; import { Stepper } from '@woocommerce/components'; import { getAdminLink } from '@woocommerce/wc-admin-settings'; -import { OPTIONS_STORE_NAME } from '@woocommerce/data'; - -/** - * Internal dependencies - */ -import { WC_ADMIN_NAMESPACE } from '../../../wc-api/constants'; +import { OPTIONS_STORE_NAME, WC_ADMIN_NAMESPACE } from '@woocommerce/data'; class Square extends Component { constructor( props ) { diff --git a/client/task-list/tasks/payments/stripe.js b/client/task-list/tasks/payments/stripe.js index 8226817ae11..d912b9a2545 100644 --- a/client/task-list/tasks/payments/stripe.js +++ b/client/task-list/tasks/payments/stripe.js @@ -11,12 +11,11 @@ import { Button } from '@wordpress/components'; import { Form, Link, Stepper, TextControl } from '@woocommerce/components'; import { getAdminLink } from '@woocommerce/wc-admin-settings'; import { getQuery } from '@woocommerce/navigation'; -import { PLUGINS_STORE_NAME, OPTIONS_STORE_NAME } from '@woocommerce/data'; - -/** - * Internal dependencies - */ -import { WCS_NAMESPACE } from '../../../wc-api/constants'; +import { + PLUGINS_STORE_NAME, + OPTIONS_STORE_NAME, + WCS_NAMESPACE, +} from '@woocommerce/data'; class Stripe extends Component { constructor( props ) { diff --git a/client/task-list/tasks/shipping/index.js b/client/task-list/tasks/shipping/index.js index 4648454bb71..c7890cdbcad 100644 --- a/client/task-list/tasks/shipping/index.js +++ b/client/task-list/tasks/shipping/index.js @@ -52,7 +52,7 @@ class Shipping extends Component { const { countryCode, countryName } = this.props; // @todo The following fetches for shipping information should be moved into - // the wc-api to make these methods and states more readily available. + // @woocommerce/data to make these methods and states more readily available. const shippingZones = []; const zones = await apiFetch( { path: '/wc/v3/shipping/zones' } ); let hasCountryZone = false; diff --git a/client/wc-api/constants.js b/client/wc-api/constants.js deleted file mode 100644 index df6be3b1963..00000000000 --- a/client/wc-api/constants.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * External dependencies - */ -import { MINUTE } from '@fresh-data/framework'; - -export const JETPACK_NAMESPACE = '/jetpack/v4'; -export const NAMESPACE = '/wc-analytics'; -export const WC_ADMIN_NAMESPACE = '/wc-admin'; -export const WCS_NAMESPACE = '/wc/v1'; // WCS endpoints like Stripe are not avaiable on later /wc versions - -export const DEFAULT_REQUIREMENT = { - timeout: 1 * MINUTE, - freshness: 30 * MINUTE, -}; - -// WordPress & WooCommerce both set a hard limit of 100 for the per_page parameter -export const MAX_PER_PAGE = 100; - -export const DEFAULT_ACTIONABLE_STATUSES = [ 'processing', 'on-hold' ]; - -export const QUERY_DEFAULTS = { - pageSize: 25, - period: 'month', - compare: 'previous_year', - noteTypes: 'info,warning,marketing,survey', -}; diff --git a/client/wc-api/utils.js b/client/wc-api/utils.js deleted file mode 100644 index bbdb0b17b38..00000000000 --- a/client/wc-api/utils.js +++ /dev/null @@ -1,23 +0,0 @@ -export function getResourceName( prefix, identifier ) { - const identifierString = JSON.stringify( - identifier, - Object.keys( identifier ).sort() - ); - return `${ prefix }:${ identifierString }`; -} - -export function getResourcePrefix( resourceName ) { - return resourceName.substring( 0, resourceName.indexOf( ':' ) ); -} - -export function isResourcePrefix( resourceName, prefix ) { - const resourcePrefix = getResourcePrefix( resourceName ); - return resourcePrefix === prefix; -} - -export function getResourceIdentifier( resourceName ) { - const identifierString = resourceName.substring( - resourceName.indexOf( ':' ) + 1 - ); - return JSON.parse( identifierString ); -} diff --git a/client/wc-api/wc-api-spec.js b/client/wc-api/wc-api-spec.js deleted file mode 100644 index ef2a0a92296..00000000000 --- a/client/wc-api/wc-api-spec.js +++ /dev/null @@ -1,20 +0,0 @@ -function createWcApiSpec() { - return { - name: 'wcApi', - mutations: {}, - selectors: {}, - operations: { - read() { - return []; - }, - update() { - return []; - }, - updateLocally() { - return []; - }, - }, - }; -} - -export default createWcApiSpec(); diff --git a/client/wc-api/with-select.js b/client/wc-api/with-select.js deleted file mode 100644 index 855012db1bd..00000000000 --- a/client/wc-api/with-select.js +++ /dev/null @@ -1,218 +0,0 @@ -/** - * NOTE: This is temporary code. It exists only until a version of `@wordpress/data` - * is released which supports this functionality. - * - * @todo Remove this and use `@wordpress/data` `withSelect` instead after - * this PR is merged: https://github.com/WordPress/gutenberg/pull/11460 - */ - -/** - * External dependencies - */ -import { isFunction } from 'lodash'; -import { Component } from '@wordpress/element'; -import isShallowEqual from '@wordpress/is-shallow-equal'; -import { createHigherOrderComponent } from '@wordpress/compose'; -import { RegistryConsumer } from '@wordpress/data'; - -/** - * Higher-order component used to inject state-derived props using registered - * selectors. - * - * @param {Function} mapSelectToProps Function called on every state change, - * expected to return object of props to - * merge with the component's own props. - * - * @return {Component} Enhanced component with merged state data props. - */ -const withSelect = ( mapSelectToProps ) => - createHigherOrderComponent( ( WrappedComponent ) => { - /** - * Default merge props. A constant value is used as the fallback since it - * can be more efficiently shallow compared in case component is repeatedly - * rendered without its own merge props. - * - * @type {Object} - */ - const DEFAULT_MERGE_PROPS = {}; - - class ComponentWithSelect extends Component { - constructor( props ) { - super( props ); - - this.onStoreChange = this.onStoreChange.bind( this ); - this.subscribe( props.registry ); - - this.onUnmounts = {}; - this.mergeProps = this.getNextMergeProps( props ); - } - - /** - * Given a props object, returns the next merge props by mapSelectToProps. - * - * @param {Object} props Props to pass as argument to mapSelectToProps. - * - * @return {Object} Props to merge into rendered wrapped element. - */ - getNextMergeProps( props ) { - const storeSelectors = {}; - const onCompletes = []; - const componentContext = { component: this }; - - const getStoreFromRegistry = ( key, registry, context ) => { - // This is our first time selecting from this store. - // Do some lazy-loading of handling at this time. - const selectorsForKey = registry.select( key ); - - if ( isFunction( selectorsForKey ) ) { - // This store has special handling for its selectors. - // We give it a context, and we check for a "resolve" - const { - selectors, - onComplete, - onUnmount, - } = selectorsForKey( context ); - if ( onComplete ) { - onCompletes.push( onComplete ); - } - if ( onUnmount ) { - this.onUnmounts[ key ] = onUnmount; - } - storeSelectors[ key ] = selectors; - } else { - storeSelectors[ key ] = selectorsForKey; - } - }; - - const select = ( key ) => { - if ( ! storeSelectors[ key ] ) { - getStoreFromRegistry( - key, - props.registry, - componentContext - ); - } - - return storeSelectors[ key ]; - }; - - const selectedProps = - mapSelectToProps( select, props.ownProps ) || - DEFAULT_MERGE_PROPS; - - // Complete the select for those stores which support it. - onCompletes.forEach( ( onComplete ) => onComplete() ); - return selectedProps; - } - - componentDidMount() { - this.canRunSelection = true; - - // A state change may have occurred between the constructor and - // mount of the component (e.g. during the wrapped component's own - // constructor), in which case selection should be rerun. - if ( this.hasQueuedSelection ) { - this.hasQueuedSelection = false; - this.onStoreChange(); - } - } - - componentWillUnmount() { - this.canRunSelection = false; - this.unsubscribe(); - Object.keys( this.onUnmounts ).forEach( ( key ) => - this.onUnmounts[ key ]() - ); - } - - shouldComponentUpdate( nextProps, nextState ) { - // Cycle subscription if registry changes. - const hasRegistryChanged = - nextProps.registry !== this.props.registry; - if ( hasRegistryChanged ) { - this.unsubscribe(); - this.subscribe( nextProps.registry ); - } - - // Treat a registry change as equivalent to `ownProps`, to reflect - // `mergeProps` to rendered component if and only if updated. - const hasPropsChanged = - hasRegistryChanged || - ! isShallowEqual( this.props.ownProps, nextProps.ownProps ); - - // Only render if props have changed or merge props have been updated - // from the store subscriber. - if ( this.state === nextState && ! hasPropsChanged ) { - return false; - } - - if ( hasPropsChanged ) { - const nextMergeProps = this.getNextMergeProps( nextProps ); - if ( ! isShallowEqual( this.mergeProps, nextMergeProps ) ) { - // If merge props change as a result of the incoming props, - // they should be reflected as such in the upcoming render. - // While side effects are discouraged in lifecycle methods, - // this component is used heavily, and prior efforts to use - // `getDerivedStateFromProps` had demonstrated miserable - // performance. - this.mergeProps = nextMergeProps; - } - - // Regardless whether merge props are changing, fall through to - // incur the render since the component will need to receive - // the changed `ownProps`. - } - - return true; - } - - onStoreChange() { - if ( ! this.canRunSelection ) { - this.hasQueuedSelection = true; - return; - } - - const nextMergeProps = this.getNextMergeProps( this.props ); - if ( isShallowEqual( this.mergeProps, nextMergeProps ) ) { - return; - } - - this.mergeProps = nextMergeProps; - - // Schedule an update. Merge props are not assigned to state since - // derivation of merge props from incoming props occurs within - // shouldComponentUpdate, where setState is not allowed. setState - // is used here instead of forceUpdate because forceUpdate bypasses - // shouldComponentUpdate altogether, which isn't desireable if both - // state and props change within the same render. Unfortunately, - // this requires that next merge props are generated twice. - this.setState( {} ); - } - - subscribe( registry ) { - this.unsubscribe = registry.subscribe( this.onStoreChange ); - } - - render() { - return ( - - ); - } - } - - return ( ownProps ) => ( - - { ( registry ) => ( - - ) } - - ); - }, 'withSelect' ); - -export default withSelect; diff --git a/client/wc-api/wp-data-store/create-api-client.js b/client/wc-api/wp-data-store/create-api-client.js deleted file mode 100644 index 6220be09d89..00000000000 --- a/client/wc-api/wp-data-store/create-api-client.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * External dependencies - */ -import { ApiClient } from '@fresh-data/framework'; -import { createStore as createReduxStore } from 'redux'; - -/** - * Internal dependencies - */ -import reducer from './reducer'; - -function createStore( name ) { - const devTools = window.__REDUX_DEVTOOLS_EXTENSION__; - - return createReduxStore( - reducer, - devTools && devTools( { name, instanceId: name } ) - ); -} - -function createDataHandlers( store ) { - return { - dataRequested: ( resourceNames ) => { - // This is a temporary fix until it can be resolved upstream in fresh-data. - // See: https://github.com/woocommerce/woocommerce-admin/pull/2387/files#r292355276 - if ( document.hidden ) { - return; - } - - store.dispatch( { - type: 'FRESH_DATA_REQUESTED', - resourceNames, - time: new Date(), - } ); - }, - dataReceived: ( resources ) => { - store.dispatch( { - type: 'FRESH_DATA_RECEIVED', - resources, - time: new Date(), - } ); - }, - }; -} - -function createApiClient( name, apiSpec ) { - const store = createStore( name ); - const dataHandlers = createDataHandlers( store ); - const apiClient = new ApiClient( apiSpec ); - apiClient.setDataHandlers( dataHandlers ); - - const storeChanged = () => { - apiClient.setState( store.getState() ); - }; - store.subscribe( storeChanged ); - - return apiClient; -} - -export default createApiClient; diff --git a/client/wc-api/wp-data-store/create-store.js b/client/wc-api/wp-data-store/create-store.js deleted file mode 100644 index a76eecab3e1..00000000000 --- a/client/wc-api/wp-data-store/create-store.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * External dependencies - */ -import { createStore } from 'redux'; - -/** - * Internal dependencies - */ -import reducer from './reducer'; - -export default ( name ) => { - const devTools = window.__REDUX_DEVTOOLS_EXTENSION__; - - return createStore( - reducer, - devTools && devTools( { name, instanceId: name } ) - ); -}; diff --git a/client/wc-api/wp-data-store/index.js b/client/wc-api/wp-data-store/index.js deleted file mode 100644 index c6f7992cacc..00000000000 --- a/client/wc-api/wp-data-store/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * External dependencies - */ -import { registerGenericStore } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import createApiClient from './create-api-client'; -import wcApiSpec from '../wc-api-spec'; - -if ( process.env.NODE_ENV === 'development' ) { - window.__FRESH_DATA_DEV_INFO__ = true; -} - -function createWcApiStore() { - const apiClient = createApiClient( 'wc-api', wcApiSpec ); - - function getComponentSelectors( component ) { - const componentRequirements = []; - - return { - selectors: apiClient.getSelectors( componentRequirements ), - onComplete: () => { - if ( componentRequirements.length === 0 ) { - apiClient.clearComponentRequirements( component ); - } else { - apiClient.setComponentRequirements( - component, - componentRequirements - ); - } - }, - onUnmount: () => { - apiClient.clearComponentRequirements( component ); - }, - }; - } - - return { - // The wrapped function for getSelectors is temporary code. - // - // @todo Remove the `() =>` after the `@wordpress/data` PR is merged: - // https://github.com/WordPress/gutenberg/pull/11460 - // - getSelectors: () => ( context ) => { - const component = - context && context.component ? context.component : context; - return getComponentSelectors( component ); - }, - getActions() { - const mutations = apiClient.getMutations(); - return mutations; - }, - subscribe: apiClient.subscribe, - }; -} - -registerGenericStore( 'wc-api', createWcApiStore() ); diff --git a/client/wc-api/wp-data-store/reducer.js b/client/wc-api/wp-data-store/reducer.js deleted file mode 100644 index 36beb707800..00000000000 --- a/client/wc-api/wp-data-store/reducer.js +++ /dev/null @@ -1,61 +0,0 @@ -const defaultState = { - resources: {}, -}; - -/** - * Primary reducer for fresh-data apiclient data. - * - * @param {Object} state The base state for fresh-data. - * @param {Object} action Action object to be processed. - * @return {Object} The new state, or the previous state if this action doesn't belong to fresh-data. - */ -export default function reducer( state = defaultState, action ) { - switch ( action.type ) { - case 'FRESH_DATA_REQUESTED': - return reduceRequested( state, action ); - case 'FRESH_DATA_RECEIVED': - return reduceReceived( state, action ); - default: - return state; - } -} - -export function reduceRequested( state, action ) { - const newResources = action.resourceNames.reduce( ( resources, name ) => { - resources[ name ] = { lastRequested: action.time }; - return resources; - }, {} ); - return reduceResources( state, newResources ); -} - -export function reduceReceived( state, action ) { - const newResources = Object.keys( action.resources ).reduce( - ( resources, name ) => { - const resource = { ...action.resources[ name ] }; - if ( resource.data ) { - resource.lastReceived = action.time; - } - if ( resource.error ) { - resource.lastError = action.time; - } - resources[ name ] = resource; - return resources; - }, - {} - ); - return reduceResources( state, newResources ); -} - -export function reduceResources( state, newResources ) { - const updatedResources = Object.keys( newResources ).reduce( - ( resources, resourceName ) => { - const resource = resources[ resourceName ]; - const newResource = newResources[ resourceName ]; - resources[ resourceName ] = { ...resource, ...newResource }; - return resources; - }, - { ...state.resources } - ); - - return { ...state, resources: updatedResources }; -} diff --git a/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js b/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js index ed5806bc19b..c97e804869d 100644 --- a/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js +++ b/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js @@ -9,7 +9,7 @@ import interpolateComponents from 'interpolate-components'; import PropTypes from 'prop-types'; import { get, isArray } from 'lodash'; import { PLUGINS_STORE_NAME } from '@woocommerce/data'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; import { getSetting } from '@woocommerce/wc-admin-settings'; import { recordEvent } from '@woocommerce/tracks'; @@ -18,7 +18,6 @@ import { recordEvent } from '@woocommerce/tracks'; */ import '../style.scss'; import DismissModal from '../dismiss-modal'; -import withSelect from '../../../wc-api/with-select'; import SetupNotice, { setupErrorTypes } from '../setup-notice'; import { getWcsAssets, acceptWcsTos } from '../wcs-api'; diff --git a/package-lock.json b/package-lock.json index f3761fa1826..96244529f00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1699,14 +1699,6 @@ } } }, - "@fresh-data/framework": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/@fresh-data/framework/-/framework-0.6.1.tgz", - "integrity": "sha512-UCaLX/WgLPputWvfnB2IK0Im3f78hrut+2epLoG2MqP7GRnM7vFzxYfQdCdIocP+SqtkKSwPaJwwTeHMeVFvBg==", - "requires": { - "@babel/runtime": "^7.4.2" - } - }, "@hapi/address": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz", diff --git a/package.json b/package.json index ec1fd202319..d64b6d87341 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,6 @@ ] }, "dependencies": { - "@fresh-data/framework": "0.6.1", "@wordpress/api-fetch": "2.2.8", "@wordpress/base-styles": "2.0.0", "@wordpress/components": "10.0.0", diff --git a/packages/data/src/index.js b/packages/data/src/index.js index c2db4fe0133..1bb77c97b72 100644 --- a/packages/data/src/index.js +++ b/packages/data/src/index.js @@ -34,7 +34,16 @@ export { getTooltipValueFormat, } from './reports/utils'; -export { MAX_PER_PAGE, QUERY_DEFAULTS } from './constants'; +export { + MAX_PER_PAGE, + QUERY_DEFAULTS, + NAMESPACE, + WC_ADMIN_NAMESPACE, + WCS_NAMESPACE, + SECOND, + MINUTE, + HOUR, +} from './constants'; export { EXPORT_STORE_NAME } from './export';