Skip to content

Commit

Permalink
retrieve full transaction list
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelhox committed Feb 1, 2023
1 parent bb3dab8 commit 5d816e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/ui/src/components/export_csv/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import dayjs from '@/utils/dayjs';
import { AsyncParser } from '@json2csv/node';
import { unwind, flatten } from '@json2csv/transforms';
import { stringQuoteOnlyIfNecessary as stringQuoteOnlyIfNecessaryFormatter } from '@json2csv/formatters';
// eslint-disable-next-line import/no-cycle
import { CSVButtonTypes } from '@/components/export_csv';

export const useMessageDetailsHook = (transactions: Transactions[]) => {
export const useMessageDetailsHook = ({
transactions,
loadMoreItems,
hasNextPage,
}: CSVButtonTypes) => {
const [csv, setCSV] = React.useState<unknown[]>();

const items = transactions.map((x) => ({
Expand Down Expand Up @@ -95,9 +101,12 @@ export const useMessageDetailsHook = (transactions: Transactions[]) => {
};

React.useEffect(() => {
if (hasNextPage) {
loadMoreItems();
}
convertToCSVString(JSON.stringify(items), options);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [items, transactions]);
}, [items, transactions, hasNextPage]);

return csv;
};
17 changes: 14 additions & 3 deletions packages/ui/src/components/export_csv/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import UploadFileOutlinedIcon from '@mui/icons-material/UploadFileOutlined';
import FileSaver from 'file-saver';
import useStyles from '@/components/export_csv/styles';
import type { TransactionsListState } from '@/components/transactions_list/types';
// eslint-disable-next-line import/no-cycle
import { useMessageDetailsHook } from './hooks';

const ExportCSVButton: FC<TransactionsListState> = (props) => {
const { transactions } = props;
export interface CSVButtonTypes extends TransactionsListState {
loadMoreItems: (() => Promise<void>) | (() => null);
hasNextPage: boolean;
}

const ExportCSVButton: FC<CSVButtonTypes> = (props) => {
const { transactions, itemCount, hasNextPage, loadMoreItems = () => null } = props;
const { classes } = useStyles();
const csv = useMessageDetailsHook(transactions);
const csv = useMessageDetailsHook({
transactions,
itemCount,
loadMoreItems,
hasNextPage,
});

const handleCSVExport = () => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ const Transactions: FC<ComponentDefault> = (props) => {
return (
<Box className={cx(classes.root, props.className)}>
<Typography variant="h2">{t('transactions')}</Typography>
<ExportCSVButton transactions={state.data} itemCount={itemCount} />
<ExportCSVButton
transactions={state.data}
itemCount={itemCount}
loadMoreItems={loadMoreItems}
isItemLoaded={isItemLoaded}
hasNextPage={state.hasNextPage}
/>
<div className={classes.list}>
{txListFormat === 'compact' ? (
<TransactionsList
Expand Down

0 comments on commit 5d816e3

Please sign in to comment.