From 50035467e8a9dd57508bfcfb93df84149c7b1a47 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Wed, 13 Mar 2024 16:02:41 -0500 Subject: [PATCH] Improve donations tab responsiveness --- .../ContactDonationsTab.test.tsx | 42 +++++++------ .../ContactDonationsTab.tsx | 36 +++++------ .../DonationsGraph/DonationsGraph.test.tsx | 61 +++++++++++-------- .../DonationsGraph/DonationsGraph.tsx | 52 ++++++++-------- .../DonationTable/DonationTable.tsx | 8 ++- src/components/Layouts/SidePanelsLayout.tsx | 2 +- 6 files changed, 105 insertions(+), 96 deletions(-) diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.test.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.test.tsx index 38984e339..20d7f305c 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.test.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.test.tsx @@ -1,5 +1,7 @@ import React from 'react'; +import { ThemeProvider } from '@mui/material/styles'; import { DateTime } from 'luxon'; +import theme from 'src/theme'; import { GqlMockedProvider } from '../../../../../__tests__/util/graphqlMocking'; import { render } from '../../../../../__tests__/util/testingLibraryReactMock'; import { ContactDetailProvider } from '../ContactDetailContext'; @@ -12,27 +14,29 @@ const contactId = 'contact-id-1'; describe('ContactDonationsTab', () => { it('test renderer', async () => { const { findByRole } = render( - - mocks={{ - GetContactDonations: { - contact: { - nextAsk: DateTime.now().plus({ month: 5 }).toISO(), - pledgeStartDate: DateTime.now().minus({ month: 5 }).toISO(), - pledgeCurrency: 'USD', - lastDonation: { - donationDate: DateTime.now().toISO(), + + + mocks={{ + GetContactDonations: { + contact: { + nextAsk: DateTime.now().plus({ month: 5 }).toISO(), + pledgeStartDate: DateTime.now().minus({ month: 5 }).toISO(), + pledgeCurrency: 'USD', + lastDonation: { + donationDate: DateTime.now().toISO(), + }, }, }, - }, - }} - > - - - - , + }} + > + + + + + , ); expect(await findByRole('region')).toBeVisible(); }); diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx index d6e8c1cee..260a9e6c6 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx @@ -29,10 +29,6 @@ const DonationsTabContainer = styled(Box)(({ theme }) => ({ borderBottom: '1px solid #DCDCDC', })); -const DonationsGraphContainer = styled(Box)(({ theme }) => ({ - margin: theme.spacing(1), -})); - const DonationsTabList = styled(TabList)(({}) => ({ minHeight: 40, })); @@ -100,23 +96,21 @@ export const ContactDonationsTab: React.FC = ({ }; return ( - - {loading ? ( - <> - - - - - ) : ( - - )} - + {loading ? ( + <> + + + + + ) : ( + + )} ({ + ...jest.requireActual('recharts'), + ResponsiveContainer: ({ children }) => ({ + ...children, + props: { + ...children.props, + height: 600, + width: 300, + }, + }), +})); + const accountListId = 'account-list-id'; const donorAccountIds = ['donor-Account-Id']; const currency = 'USD'; + describe('Donations Graph', () => { + beforeEach(() => { + beforeTestResizeObserver(); + }); + + afterEach(() => { + afterTestResizeObserver(); + }); + it('test renderer', async () => { - const { findByRole } = render( + const { findByText } = render( mocks={{ GetDonationsGraph: { @@ -43,35 +67,20 @@ describe('Donations Graph', () => { /> , ); - expect(await findByRole('textbox')).toBeVisible(); + expect(await findByText('Amount (USD)')).toBeInTheDocument(); }); - it('test loading renderer', async () => { - const { findByRole } = render( - + it('renders loading placeholders while loading data', () => { + const { getByLabelText } = render( + - , + , ); - expect(await findByRole('alert')).toBeVisible(); + expect(getByLabelText('Loading donations graph')).toBeInTheDocument(); }); it('test query', async () => { diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx index 2168ab0d5..d6b999c0c 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx @@ -10,30 +10,22 @@ import { BarChart, CartesianGrid, Legend, + ResponsiveContainer, + Text, Tooltip, XAxis, YAxis, } from 'recharts'; import { useLocale } from 'src/hooks/useLocale'; import { currencyFormat } from 'src/lib/intlFormat'; -import theme from '../../../../../theme'; +import theme from 'src/theme'; import { useGetDonationsGraphQuery } from './DonationsGraph.generated'; -const LegendText = styled(Typography)(({ theme }) => ({ - margin: theme.spacing(3, 0), - writingMode: 'vertical-rl', - textOrientation: 'mixed', -})); - const GraphContainer = styled(Box)(({ theme }) => ({ - display: 'flex', - margin: theme.spacing(0, 2, 0, 0), -})); - -const GraphLoadingPlaceHolder = styled(Skeleton)(({ theme }) => ({ - width: '400', - height: '24px', - margin: theme.spacing(2, 0), + height: 300, + marginBottom: theme.spacing(2), + padding: theme.spacing(1), + overflowX: 'scroll', })); interface DonationsGraphProps { @@ -108,22 +100,26 @@ export const DonationsGraph: React.FC = ({ })} )} - + {loading ? ( - - - - - + ) : ( - <> - - {t('Amount ({{amount}})', { amount: convertedCurrency })} - - + + - + + {t('Amount ({{amount}})', { amount: convertedCurrency })} + + } + /> = ({ fill={theme.palette.secondary.main} /> - + )} diff --git a/src/components/DonationTable/DonationTable.tsx b/src/components/DonationTable/DonationTable.tsx index b4f40f2cd..bd7af1d6b 100644 --- a/src/components/DonationTable/DonationTable.tsx +++ b/src/components/DonationTable/DonationTable.tsx @@ -205,26 +205,29 @@ export const DonationTable: React.FC = ({ { field: 'date', headerName: t('Date'), - minWidth: 80, flex: 1, + minWidth: 80, renderCell: date, }, { field: 'donorAccountName', headerName: t('Partner'), flex: 3, + minWidth: 200, renderCell: donor, }, { field: 'convertedAmount', headerName: t('Amount'), flex: 1, + minWidth: 120, renderCell: amount, }, { field: 'foreignAmount', headerName: t('Foreign Amount'), flex: 1.5, + minWidth: 120, renderCell: foreignAmount, hideable: false, }, @@ -232,16 +235,19 @@ export const DonationTable: React.FC = ({ field: 'designationAccount', headerName: t('Designation'), flex: 3, + minWidth: 200, }, { field: 'paymentMethod', headerName: t('Method'), flex: 1, + minWidth: 100, }, { field: 'appeal', headerName: t('Appeal'), flex: 1, + minWidth: 100, renderCell: appeal, }, { diff --git a/src/components/Layouts/SidePanelsLayout.tsx b/src/components/Layouts/SidePanelsLayout.tsx index 56763e606..ad4d6d770 100644 --- a/src/components/Layouts/SidePanelsLayout.tsx +++ b/src/components/Layouts/SidePanelsLayout.tsx @@ -115,7 +115,7 @@ export const SidePanelsLayout: FC = ({ headerHeight = '0px', }) => { const isMobile = useMediaQuery((theme: Theme) => - theme.breakpoints.down('sm'), + theme.breakpoints.down('md'), ); return (