diff --git a/changelog/fix-use-type-is-in-filter b/changelog/fix-use-type-is-in-filter new file mode 100644 index 00000000000..3639b203c36 --- /dev/null +++ b/changelog/fix-use-type-is-in-filter @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Support 'type_is_in' filter for Transactions list report, to allow easy filtering by multiple types. diff --git a/client/components/payment-activity/payment-activity-data.tsx b/client/components/payment-activity/payment-activity-data.tsx index 255770e587f..7731ecfb5b1 100644 --- a/client/components/payment-activity/payment-activity-data.tsx +++ b/client/components/payment-activity/payment-activity-data.tsx @@ -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', @@ -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, } ), {} ); @@ -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" @@ -169,8 +169,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( { ) .add( siteTimeZone ) .format( 'YYYY-MM-DD' ), - ...getSearchParams( - searchTermsForViewReportLink.charge + ...getTypeFilters( + typeFiltersForViewReportLink.charge ), } ) } tracksSource="charges" @@ -196,8 +196,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( { ) .add( siteTimeZone ) .format( 'YYYY-MM-DD' ), - ...getSearchParams( - searchTermsForViewReportLink.refunds + ...getTypeFilters( + typeFiltersForViewReportLink.refunds ), } ) } tracksSource="refunds" @@ -250,8 +250,8 @@ const PaymentActivityDataComponent: React.FC< Props > = ( { ) .add( siteTimeZone ) .format( 'YYYY-MM-DD' ), - ...getSearchParams( - searchTermsForViewReportLink.dispute + ...getTypeFilters( + typeFiltersForViewReportLink.dispute ), } ) } tracksSource="disputes" diff --git a/client/components/payment-activity/test/__snapshots__/index.test.tsx.snap b/client/components/payment-activity/test/__snapshots__/index.test.tsx.snap index fd5ac782458..c4d9d6d7087 100644 --- a/client/components/payment-activity/test/__snapshots__/index.test.tsx.snap +++ b/client/components/payment-activity/test/__snapshots__/index.test.tsx.snap @@ -123,7 +123,7 @@ exports[`PaymentActivity component should render 1`] = `

View report @@ -183,7 +183,7 @@ exports[`PaymentActivity component should render 1`] = `

View report @@ -212,7 +212,7 @@ exports[`PaymentActivity component should render 1`] = `

View report @@ -269,7 +269,7 @@ exports[`PaymentActivity component should render 1`] = `

View report diff --git a/client/data/transactions/hooks.ts b/client/data/transactions/hooks.ts index e65ba57a03f..0b860612dc9 100644 --- a/client/data/transactions/hooks.ts +++ b/client/data/transactions/hooks.ts @@ -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, @@ -189,6 +190,7 @@ export const useTransactions = ( ), typeIs, typeIsNot, + typeIsIn, sourceDeviceIs, sourceDeviceIsNot, storeCurrencyIs, @@ -222,6 +224,7 @@ export const useTransactions = ( JSON.stringify( dateBetween ), typeIs, typeIsNot, + JSON.stringify( typeIsIn ), sourceDeviceIs, sourceDeviceIsNot, storeCurrencyIs, @@ -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, @@ -276,6 +280,7 @@ export const useTransactionsSummary = ( dateBetween, typeIs, typeIsNot, + typeIsIn, sourceDeviceIs, sourceDeviceIsNot, storeCurrencyIs, @@ -304,6 +309,7 @@ export const useTransactionsSummary = ( JSON.stringify( dateBetween ), typeIs, typeIsNot, + JSON.stringify( typeIsIn ), sourceDeviceIs, sourceDeviceIsNot, storeCurrencyIs, diff --git a/client/data/transactions/resolvers.js b/client/data/transactions/resolvers.js index d2d6cab6cfb..77e517bdf6d 100644 --- a/client/data/transactions/resolvers.js +++ b/client/data/transactions/resolvers.js @@ -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, diff --git a/client/transactions/declarations.d.ts b/client/transactions/declarations.d.ts index 08ff94e4892..1ee8fe71627 100644 --- a/client/transactions/declarations.d.ts +++ b/client/transactions/declarations.d.ts @@ -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; diff --git a/client/transactions/filters/config.ts b/client/transactions/filters/config.ts index b6e3c34f534..b5552654494 100644 --- a/client/transactions/filters/config.ts +++ b/client/transactions/filters/config.ts @@ -99,6 +99,7 @@ export const getFilters = ( 'filter', 'type_is', 'type_is_not', + 'type_is_in', 'date_before', 'date_after', 'date_between', diff --git a/includes/core/server/request/class-list-transactions.php b/includes/core/server/request/class-list-transactions.php index 4a2b998622e..3f369df29ba 100644 --- a/includes/core/server/request/class-list-transactions.php +++ b/includes/core/server/request/class-list-transactions.php @@ -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' ),