-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Reporting API in components (#8589)
Co-authored-by: Jessy <[email protected]> Co-authored-by: Naman Malhotra <[email protected]> Co-authored-by: Nagesh Pai <[email protected]> Co-authored-by: Shendy <[email protected]> Co-authored-by: Eric Jinks <[email protected]>
- Loading branch information
1 parent
1b9b52a
commit 45719a0
Showing
25 changed files
with
533 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Not user-facing: hidden behind feature flag. Use Reporting API to fetch and populate data in the Payment Activity widget. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface DateRange { | ||
date_start: string; // Start date | ||
date_end: string; // End date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @format */ | ||
|
||
export default { | ||
SET_PAYMENT_ACTIVITY_DATA: 'SET_PAYMENT_ACTIVITY_DATA', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import TYPES from './action-types'; | ||
import { PaymentActivityData, PaymentActivityAction } from './types'; | ||
|
||
export function updatePaymentActivity( | ||
data: PaymentActivityData | ||
): PaymentActivityAction { | ||
return { | ||
type: TYPES.SET_PAYMENT_ACTIVITY_DATA, | ||
data, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** @format */ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { STORE_NAME } from '../constants'; | ||
import { PaymentActivityState, PaymentActivityQuery } from './types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const usePaymentActivityData = ( | ||
query: PaymentActivityQuery | ||
): PaymentActivityState => | ||
useSelect( ( select ) => { | ||
const { getPaymentActivityData, isResolving } = select( STORE_NAME ); | ||
|
||
return { | ||
paymentActivityData: getPaymentActivityData( query ), | ||
isLoading: isResolving( 'getPaymentActivityData', [ query ] ), | ||
}; | ||
}, [] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import reducer from './reducer'; | ||
import * as selectors from './selectors'; | ||
import * as actions from './actions'; | ||
import * as resolvers from './resolvers'; | ||
|
||
export { reducer, selectors, actions, resolvers }; | ||
export * from './hooks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TYPES from './action-types'; | ||
import { PaymentActivityAction, PaymentActivityState } from './types'; | ||
|
||
const receivePaymentActivity = ( | ||
state: PaymentActivityState = {}, | ||
{ type, data }: PaymentActivityAction | ||
): PaymentActivityState => { | ||
switch ( type ) { | ||
case TYPES.SET_PAYMENT_ACTIVITY_DATA: | ||
state = { | ||
...state, | ||
paymentActivityData: data, | ||
}; | ||
break; | ||
} | ||
return state; | ||
}; | ||
|
||
export default receivePaymentActivity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { apiFetch } from '@wordpress/data-controls'; | ||
import { controls } from '@wordpress/data'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { NAMESPACE } from '../constants'; | ||
import { updatePaymentActivity } from './actions'; | ||
import { PaymentActivityData, QueryDate } from './types'; | ||
|
||
/** | ||
* Retrieves payment activity data from the reporting API. | ||
* | ||
* @param {string} query Data on which to parameterize the selection. | ||
*/ | ||
export function* getPaymentActivityData( | ||
query: QueryDate | ||
): Generator< unknown > { | ||
const path = addQueryArgs( | ||
`${ NAMESPACE }/reporting/payment_activity`, | ||
query | ||
); | ||
|
||
try { | ||
const results = yield apiFetch( { path } ); | ||
|
||
yield updatePaymentActivity( results as PaymentActivityData ); | ||
} catch ( e ) { | ||
yield controls.dispatch( | ||
'core/notices', | ||
'createErrorNotice', | ||
__( | ||
'Error retrieving payment activity data.', | ||
'woocommerce-payments' | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { State } from 'wcpay/data/types'; | ||
import { PaymentActivityData } from './types'; | ||
|
||
export const getPaymentActivityData = ( state: State ): PaymentActivityData => { | ||
return state?.paymentActivity?.paymentActivityData || {}; | ||
}; |
Oops, something went wrong.