Skip to content

Commit

Permalink
Use type_is_in filter from the client to filter by multiple transac…
Browse files Browse the repository at this point in the history
…tion types. (#9871)

Co-authored-by: Jessy <jessy.pappachan@automattic.com>
Co-authored-by: Nagesh Pai <4162931+nagpai@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 1fc7a8a commit b1f9861
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-use-type-is-in-filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Support 'type_is_in' filter for Transactions list report, to allow easy filtering by multiple types.
24 changes: 12 additions & 12 deletions client/components/payment-activity/payment-activity-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getAdminUrl } from 'wcpay/utils';
import type { PaymentActivityData } from 'wcpay/data/payment-activity/types';
import './style.scss';

const searchTermsForViewReportLink = {
const typeFiltersForViewReportLink = {
totalPaymentVolume: [
'charge',
'payment',
Expand All @@ -43,11 +43,11 @@ const searchTermsForViewReportLink = {
dispute: [ 'dispute', 'dispute_reversal' ],
};

const getSearchParams = ( searchTerms: string[] ) => {
return searchTerms.reduce(
const getTypeFilters = ( types: string[] ) => {
return types.reduce(
( acc, term, index ) => ( {
...acc,
[ `search[${ index }]` ]: term,
[ `type_is_in[${ index }]` ]: term,
} ),
{}
);
Expand Down Expand Up @@ -122,8 +122,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( {
'date_between[1]': moment( paymentActivityData?.date_end )
.add( siteTimeZone )
.format( 'YYYY-MM-DD' ),
...getSearchParams(
searchTermsForViewReportLink.totalPaymentVolume
...getTypeFilters(
typeFiltersForViewReportLink.totalPaymentVolume
),
} ) }
tracksSource="total_payment_volume"
Expand Down Expand Up @@ -169,8 +169,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( {
)
.add( siteTimeZone )
.format( 'YYYY-MM-DD' ),
...getSearchParams(
searchTermsForViewReportLink.charge
...getTypeFilters(
typeFiltersForViewReportLink.charge
),
} ) }
tracksSource="charges"
Expand All @@ -196,8 +196,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( {
)
.add( siteTimeZone )
.format( 'YYYY-MM-DD' ),
...getSearchParams(
searchTermsForViewReportLink.refunds
...getTypeFilters(
typeFiltersForViewReportLink.refunds
),
} ) }
tracksSource="refunds"
Expand Down Expand Up @@ -250,8 +250,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( {
)
.add( siteTimeZone )
.format( 'YYYY-MM-DD' ),
...getSearchParams(
searchTermsForViewReportLink.dispute
...getTypeFilters(
typeFiltersForViewReportLink.dispute
),
} ) }
tracksSource="disputes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ exports[`PaymentActivity component should render 1`] = `
</p>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&search%5B0%5D=charge&search%5B1%5D=payment&search%5B2%5D=payment_failure_refund&search%5B3%5D=payment_refund&search%5B4%5D=refund&search%5B5%5D=refund_failure&search%5B6%5D=dispute&search%5B7%5D=dispute_reversal&search%5B8%5D=card_reader_fee&search%5B9%5D=adjustment"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&type_is_in%5B0%5D=charge&type_is_in%5B1%5D=payment&type_is_in%5B2%5D=payment_failure_refund&type_is_in%5B3%5D=payment_refund&type_is_in%5B4%5D=refund&type_is_in%5B5%5D=refund_failure&type_is_in%5B6%5D=dispute&type_is_in%5B7%5D=dispute_reversal&type_is_in%5B8%5D=card_reader_fee&type_is_in%5B9%5D=adjustment"
>
View report
</a>
Expand Down Expand Up @@ -183,7 +183,7 @@ exports[`PaymentActivity component should render 1`] = `
</p>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&search%5B0%5D=charge&search%5B1%5D=payment&search%5B2%5D=adjustment"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&type_is_in%5B0%5D=charge&type_is_in%5B1%5D=payment&type_is_in%5B2%5D=adjustment"
>
View report
</a>
Expand Down Expand Up @@ -212,7 +212,7 @@ exports[`PaymentActivity component should render 1`] = `
</p>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&search%5B0%5D=refund&search%5B1%5D=refund_failure&search%5B2%5D=payment_refund&search%5B3%5D=payment_failure_refund"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&type_is_in%5B0%5D=refund&type_is_in%5B1%5D=refund_failure&type_is_in%5B2%5D=payment_refund&type_is_in%5B3%5D=payment_failure_refund"
>
View report
</a>
Expand Down Expand Up @@ -269,7 +269,7 @@ exports[`PaymentActivity component should render 1`] = `
</p>
<a
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&search%5B0%5D=dispute&search%5B1%5D=dispute_reversal"
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions&filter=advanced&store_currency_is=eur&date_between%5B0%5D=2024-01-01&date_between%5B1%5D=2024-01-31&type_is_in%5B0%5D=dispute&type_is_in%5B1%5D=dispute_reversal"
>
View report
</a>
Expand Down
6 changes: 6 additions & 0 deletions client/data/transactions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const useTransactions = (
date_between: dateBetween,
type_is: typeIs,
type_is_not: typeIsNot,
type_is_in: typeIsIn,
source_device_is: sourceDeviceIs,
source_device_is_not: sourceDeviceIsNot,
channel_is: channelIs,
Expand Down Expand Up @@ -189,6 +190,7 @@ export const useTransactions = (
),
typeIs,
typeIsNot,
typeIsIn,
sourceDeviceIs,
sourceDeviceIsNot,
storeCurrencyIs,
Expand Down Expand Up @@ -222,6 +224,7 @@ export const useTransactions = (
JSON.stringify( dateBetween ),
typeIs,
typeIsNot,
JSON.stringify( typeIsIn ),
sourceDeviceIs,
sourceDeviceIsNot,
storeCurrencyIs,
Expand All @@ -247,6 +250,7 @@ export const useTransactionsSummary = (
date_between: dateBetween,
type_is: typeIs,
type_is_not: typeIsNot,
type_is_in: typeIsIn,
source_device_is: sourceDeviceIs,
source_device_is_not: sourceDeviceIsNot,
store_currency_is: storeCurrencyIs,
Expand Down Expand Up @@ -276,6 +280,7 @@ export const useTransactionsSummary = (
dateBetween,
typeIs,
typeIsNot,
typeIsIn,
sourceDeviceIs,
sourceDeviceIsNot,
storeCurrencyIs,
Expand Down Expand Up @@ -304,6 +309,7 @@ export const useTransactionsSummary = (
JSON.stringify( dateBetween ),
typeIs,
typeIsNot,
JSON.stringify( typeIsIn ),
sourceDeviceIs,
sourceDeviceIsNot,
storeCurrencyIs,
Expand Down
1 change: 1 addition & 0 deletions client/data/transactions/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const formatQueryFilters = ( query ) => ( {
],
type_is: query.typeIs,
type_is_not: query.typeIsNot,
type_is_in: query.typeIsIn,
source_device_is: query.sourceDeviceIs,
source_device_is_not: query.sourceDeviceIsNot,
channel_is: query.channelIs,
Expand Down
1 change: 1 addition & 0 deletions client/transactions/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ declare module '@woocommerce/navigation' {
date_between?: string[];
type_is?: unknown;
type_is_not?: unknown;
type_is_in?: unknown;
source_device_is?: unknown;
source_device_is_not?: unknown;
channel_is?: string;
Expand Down
1 change: 1 addition & 0 deletions client/transactions/filters/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const getFilters = (
'filter',
'type_is',
'type_is_not',
'type_is_in',
'date_before',
'date_after',
'date_between',
Expand Down
1 change: 1 addition & 0 deletions includes/core/server/request/class-list-transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function ( $transaction_date ) use ( $user_timezone ) {
'date_between' => $date_between_filter,
'type_is' => $request->get_param( 'type_is' ),
'type_is_not' => $request->get_param( 'type_is_not' ),
'type_is_in' => (array) $request->get_param( 'type_is_in' ),
'source_device_is' => $request->get_param( 'source_device_is' ),
'source_device_is_not' => $request->get_param( 'source_device_is_not' ),
'channel_is' => $request->get_param( 'channel_is' ),
Expand Down

0 comments on commit b1f9861

Please sign in to comment.