chore(2559): filter ledger entries by account type (#2631)

* chore: ledger entries - add account type filters

* chore: ledger entries filtering - add int test

* chore: ledger entries filtering - fix linter fails

* chore: ledger entries filtering - fix int test failing

* chore: ledger entries filtering - fix int test failing
This commit is contained in:
macqbat 2023-01-17 14:44:23 +01:00 committed by GitHub
parent 8eebd814ae
commit 5e97391d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 17 deletions

View File

@ -51,6 +51,7 @@ const generateProposal = (code: string): ProposalListFieldsFragment => ({
describe('home', { tags: '@regression' }, () => { describe('home', { tags: '@regression' }, () => {
beforeEach(() => { beforeEach(() => {
cy.clearLocalStorage();
cy.mockTradingPage(); cy.mockTradingPage();
cy.mockSubscription(); cy.mockSubscription();
}); });
@ -226,9 +227,6 @@ describe('home', { tags: '@regression' }, () => {
}); });
describe('redirect should take last visited market into consideration', () => { describe('redirect should take last visited market into consideration', () => {
beforeEach(() => {
cy.clearLocalStorage();
});
it('marketId comes from existing market', () => { it('marketId comes from existing market', () => {
cy.window().then((window) => { cy.window().then((window) => {
window.localStorage.setItem('marketId', 'market-1'); window.localStorage.setItem('marketId', 'market-1');

View File

@ -37,5 +37,21 @@ describe('Portfolio page', { tags: '@smoke' }, () => {
'[data-testid="tab-ledger-entries"] .ag-center-cols-container .ag-row' '[data-testid="tab-ledger-entries"] .ag-center-cols-container .ag-row'
).should('have.length', ledgerEntriesQuery().ledgerEntries.edges.length); ).should('have.length', ledgerEntriesQuery().ledgerEntries.edges.length);
}); });
it('account filters should be callable', () => {
cy.visit('/#/portfolio');
cy.getByTestId('"Ledger entries"').click();
cy.get('[role="columnheader"][col-id="senderAccountType"]').realHover();
cy.get(
'[role="columnheader"][col-id="senderAccountType"] .ag-header-cell-menu-button'
).click();
cy.get('fieldset.ag-simple-filter-body-wrapper')
.should('be.visible')
.within((fields) => {
cy.wrap(fields).find('label').should('have.length', 16);
});
cy.getByTestId('"Ledger entries"').click();
cy.get('fieldset.ag-simple-filter-body-wrapper').should('not.exist');
});
}); });
}); });

View File

@ -28,6 +28,7 @@ export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
// Replace http with ws, preserving if its a secure connection eg. https => wss // Replace http with ws, preserving if its a secure connection eg. https => wss
urlWS.protocol = urlWS.protocol.replace('http', 'ws'); urlWS.protocol = urlWS.protocol.replace('http', 'ws');
const timeoutLink = new ApolloLinkTimeout(10000); const timeoutLink = new ApolloLinkTimeout(10000);
const enlargedTimeoutLink = new ApolloLinkTimeout(100000);
const retryLink = new RetryLink({ const retryLink = new RetryLink({
delay: { delay: {
initial: 300, initial: 300,
@ -76,8 +77,14 @@ export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
} }
}); });
const composedTimeoutLink = split(
({ getContext }) => Boolean(getContext()['isEnlargedTimeout']),
enlargedTimeoutLink,
timeoutLink
);
return new ApolloClient({ return new ApolloClient({
link: from([errorLink, timeoutLink, retryLink, splitLink]), link: from([errorLink, composedTimeoutLink, retryLink, splitLink]),
cache: new InMemoryCache(cacheConfig), cache: new InMemoryCache(cacheConfig),
}); });
} }

View File

@ -15,11 +15,19 @@ query LedgerEntries(
$partyId: ID! $partyId: ID!
$pagination: Pagination $pagination: Pagination
$dateRange: DateRange $dateRange: DateRange
$senderAccountType: [AccountType!]
$receiverAccountType: [AccountType!]
) { ) {
ledgerEntries( ledgerEntries(
filter: { filter: {
SenderAccountFilter: { partyIds: [$partyId] } SenderAccountFilter: {
ReceiverAccountFilter: { partyIds: [$partyId] } partyIds: [$partyId]
accountTypes: $senderAccountType
}
ReceiverAccountFilter: {
partyIds: [$partyId]
accountTypes: $receiverAccountType
}
} }
pagination: $pagination pagination: $pagination
dateRange: $dateRange dateRange: $dateRange

View File

@ -9,6 +9,8 @@ export type LedgerEntriesQueryVariables = Types.Exact<{
partyId: Types.Scalars['ID']; partyId: Types.Scalars['ID'];
pagination?: Types.InputMaybe<Types.Pagination>; pagination?: Types.InputMaybe<Types.Pagination>;
dateRange?: Types.InputMaybe<Types.DateRange>; dateRange?: Types.InputMaybe<Types.DateRange>;
senderAccountType?: Types.InputMaybe<Array<Types.AccountType> | Types.AccountType>;
receiverAccountType?: Types.InputMaybe<Array<Types.AccountType> | Types.AccountType>;
}>; }>;
@ -29,9 +31,9 @@ export const LedgerEntryFragmentDoc = gql`
} }
`; `;
export const LedgerEntriesDocument = gql` export const LedgerEntriesDocument = gql`
query LedgerEntries($partyId: ID!, $pagination: Pagination, $dateRange: DateRange) { query LedgerEntries($partyId: ID!, $pagination: Pagination, $dateRange: DateRange, $senderAccountType: [AccountType!], $receiverAccountType: [AccountType!]) {
ledgerEntries( ledgerEntries(
filter: {SenderAccountFilter: {partyIds: [$partyId]}, ReceiverAccountFilter: {partyIds: [$partyId]}} filter: {SenderAccountFilter: {partyIds: [$partyId], accountTypes: $senderAccountType}, ReceiverAccountFilter: {partyIds: [$partyId], accountTypes: $receiverAccountType}}
pagination: $pagination pagination: $pagination
dateRange: $dateRange dateRange: $dateRange
) { ) {
@ -65,6 +67,8 @@ export const LedgerEntriesDocument = gql`
* partyId: // value for 'partyId' * partyId: // value for 'partyId'
* pagination: // value for 'pagination' * pagination: // value for 'pagination'
* dateRange: // value for 'dateRange' * dateRange: // value for 'dateRange'
* senderAccountType: // value for 'senderAccountType'
* receiverAccountType: // value for 'receiverAccountType'
* }, * },
* }); * });
*/ */

View File

@ -106,6 +106,9 @@ const ledgerEntriesOnlyProvider = makeDataProvider({
append, append,
first: 100, first: 100,
}, },
additionalContext: {
isEnlargedTimeout: true,
},
}); });
export const ledgerEntriesProvider = makeDerivedDataProvider< export const ledgerEntriesProvider = makeDerivedDataProvider<
@ -147,6 +150,8 @@ export const useLedgerEntriesDataProvider = ({
() => ({ () => ({
partyId, partyId,
dateRange: filter?.vegaTime?.value, dateRange: filter?.vegaTime?.value,
senderAccountType: filter?.senderAccountType?.value ?? null,
receiverAccountType: filter?.receiverAccountType?.value ?? null,
}), }),
[partyId, filter] [partyId, filter]
); );

View File

@ -3,14 +3,17 @@ import type * as Schema from '@vegaprotocol/types';
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit'; import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
import type { FilterChangedEvent } from 'ag-grid-community'; import type { FilterChangedEvent } from 'ag-grid-community';
import type { AgGridReact } from 'ag-grid-react'; import type { AgGridReact } from 'ag-grid-react';
import { useRef, useState } from 'react'; import { useCallback, useRef, useState } from 'react';
import { useLedgerEntriesDataProvider } from './ledger-entries-data-provider'; import { useLedgerEntriesDataProvider } from './ledger-entries-data-provider';
import { LedgerTable } from './ledger-table'; import { LedgerTable } from './ledger-table';
import type * as Types from '@vegaprotocol/types';
export interface Filter { export interface Filter {
vegaTime?: { vegaTime?: {
value: Schema.DateRange; value: Schema.DateRange;
}; };
senderAccountType?: { value: Types.AccountType[] };
receiverAccountType?: { value: Types.AccountType[] };
} }
type LedgerManagerProps = { partyId: string }; type LedgerManagerProps = { partyId: string };
@ -24,14 +27,17 @@ export const LedgerManager = ({ partyId }: LedgerManagerProps) => {
gridRef, gridRef,
}); });
const onFilterChanged = (event: FilterChangedEvent) => { const onFilterChanged = useCallback(
const updatedFilter = event.api.getFilterModel(); (event: FilterChangedEvent) => {
if (Object.keys(updatedFilter).length) { const updatedFilter = event.api.getFilterModel();
setFilter(updatedFilter); if (Object.keys(updatedFilter).length) {
} else if (filter) { setFilter(updatedFilter);
setFilter(undefined); } else if (filter) {
} setFilter(undefined);
}; }
},
[filter]
);
return ( return (
<div className="h-full relative"> <div className="h-full relative">

View File

@ -3,6 +3,7 @@ import {
DateRangeFilter, DateRangeFilter,
fromNanoSeconds, fromNanoSeconds,
getDateTimeFormat, getDateTimeFormat,
SetFilter,
t, t,
truncateByChars, truncateByChars,
} from '@vegaprotocol/react-helpers'; } from '@vegaprotocol/react-helpers';
@ -50,6 +51,7 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
resizable: true, resizable: true,
sortable: true, sortable: true,
tooltipComponent: TransferTooltipCellComponent, tooltipComponent: TransferTooltipCellComponent,
filterParams: { buttons: ['reset'] },
}} }}
{...props} {...props}
> >
@ -64,6 +66,10 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
/> />
<AgGridColumn <AgGridColumn
headerName={t('Account type')} headerName={t('Account type')}
filter={SetFilter}
filterParams={{
set: AccountTypeMapping,
}}
field="senderAccountType" field="senderAccountType"
cellRenderer={({ cellRenderer={({
value, value,
@ -92,6 +98,10 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
/> />
<AgGridColumn <AgGridColumn
headerName={t('Account type')} headerName={t('Account type')}
filter={SetFilter}
filterParams={{
set: AccountTypeMapping,
}}
field="receiverAccountType" field="receiverAccountType"
cellRenderer={({ cellRenderer={({
value, value,

View File

@ -171,6 +171,7 @@ interface DataProviderParams<
}; };
fetchPolicy?: FetchPolicy; fetchPolicy?: FetchPolicy;
resetDelay?: number; resetDelay?: number;
additionalContext?: Record<string, unknown>;
} }
/** /**
@ -196,6 +197,7 @@ function makeDataProviderInternal<
pagination, pagination,
fetchPolicy, fetchPolicy,
resetDelay, resetDelay,
additionalContext,
}: DataProviderParams< }: DataProviderParams<
QueryData, QueryData,
Data, Data,
@ -275,6 +277,7 @@ function makeDataProviderInternal<
pagination: paginationVariables, pagination: paginationVariables,
}, },
fetchPolicy: fetchPolicy || 'no-cache', fetchPolicy: fetchPolicy || 'no-cache',
context: additionalContext,
}); });
const insertionData = getData(res.data, variables); const insertionData = getData(res.data, variables);
const insertionPageInfo = pagination.getPageInfo(res.data); const insertionPageInfo = pagination.getPageInfo(res.data);
@ -311,6 +314,7 @@ function makeDataProviderInternal<
? { ...variables, pagination: { first: pagination.first } } ? { ...variables, pagination: { first: pagination.first } }
: variables, : variables,
fetchPolicy: fetchPolicy || 'no-cache', fetchPolicy: fetchPolicy || 'no-cache',
context: additionalContext,
}); });
data = getData(res.data, variables); data = getData(res.data, variables);
if (data && pagination) { if (data && pagination) {