From da838005d56f1a01568592adb33c05c6e2f2c297 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Thu, 14 Mar 2024 14:34:49 -0500 Subject: [PATCH] Merge donations graph loading skeletons --- .../ContactDonationsTab.tsx | 44 +++++++++---------- .../DonationsGraph/DonationsGraph.test.tsx | 13 ++++++ .../DonationsGraph/DonationsGraph.tsx | 8 ++-- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx index 260a9e6c6..7c0e73624 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/ContactDonationsTab.tsx @@ -43,8 +43,8 @@ const DonationsTab = styled(Tab)(({ theme }) => ({ '&:hover': { opacity: 1 }, })); -const ContactDonationsLoadingPlaceHolder = styled(Skeleton)(({ theme }) => ({ - width: '100%', +const PartnershipInfoLoadingPlaceHolder = styled(Skeleton)(({ theme }) => ({ + width: '20em', height: '24px', margin: theme.spacing(2, 0), })); @@ -78,10 +78,9 @@ export const ContactDonationsTab: React.FC = ({ contactId: contactId, }, }); - const donorAccountIds = - data?.contact.contactDonorAccounts.nodes.map( - (donor) => donor.donorAccount.id, - ) ?? []; + const donorAccountIds = data?.contact.contactDonorAccounts.nodes.map( + (donor) => donor.donorAccount.id, + ); const { t } = useTranslation(); @@ -96,21 +95,11 @@ export const ContactDonationsTab: React.FC = ({ }; return ( - {loading ? ( - <> - - - - - ) : ( - - )} + = ({ {loading ? ( <> - - - + + + + + + + + + + ) : ( diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.test.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.test.tsx index aa15f6393..69f608603 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.test.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.test.tsx @@ -83,6 +83,19 @@ describe('Donations Graph', () => { expect(getByLabelText('Loading donations graph')).toBeInTheDocument(); }); + it('renders loading placeholders while waiting for donorAccountIds', async () => { + const { getByLabelText } = render( + + + , + ); + expect(getByLabelText('Loading donations graph')).toBeInTheDocument(); + }); + it('test query', async () => { const { result, waitForNextUpdate } = renderHook( () => diff --git a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx index d6b999c0c..e2e8fb16d 100644 --- a/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx +++ b/src/components/Contacts/ContactDetails/ContactDonationsTab/DonationsGraph/DonationsGraph.tsx @@ -30,8 +30,8 @@ const GraphContainer = styled(Box)(({ theme }) => ({ interface DonationsGraphProps { accountListId: string; - donorAccountIds: string[]; - convertedCurrency: string; + donorAccountIds: string[] | undefined; + convertedCurrency: string | undefined; } export const DonationsGraph: React.FC = ({ @@ -41,11 +41,13 @@ export const DonationsGraph: React.FC = ({ }) => { const { t } = useTranslation(); const locale = useLocale(); + const skipped = !donorAccountIds; const { data, loading } = useGetDonationsGraphQuery({ variables: { accountListId: accountListId, donorAccountIds: donorAccountIds, }, + skip: skipped, }); const monthFormatter = useMemo( @@ -101,7 +103,7 @@ export const DonationsGraph: React.FC = ({ )} - {loading ? ( + {loading || skipped ? (