Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use type_is_in filter from the client to filter by multiple transaction types. #9871

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading