Skip to content

Commit

Permalink
fix(explorer): update tx navigation for 0.74.0 (#5662)
Browse files Browse the repository at this point in the history
  • Loading branch information
edd authored Jan 24, 2024
1 parent 261f32a commit 27a9d5f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 65 deletions.
49 changes: 0 additions & 49 deletions apps/explorer/src/app/components/txs/tx-list-navigation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,53 +61,4 @@ describe('TxsListNavigation', () => {

expect(nextPageMock).toHaveBeenCalledTimes(1);
});

it('disables "Older" button if hasMoreTxs is false', () => {
render(
<TxsListNavigation
refreshTxs={NOOP}
nextPage={NOOP}
previousPage={NOOP}
hasMoreTxs={false}
hasPreviousPage={false}
>
<span></span>
</TxsListNavigation>
);

expect(screen.getByText('Older')).toBeDisabled();
});

it('disables "Newer" button if hasPreviousPage is false', () => {
render(
<TxsListNavigation
refreshTxs={NOOP}
nextPage={NOOP}
previousPage={NOOP}
hasMoreTxs={true}
hasPreviousPage={false}
>
<span></span>
</TxsListNavigation>
);

expect(screen.getByText('Newer')).toBeDisabled();
});

it('disables both buttons when more and previous are false', () => {
render(
<TxsListNavigation
refreshTxs={NOOP}
nextPage={NOOP}
previousPage={NOOP}
hasMoreTxs={false}
hasPreviousPage={false}
>
<span></span>
</TxsListNavigation>
);

expect(screen.getByText('Newer')).toBeDisabled();
expect(screen.getByText('Older')).toBeDisabled();
});
});
9 changes: 4 additions & 5 deletions apps/explorer/src/app/components/txs/tx-list-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface TxListNavigationProps {
loading?: boolean;
hasPreviousPage: boolean;
hasMoreTxs: boolean;
children: React.ReactNode;
children?: React.ReactNode;
isEmpty?: boolean;
}
/**
* Displays a list of transactions with filters and controls to navigate through the list.
Expand All @@ -21,9 +22,8 @@ export const TxsListNavigation = ({
refreshTxs,
nextPage,
previousPage,
hasMoreTxs,
hasPreviousPage,
children,
isEmpty,
loading = false,
}: TxListNavigationProps) => {
return (
Expand All @@ -35,7 +35,6 @@ export const TxsListNavigation = ({
<Button
className="mr-2"
size="xs"
disabled={!hasPreviousPage || loading}
onClick={() => {
previousPage();
}}
Expand All @@ -44,7 +43,7 @@ export const TxsListNavigation = ({
</Button>
<Button
size="xs"
disabled={!hasMoreTxs}
disabled={isEmpty}
onClick={() => {
nextPage();
}}
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/app/hooks/get-txs-data-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getTxsDataUrl = (params: IGetTxsDataUrl) => {
url.searchParams.append('first', count);
url.searchParams.append('after', params.after);
} else {
url.searchParams.append('last', count);
url.searchParams.append('first', count);
}

// Hacky fix for param as array
Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/app/hooks/get-txs-data-urls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('getTxsDataUrl', () => {
count: 10,
baseUrl: 'https://example.com/transactions',
};
const expectedUrl = 'https://example.com/transactions?last=10';
const expectedUrl = 'https://example.com/transactions?first=10';

expect(getTxsDataUrl(params)).toEqual(expectedUrl);
});
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('getTxsDataUrl', () => {
baseUrl: 'https://example.com/transactions',
};
const expectedUrl =
'https://example.com/transactions?last=10&filters[cmd.type]=Made%20Up%20Transaction&filters[tx.submitter]=1234';
'https://example.com/transactions?first=10&filters[cmd.type]=Made%20Up%20Transaction&filters[tx.submitter]=1234';

expect(getTxsDataUrl(params)).toEqual(expectedUrl);
});
Expand Down
12 changes: 6 additions & 6 deletions apps/explorer/src/app/hooks/use-txs-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export interface IUseTxsData {
}

export const useTxsData = ({
count = 25,
count = 50,
before,
after,
filters,
party,
}: IUseTxsData) => {
const [, setSearchParams] = useSearchParams();
let hasMoreTxs = true;
let hasMoreTxs = false;
let txsData: BlockExplorerTransactionResult[] = [];

const url = getTxsDataUrl({
Expand All @@ -60,17 +60,17 @@ export const useTxsData = ({
}

const nextPage = useCallback(() => {
const after = data?.transactions.at(-1)?.cursor || '';
const params: URLSearchParamsInit = { after };
const before = data?.transactions.at(-1)?.cursor || '';
const params: URLSearchParamsInit = { before };
if (filters) {
params.filters = Array.from(filters).join(',');
}
setSearchParams(params);
}, [filters, data, setSearchParams]);

const previousPage = useCallback(() => {
const before = data?.transactions[0]?.cursor || '';
const params: URLSearchParamsInit = { before };
const after = data?.transactions[0]?.cursor || '';
const params: URLSearchParamsInit = { after };
if (filters && filters.size > 0 && filters.size === 1) {
params.filters = Array.from(filters)[0];
}
Expand Down
14 changes: 12 additions & 2 deletions apps/explorer/src/app/routes/txs/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export const TxsListFiltered = () => {
refreshTxs={refreshTxs}
nextPage={nextPage}
previousPage={previousPage}
hasPreviousPage={true}
hasPreviousPage={hasMoreTxs}
loading={loading}
hasMoreTxs={hasMoreTxs}
isEmpty={txsData.length === 0}
>
<TxsFilter
filters={filters}
Expand All @@ -70,7 +71,16 @@ export const TxsListFiltered = () => {
txs={txsData}
loadMoreTxs={nextPage}
error={error}
className="mb-28 w-full min-w-[400px]"
className="mb-4 w-full min-w-[400px]"
/>
<TxsListNavigation
refreshTxs={refreshTxs}
nextPage={nextPage}
previousPage={previousPage}
hasPreviousPage={hasMoreTxs}
loading={loading}
hasMoreTxs={hasMoreTxs}
isEmpty={txsData.length === 0}
/>
</>
);
Expand Down

0 comments on commit 27a9d5f

Please sign in to comment.