Skip to content

Commit

Permalink
Replace with the dynamic source values from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
htdat committed Dec 20, 2024
1 parent 9cea0e4 commit cee5b6c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions client/data/transactions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ interface TransactionsSummary {
currency?: string;
store_currencies?: string[];
customer_currencies?: string[];
sources?: Transaction[ 'source' ][];
};
isLoading: boolean;
}
Expand Down
8 changes: 3 additions & 5 deletions client/transactions/filters/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export const getFilters = (

/*eslint-disable max-len*/
export const getAdvancedFilters = (
customerCurrencyOptions?: TransactionsFilterEntryType[]
customerCurrencyOptions?: TransactionsFilterEntryType[],
transactionSourceOptions?: TransactionsFilterEntryType[]
): any => {
// TODO: Remove this and all the checks once we drop support of WooCommerce 7.7 and below.
const wooCommerceVersionString = getSetting( 'wcVersion' );
Expand Down Expand Up @@ -312,10 +313,7 @@ export const getAdvancedFilters = (
],
input: {
component: 'SelectControl',
options: [
{ label: 'card label', value: 'card' },
{ label: 'giropay label', value: 'giropay' },
], // @todo change to real options.
options: transactionSourceOptions,
},
},
type: {
Expand Down
14 changes: 12 additions & 2 deletions client/transactions/filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,35 @@ import { getQuery } from '@woocommerce/navigation';
import { getFilters, getAdvancedFilters } from './config';
import { formatCurrencyName } from 'multi-currency/interface/functions';
import { recordEvent } from 'tracks';
import { PAYMENT_METHOD_TITLES } from 'wcpay/constants/payment-method';
import { Transaction } from 'wcpay/data';

interface TransactionsFiltersProps {
storeCurrencies: string[];
customerCurrencies: string[];
transactionSources?: Transaction[ 'source' ][];
}

export const TransactionsFilters = ( {
storeCurrencies,
customerCurrencies,
transactionSources,
}: TransactionsFiltersProps ): JSX.Element => {
const advancedFilters = useMemo(
() =>
getAdvancedFilters(
customerCurrencies.map( ( currencyCode: string ) => ( {
label: formatCurrencyName( currencyCode ),
value: currencyCode,
} ) )
} ) ),
typeof transactionSources === 'undefined'
? []
: transactionSources.map( ( source ) => ( {
label: PAYMENT_METHOD_TITLES[ source ] || source,
value: source,
} ) )
),
[ customerCurrencies ]
[ customerCurrencies, transactionSources ]
);

const filters = useMemo(
Expand Down
2 changes: 2 additions & 0 deletions client/transactions/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,15 @@ export const TransactionsList = (
transactionsSummary.store_currencies ||
( isCurrencyFiltered ? [ getQuery().store_currency_is ?? '' ] : [] );
const customerCurrencies = transactionsSummary.customer_currencies || [];
const transactionSources = transactionsSummary.sources || [];

return (
<Page>
{ showFilters && (
<TransactionsFilters
storeCurrencies={ storeCurrencies }
customerCurrencies={ customerCurrencies }
transactionSources={ transactionSources }
/>
) }
<TableCard
Expand Down

0 comments on commit cee5b6c

Please sign in to comment.