From 5dcea1af6f225b7513540ca9b8ba66445720ba03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 17 Jan 2019 19:07:21 +0100 Subject: [PATCH] Remove wc-api customers (https://github.com/woocommerce/woocommerce-admin/pull/1338) --- .../client/wc-api/customers/index.js | 11 ----- .../client/wc-api/customers/operations.js | 47 ------------------- .../client/wc-api/customers/selectors.js | 43 ----------------- .../client/wc-api/wc-api-spec.js | 3 -- 4 files changed, 104 deletions(-) delete mode 100644 plugins/woocommerce-admin/client/wc-api/customers/index.js delete mode 100644 plugins/woocommerce-admin/client/wc-api/customers/operations.js delete mode 100644 plugins/woocommerce-admin/client/wc-api/customers/selectors.js diff --git a/plugins/woocommerce-admin/client/wc-api/customers/index.js b/plugins/woocommerce-admin/client/wc-api/customers/index.js deleted file mode 100644 index cd0cff2f807..00000000000 --- a/plugins/woocommerce-admin/client/wc-api/customers/index.js +++ /dev/null @@ -1,11 +0,0 @@ -/** @format */ -/** - * Internal dependencies - */ -import operations from './operations'; -import selectors from './selectors'; - -export default { - operations, - selectors, -}; diff --git a/plugins/woocommerce-admin/client/wc-api/customers/operations.js b/plugins/woocommerce-admin/client/wc-api/customers/operations.js deleted file mode 100644 index 54f8bf7e2cb..00000000000 --- a/plugins/woocommerce-admin/client/wc-api/customers/operations.js +++ /dev/null @@ -1,47 +0,0 @@ -/** @format */ -/** - * External dependencies - */ -import apiFetch from '@wordpress/api-fetch'; - -/** - * WooCommerce dependencies - */ -import { stringifyQuery } from '@woocommerce/navigation'; - -/** - * Internal dependencies - */ -import { isResourcePrefix, getResourceIdentifier, getResourceName } from '../utils'; -import { NAMESPACE } from '../constants'; - -function read( resourceNames, fetch = apiFetch ) { - const filteredNames = resourceNames.filter( name => isResourcePrefix( name, 'customers-query' ) ); - - return filteredNames.map( async resourceName => { - const query = getResourceIdentifier( resourceName ); - const url = `${ NAMESPACE }/customers${ stringifyQuery( query ) }`; - - try { - const customers = await fetch( { path: url } ); - const ids = customers.map( customer => customer.id ); - const customerResources = customers.reduce( ( resources, customer ) => { - resources[ getResourceName( 'customer', customer.id ) ] = { data: customer }; - return resources; - }, {} ); - - return { - [ resourceName ]: { - data: ids, - }, - ...customerResources, - }; - } catch ( error ) { - return { [ resourceName ]: { error } }; - } - } ); -} - -export default { - read, -}; diff --git a/plugins/woocommerce-admin/client/wc-api/customers/selectors.js b/plugins/woocommerce-admin/client/wc-api/customers/selectors.js deleted file mode 100644 index bb72925b7f5..00000000000 --- a/plugins/woocommerce-admin/client/wc-api/customers/selectors.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @format */ - -/** - * External dependencies - */ -import { isNil } from 'lodash'; - -/** - * Internal dependencies - */ -import { getResourceName } from '../utils'; -import { DEFAULT_REQUIREMENT } from '../constants'; - -const getCustomers = ( getResource, requireResource ) => ( - query = {}, - requirement = DEFAULT_REQUIREMENT -) => { - const resourceName = getResourceName( 'customers-query', query ); - const ids = requireResource( requirement, resourceName ).data || []; - return ids.map( id => getResource( getResourceName( 'customer', id ) ).data || {} ); -}; - -const getCustomersError = getResource => ( query = {} ) => { - const resourceName = getResourceName( 'customers-query', query ); - return getResource( resourceName ).error; -}; - -const isGetCustomersRequesting = getResource => ( query = {} ) => { - const resourceName = getResourceName( 'customers-query', query ); - const { lastRequested, lastReceived } = getResource( resourceName ); - - if ( isNil( lastRequested ) || isNil( lastReceived ) ) { - return true; - } - - return lastRequested > lastReceived; -}; - -export default { - getCustomers, - getCustomersError, - isGetCustomersRequesting, -}; diff --git a/plugins/woocommerce-admin/client/wc-api/wc-api-spec.js b/plugins/woocommerce-admin/client/wc-api/wc-api-spec.js index b14f3a5ef07..df38ee4a4ef 100644 --- a/plugins/woocommerce-admin/client/wc-api/wc-api-spec.js +++ b/plugins/woocommerce-admin/client/wc-api/wc-api-spec.js @@ -4,7 +4,6 @@ * Internal dependencies */ import categories from './categories'; -import customers from './customers'; import notes from './notes'; import orders from './orders'; import reportItems from './reports/items'; @@ -19,7 +18,6 @@ function createWcApiSpec() { }, selectors: { ...categories.selectors, - ...customers.selectors, ...notes.selectors, ...orders.selectors, ...reportItems.selectors, @@ -31,7 +29,6 @@ function createWcApiSpec() { read( resourceNames ) { return [ ...categories.operations.read( resourceNames ), - ...customers.operations.read( resourceNames ), ...notes.operations.read( resourceNames ), ...orders.operations.read( resourceNames ), ...reportItems.operations.read( resourceNames ),