From ec6bcc62cb56b4c510dae0008b2f542f97c4d58d Mon Sep 17 00:00:00 2001 From: Jeff Clay <91073628+jeff-clay@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:18:16 -0800 Subject: [PATCH 1/6] Add partner phone and email to address change CSV Co-Authored-By: Claude Opus 5.5 --- .../AddressChangeHistory.graphql | 2 ++ .../ChangeHistoryAddressesMock.ts | 2 ++ .../downloadAddressChanges.test.ts | 16 ++++++++++++++++ .../ExportCsvButton/downloadAddressChanges.ts | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql index 6c353db7c..79663a387 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql @@ -21,6 +21,8 @@ query AddressChangeHistory( partnerName partnerStatus donorAccountNumbers + partnerPhone + partnerEmail street city state diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesMock.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesMock.ts index c0b0e57f3..a3e3cd272 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesMock.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesMock.ts @@ -29,6 +29,8 @@ export const mockAddressChanges: AddressChangeRow[] = [ partnerName: 'Dalmation, Pongo and Perdita', partnerStatus: StatusEnum.PartnerFinancial, donorAccountNumbers: '10001', + partnerPhone: '(206) 555-0100', + partnerEmail: 'pongo@example.com', street: '2125 6th Ave W', city: 'Seattle', state: 'WA', diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.test.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.test.ts index 7ae317840..246c8191e 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.test.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.test.ts @@ -29,6 +29,8 @@ describe('createAddressChangesCsv', () => { 'Address', 'Previous Address', 'Made by', + 'Primary phone (current)', + 'Primary email (current)', ]); expect(rows[1]).toEqual([ 'Sep 30, 2026', @@ -38,6 +40,8 @@ describe('createAddressChangesCsv', () => { '2125 6th Ave W, Seattle, WA 98119', '98 Lake St, Seattle, WA 98109', 'Automatic update from US Donation Services', + '(206) 555-0100', + 'pongo@example.com', ]); }); @@ -53,6 +57,18 @@ describe('createAddressChangesCsv', () => { expect(rows[6][1]).toBe('Doe, John and Jane'); expect(rows[6][5]).toBe(''); }); + + it('leaves the phone and email blank when the partner has none', () => { + const rows = createAddressChangesCsv({ + addressChanges: mockAddressChanges, + currentUserId, + getStatusLabel, + t: i18n.t, + locale: 'en-US', + }); + + expect(rows[6].slice(-2)).toEqual(['', '']); + }); }); describe('downloadAddressChanges', () => { diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.ts index 8ea91a124..f34617aed 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ExportCsvButton/downloadAddressChanges.ts @@ -32,6 +32,8 @@ export const createAddressChangesCsv = ({ t('Address'), t('Previous Address'), t('Made by'), + t('Primary phone (current)'), + t('Primary email (current)'), ], ...addressChanges.map((addressChange) => [ dateFormat(DateTime.fromISO(addressChange.date), locale), @@ -45,6 +47,8 @@ export const createAddressChangesCsv = ({ ? formatAddress(addressChange.previousAddress) : '', formatChangeMadeBy(addressChange, currentUserId, t), + addressChange.partnerPhone ?? '', + addressChange.partnerEmail ?? '', ]), ]; From e97a5def3be2e36314d0502f3a74b5fa5ff924c1 Mon Sep 17 00:00:00 2001 From: Jeff Clay <91073628+jeff-clay@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:20:43 -0800 Subject: [PATCH 2/6] Turn Mailing Addresses tabs into described tab cards Co-Authored-By: Claude Opus 5.5 --- .../MailingAddresses.test.tsx | 25 +++-- .../MailingAddresses/MailingAddresses.tsx | 92 +++++++++++++------ .../MailingAddressesTabLabel.tsx | 79 ++++++++++++++++ 3 files changed, 163 insertions(+), 33 deletions(-) create mode 100644 src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx diff --git a/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx b/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx index 30ab9fa60..e7ef3d23d 100644 --- a/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx +++ b/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx @@ -61,7 +61,7 @@ describe('MailingAddresses', () => { [18, '18'], [150, '99+'], ])( - 'shows %s contacts to confirm as %s on the To Confirm tab', + 'shows %s contacts to confirm as %s on the Confirm addresses tab', async (toConfirmCount, badgeText) => { const { findByTestId } = render( , @@ -78,22 +78,33 @@ describe('MailingAddresses', () => { expect(queryByTestId('toConfirmCount')).not.toBeInTheDocument(); }); - it('opens on To Confirm by default', async () => { + it('describes each tab', () => { + const { getByRole } = render(); + + expect(getByRole('tab', { name: /Confirm addresses/ })).toHaveTextContent( + "Pick each partner's primary address.", + ); + expect(getByRole('tab', { name: /Change history/ })).toHaveTextContent( + 'See what changed, when, and by whom.', + ); + }); + + it('opens on Confirm addresses by default', async () => { const { findByTestId, getByRole } = render(); - expect(getByRole('tab', { name: 'To Confirm' })).toHaveAttribute( + expect(getByRole('tab', { name: /Confirm addresses/ })).toHaveAttribute( 'aria-selected', 'true', ); expect(await findByTestId('Home')).toBeInTheDocument(); }); - it('opens on Change History from the URL', async () => { + it('opens on Change history from the URL', async () => { const { findByText, getByRole, queryByTestId } = render( , ); - expect(getByRole('tab', { name: 'Change History' })).toHaveAttribute( + expect(getByRole('tab', { name: /Change history/ })).toHaveAttribute( 'aria-selected', 'true', ); @@ -104,7 +115,7 @@ describe('MailingAddresses', () => { it('puts the selected tab in the URL', () => { const { getByRole } = render(); - userEvent.click(getByRole('tab', { name: 'Change History' })); + userEvent.click(getByRole('tab', { name: /Change history/ })); expect(push).toHaveBeenCalledWith( { pathname, query: { accountListId, mailingTab: 'history' } }, @@ -113,7 +124,7 @@ describe('MailingAddresses', () => { ); }); - it('stays on Change History when a partner is opened', async () => { + it('stays on Change history when a partner is opened', async () => { const { findByRole } = render(); expect( diff --git a/src/components/Tool/MailingAddresses/MailingAddresses.tsx b/src/components/Tool/MailingAddresses/MailingAddresses.tsx index 1fd24ee8c..b6ae62280 100644 --- a/src/components/Tool/MailingAddresses/MailingAddresses.tsx +++ b/src/components/Tool/MailingAddresses/MailingAddresses.tsx @@ -1,27 +1,51 @@ import { useRouter } from 'next/router'; import React from 'react'; +import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import HistoryIcon from '@mui/icons-material/History'; import TabContext from '@mui/lab/TabContext'; import TabList from '@mui/lab/TabList'; import TabPanel from '@mui/lab/TabPanel'; -import { Box, Tab } from '@mui/material'; -import { styled } from '@mui/material/styles'; +import { Tab } from '@mui/material'; +import { SxProps, Theme } from '@mui/material/styles'; import { useTranslation } from 'react-i18next'; import { useGetToolNotificationsQuery } from 'src/components/Layouts/Primary/TopBar/Items/NavMenu/GetToolNotifcations.generated'; import { getQueryParam } from 'src/lib/queryParam'; import { ChangeHistoryAddresses } from './ChangeHistoryAddresses/ChangeHistoryAddresses'; import { ConfirmAddresses } from './ConfirmAddresses/ConfirmAddresses'; import { MailingAddressesTabKey } from './MailingAddressesTabKey'; +import { MailingAddressesTabLabel } from './MailingAddressesTabLabel'; -const CountBadge = styled(Box)(({ theme }) => ({ - backgroundColor: theme.palette.progressBarYellow.main, - color: theme.palette.mpdxGrayDark.main, - borderRadius: '10px', - marginLeft: theme.spacing(1), - padding: '3px 7px', - fontSize: '12px', - fontWeight: 700, - lineHeight: 1, -})); +const tabBorder = { border: 1, borderColor: 'divider' }; + +const tabSx: SxProps = (theme) => ({ + textTransform: 'none', + maxWidth: 'none', + minHeight: 0, + alignItems: 'stretch', + textAlign: 'left', + padding: theme.spacing(2, 2.5), + color: 'text.primary', + backgroundColor: 'mpdxGrayLight.main', + ...tabBorder, + borderBottom: 0, + borderRadius: '6px 6px 0 0', + opacity: 1, + '&:hover': { + backgroundColor: 'common.white', + borderColor: 'mpdxBlue.main', + }, + '&.Mui-selected': { + color: 'text.primary', + backgroundColor: 'common.white', + borderColor: 'divider', + borderTop: `4px solid ${theme.palette.mpdxBlue.main}`, + paddingTop: 1.75, + // Covers the panel's top border so the tab and panel read as one card + marginBottom: '-1px', + paddingBottom: '17px', + zIndex: 1, + }, +}); interface Props { accountListId: string; @@ -59,32 +83,48 @@ export const MailingAddresses: React.FC = ({ accountListId }) => { - {t('To Confirm')} - {toConfirmCount > 0 && ( - - {toConfirmCount < 100 ? toConfirmCount : '99+'} - - )} - + } + iconBackground="mpdxYellow.main" + title={t('Confirm addresses')} + description={t("Pick each partner's primary address.")} + count={toConfirmCount} + selected={selectedTab === MailingAddressesTabKey.Confirm} + /> } value={MailingAddressesTabKey.Confirm} - sx={{ fontWeight: 'bold' }} + sx={tabSx} /> } + iconBackground="mpdxBlue.light" + title={t('Change history')} + description={t('See what changed, when, and by whom.')} + selected={selectedTab === MailingAddressesTabKey.History} + /> + } value={MailingAddressesTabKey.History} - sx={{ fontWeight: 'bold' }} + sx={tabSx} /> - + - + diff --git a/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx b/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx new file mode 100644 index 000000000..15b1eb296 --- /dev/null +++ b/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx @@ -0,0 +1,79 @@ +import React from 'react'; +import ChevronRightIcon from '@mui/icons-material/ChevronRight'; +import { Box, Typography } from '@mui/material'; +import { styled } from '@mui/material/styles'; + +const CountBadge = styled(Box)(({ theme }) => ({ + backgroundColor: theme.palette.progressBarYellow.main, + color: theme.palette.mpdxGrayDark.main, + borderRadius: '10px', + padding: '3px 7px', + fontSize: '12px', + fontWeight: 700, + lineHeight: 1, +})); + +// Phones get plain tabs: just the title and badge +const hideOnPhone = { xs: 'none', sm: 'flex' }; + +interface MailingAddressesTabLabelProps { + icon: React.ReactNode; + iconBackground: string; + title: string; + description: string; + count?: number; + selected: boolean; +} + +export const MailingAddressesTabLabel: React.FC< + MailingAddressesTabLabelProps +> = ({ icon, iconBackground, title, description, count, selected }) => ( + + + {icon} + + + + + {title} + + {!!count && ( + + {count < 100 ? count : '99+'} + + )} + + + {description} + + + {!selected && ( + + )} + +); From 3d4b0c3458221cab945b119f212f822a02c07250 Mon Sep 17 00:00:00 2001 From: Jeff Clay <91073628+jeff-clay@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:29:11 -0800 Subject: [PATCH 3/6] Add address change search, no-results actions, Not recorded tooltip Co-Authored-By: Claude Opus 5.5 --- public/locales/en/translation.json | 18 +- public/locales/en/translation_old.json | 2 + .../AddressChangeSearchEmptyState.test.tsx | 81 ++++++++ .../AddressChangeSearchEmptyState.tsx | 72 +++++++ .../AddressChangeHistory.graphql | 2 + .../AddressFilters/AddressFilters.test.tsx | 117 ++++++++++++ .../AddressFilters/AddressFilters.tsx | 35 +++- .../AddressFilters/MadeByMenuItem.tsx | 34 ++++ .../ChangeHistoryAddresses.tsx | 18 +- .../ChangeHistoryAddressesSearch.test.tsx | 180 ++++++++++++++++++ .../ChangeHistoryResults.tsx | 10 +- .../ChangeHistoryAddresses/helpers.test.ts | 7 +- .../ChangeHistoryAddresses/helpers.ts | 6 + .../useAddressChangeFilters.ts | 32 +++- 14 files changed, 594 insertions(+), 20 deletions(-) create mode 100644 src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.test.tsx create mode 100644 src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.tsx create mode 100644 src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.test.tsx create mode 100644 src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/MadeByMenuItem.tsx create mode 100644 src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index dc4f2caae..1a2165799 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -176,8 +176,24 @@ "(Quarter)": "(Quarter)", "(Sent by {{firstName}} {{lastName}})": "(Sent by {{firstName}} {{lastName}})", "(Year)": "(Year)", + "Change history": "Change history", + "Confirm addresses": "Confirm addresses", "Dismiss": "Dismiss", + "MPDX started saving who made each change in Nov 2026. Changes made in MPDX before then don't have a name.": "MPDX started saving who made each change in Nov 2026. Changes made in MPDX before then don't have a name.", + "No address changes for \"{{search}}\"": "No address changes for \"{{search}}\"", + "No address changes for \"{{search}}\" in the last 12 months": "No address changes for \"{{search}}\" in the last 12 months", + "No address changes for \"{{search}}\" in the last 3 months": "No address changes for \"{{search}}\" in the last 3 months", + "No address changes for \"{{search}}\" in the last 6 months": "No address changes for \"{{search}}\" in the last 6 months", + "No address changes for \"{{search}}\" in the selected dates": "No address changes for \"{{search}}\" in the selected dates", + "Partner name or address": "Partner name or address", + "Pick each partner's primary address.": "Pick each partner's primary address.", + "Primary email (current)": "Primary email (current)", + "Primary phone (current)": "Primary phone (current)", "Review your goal, see how to present it to partners, and read your next steps. We also emailed you the full worksheet as a PDF.": "Review your goal, see how to present it to partners, and read your next steps. We also emailed you the full worksheet as a PDF.", + "Search all dates": "Search all dates", + "See what changed, when, and by whom.": "See what changed, when, and by whom.", + "There may be older changes, or the partner may not match your other filters.": "There may be older changes, or the partner may not match your other filters.", + "Try a different search, or clear your filters.": "Try a different search, or clear your filters.", "View my MPD goal": "View my MPD goal", "Your goal changed since you last looked. Review the updated worksheet, which was also emailed to you as a PDF.": "Your goal changed since you last looked. Review the updated worksheet, which was also emailed to you as a PDF.", "Your MPD goal is ready": "Your MPD goal is ready", @@ -855,7 +871,6 @@ "Chalk Line is a significant way to save valuable ministry time while more effectively\n connecting with your partners. Send physical newsletters to your current list using\n Chalk Line with a simple click. Chalk Line is a one way send available anytime you’re\n ready to send a new newsletter out.": "Chalk Line is a significant way to save valuable ministry time while more effectively\n connecting with your partners. Send physical newsletters to your current list using\n Chalk Line with a simple click. Chalk Line is a one way send available anytime you’re\n ready to send a new newsletter out.", "Chalk Line Overview": "Chalk Line Overview", "Change Coach": "Change Coach", - "Change History": "Change History", "Change made by": "Change made by", "Change the contact's status to: {{status}}": "Change the contact's status to: {{status}}", "Change the Geographic Multiplier in the staff member's details to recalculate it. Interns, part-time field staff and volunteers have no New Staff Monthly Salary, so they have no Geographic Multiplier to change.": "Change the Geographic Multiplier in the staff member's details to recalculate it. Interns, part-time field staff and volunteers have no New Staff Monthly Salary, so they have no Geographic Multiplier to change.", @@ -3501,7 +3516,6 @@ "To be Developed: {{amount}}": "To be Developed: {{amount}}", "To change this amount, update the Reimbursable Expenses step": "To change this amount, update the Reimbursable Expenses step", "to check it out and get started saving for future needs!": "to check it out and get started saving for future needs!", - "To Confirm": "To Confirm", "To Do This Week": "To Do This Week", "To get started, we're going to walk with you through a few key steps to set you up for success in {{appName}}!": "To get started, we're going to walk with you through a few key steps to set you up for success in {{appName}}!", "To import your TntConnect database, go to Import from TntConnect": "To import your TntConnect database, go to Import from TntConnect", diff --git a/public/locales/en/translation_old.json b/public/locales/en/translation_old.json index 2947082a1..9a8831571 100644 --- a/public/locales/en/translation_old.json +++ b/public/locales/en/translation_old.json @@ -101,6 +101,7 @@ "Cannot upload file: file size cannot exceed 1MB": "Cannot upload file: file size cannot exceed 1MB", "Cell phone number is required": "Cell phone number is required", "Change": "Change", + "Change History": "Change History", "Change the Geographic Multiplier in the staff member's details to recalculate it.": "Change the Geographic Multiplier in the staff member's details to recalculate it.", "Check": "Check", "Clear Filters": "Clear Filters", @@ -559,6 +560,7 @@ "This updated request will take the place of your previous request. Once submitted, you can return and make edits until {{date}}. After this date, your request will be processed as is.": "This updated request will take the place of your previous request. Once submitted, you can return and make edits until {{date}}. After this date, your request will be processed as is.", "This will log you in on behalf of the user specified below. You will be able to see what the user sees on {{appName}}.\n Impersonation sessions have 20 minute timeout where you will automatically be logged out of the user's account after\n the specified amount of time. Once you are finished impersonating, click 'Exit Impersonation Mode' at the top of the\n page.": "This will log you in on behalf of the user specified below. You will be able to see what the user sees on {{appName}}.\n Impersonation sessions have 20 minute timeout where you will automatically be logged out of the user's account after\n the specified amount of time. Once you are finished impersonating, click 'Exit Impersonation Mode' at the top of the\n page.", "This Year": "This Year", + "To Confirm": "To Confirm", "To Do": "To Do", "To set a one-time savings goal, click \"Add One-time Goal\" to create a new row in the goal table. In the left cell of the new row, enter the name of your goal—for example, \"Car.\" Then, in the right cell, enter the full dollar amount you need to raise, such as 15000.": "To set a one-time savings goal, click \"Add One-time Goal\" to create a new row in the goal table. In the left cell of the new row, enter the name of your goal—for example, \"Car.\" Then, in the right cell, enter the full dollar amount you need to raise, such as 15000.", "TO_DO": "To Do", diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.test.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.test.tsx new file mode 100644 index 000000000..58b2b2cc3 --- /dev/null +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.test.tsx @@ -0,0 +1,81 @@ +import { ThemeProvider } from '@mui/material/styles'; +import { render } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { ContactFilterChangedDuringEnum } from 'src/components/Shared/Filters/ChangedDuring/changedDuring'; +import theme from 'src/theme'; +import { AddressChangeSearchEmptyState } from './AddressChangeSearchEmptyState'; + +const onSearchAllDates = jest.fn(); +const onClearFilters = jest.fn(); + +const renderEmptyState = ( + changedDuring: ContactFilterChangedDuringEnum | null, +) => + render( + + + , + ); + +describe('AddressChangeSearchEmptyState', () => { + it.each([ + [ContactFilterChangedDuringEnum.Last3Months, 'in the last 3 months'], + [ContactFilterChangedDuringEnum.Last6Months, 'in the last 6 months'], + [ContactFilterChangedDuringEnum.Last12Months, 'in the last 12 months'], + [ContactFilterChangedDuringEnum.Custom, 'in the selected dates'], + ])('names the search and the %s range', (changedDuring, range) => { + const { getByRole, getByText } = renderEmptyState(changedDuring); + + expect( + getByRole('heading', { name: `No address changes for "Smith" ${range}` }), + ).toBeInTheDocument(); + expect( + getByText( + 'There may be older changes, or the partner may not match your other filters.', + ), + ).toBeInTheDocument(); + }); + + it('is announced to screen readers', () => { + const { getByTestId } = renderEmptyState( + ContactFilterChangedDuringEnum.Last12Months, + ); + + expect(getByTestId('address-changes-null-state')).toHaveAttribute( + 'role', + 'status', + ); + }); + + it('searches all dates or clears the filters', () => { + const { getByRole } = renderEmptyState( + ContactFilterChangedDuringEnum.Last12Months, + ); + + userEvent.click(getByRole('button', { name: 'Search all dates' })); + expect(onSearchAllDates).toHaveBeenCalled(); + + userEvent.click(getByRole('button', { name: 'Clear filters' })); + expect(onClearFilters).toHaveBeenCalled(); + }); + + it('hides Search all dates when the range is already any time', () => { + const { getByRole, queryByRole, getByText } = renderEmptyState(null); + + expect( + getByRole('heading', { name: 'No address changes for "Smith"' }), + ).toBeInTheDocument(); + expect( + getByText('Try a different search, or clear your filters.'), + ).toBeInTheDocument(); + expect( + queryByRole('button', { name: 'Search all dates' }), + ).not.toBeInTheDocument(); + expect(getByRole('button', { name: 'Clear filters' })).toBeInTheDocument(); + }); +}); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.tsx new file mode 100644 index 000000000..f8498a207 --- /dev/null +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeEmptyState/AddressChangeSearchEmptyState.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import SearchIcon from '@mui/icons-material/Search'; +import { Box, Button, Typography } from '@mui/material'; +import { TFunction, useTranslation } from 'react-i18next'; +import { ContactFilterChangedDuringEnum } from 'src/components/Shared/Filters/ChangedDuring/changedDuring'; +import { NullStateBox } from 'src/components/Shared/Filters/NullState/NullStateBox'; + +const getTitle = ( + search: string, + changedDuring: ContactFilterChangedDuringEnum | null, + t: TFunction, +): string => { + if (!changedDuring) { + return t('No address changes for "{{search}}"', { search }); + } + const titles: Record = { + [ContactFilterChangedDuringEnum.Last3Months]: t( + 'No address changes for "{{search}}" in the last 3 months', + { search }, + ), + [ContactFilterChangedDuringEnum.Last6Months]: t( + 'No address changes for "{{search}}" in the last 6 months', + { search }, + ), + [ContactFilterChangedDuringEnum.Last12Months]: t( + 'No address changes for "{{search}}" in the last 12 months', + { search }, + ), + [ContactFilterChangedDuringEnum.Custom]: t( + 'No address changes for "{{search}}" in the selected dates', + { search }, + ), + }; + return titles[changedDuring]; +}; + +interface AddressChangeSearchEmptyStateProps { + search: string; + changedDuring: ContactFilterChangedDuringEnum | null; + onSearchAllDates: () => void; + onClearFilters: () => void; +} + +export const AddressChangeSearchEmptyState: React.FC< + AddressChangeSearchEmptyStateProps +> = ({ search, changedDuring, onSearchAllDates, onClearFilters }) => { + const { t } = useTranslation(); + + return ( + + + + {getTitle(search, changedDuring, t)} + + + {changedDuring + ? t( + 'There may be older changes, or the partner may not match your other filters.', + ) + : t('Try a different search, or clear your filters.')} + + + {changedDuring && ( + + )} + + + + ); +}; diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql index 79663a387..3498534d9 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressChangeHistory.graphql @@ -5,6 +5,7 @@ query AddressChangeHistory( $startDate: ISO8601Date $endDate: ISO8601Date $madeBy: [ID!] + $search: String ) { addressChangeHistory( accountListId: $accountListId @@ -14,6 +15,7 @@ query AddressChangeHistory( startDate: $startDate endDate: $endDate madeBy: $madeBy + search: $search ) { nodes { id diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.test.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.test.tsx new file mode 100644 index 000000000..101b95388 --- /dev/null +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.test.tsx @@ -0,0 +1,117 @@ +import { ThemeProvider } from '@mui/material/styles'; +import { LocalizationProvider } from '@mui/x-date-pickers'; +import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; +import { render, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; +import { ContactFilterPartnerEnum } from 'src/graphql/types.generated'; +import theme from 'src/theme'; +import { + currentUserId, + mockAddressChangeHistory, +} from '../ChangeHistoryAddressesMock'; +import { AddressFilters } from './AddressFilters'; + +const onSearchChange = jest.fn(); + +const TestComponent: React.FC<{ search?: string }> = ({ search = '' }) => ( + + + + + + + +); + +const notRecordedHelp = + "MPDX started saving who made each change in Nov 2026. Changes made in MPDX before then don't have a name."; + +describe('AddressFilters', () => { + it('puts the search field first', () => { + const { getByRole, container } = render(); + + const search = getByRole('searchbox', { name: 'Search' }); + expect(search).toHaveAttribute('placeholder', 'Partner name or address'); + expect(container.querySelector('input, [role="combobox"]')).toBe(search); + }); + + it('reports what is typed in the search field', () => { + const { getByRole } = render(); + + userEvent.type(getByRole('searchbox', { name: 'Search' }), 'S'); + + expect(onSearchChange).toHaveBeenLastCalledWith('S'); + }); + + it('shows the current search', () => { + const { getByRole } = render(); + + expect(getByRole('searchbox', { name: 'Search' })).toHaveValue('Smith'); + }); + + it('explains "Not recorded" in a tooltip on hover', async () => { + const { getByRole, findByRole } = render(); + + userEvent.click(getByRole('combobox', { name: 'Change made by' })); + // Found by text: while the tooltip is closed, MUI copies its text into the option's title + const option = within(await findByRole('listbox')) + .getByText('Not recorded (before Nov 2026)') + .closest('li'); + expect(option).toHaveAttribute('role', 'option'); + userEvent.hover(option!); + + const tooltip = await findByRole('tooltip'); + expect(tooltip).toHaveTextContent(notRecordedHelp); + expect(option).toHaveAttribute('aria-describedby', tooltip.id); + }); + + it('explains "Not recorded" in a tooltip on keyboard focus', async () => { + // jsdom has no :focus-visible, so MUI's Tooltip would never open on focus. + // Treat the focused element as focus-visible, as a browser does for keyboard focus. + const matches = Element.prototype.matches; + const matchesSpy = jest + .spyOn(Element.prototype, 'matches') + .mockImplementation(function (this: Element, selector: string) { + return selector === ':focus-visible' + ? this === document.activeElement + : matches.call(this, selector); + }); + try { + const { getByRole, findByRole } = render(); + + userEvent.click(getByRole('combobox', { name: 'Change made by' })); + await findByRole('listbox'); + userEvent.keyboard('{end}'); + + expect(await findByRole('tooltip')).toHaveTextContent(notRecordedHelp); + } finally { + matchesSpy.mockRestore(); + } + }); + + it('keeps the other choices free of the tooltip', async () => { + const { getByRole, findByRole, queryByRole } = render(); + + userEvent.click(getByRole('combobox', { name: 'Change made by' })); + userEvent.hover( + within(await findByRole('listbox')).getByRole('option', { + name: 'Jane Smith', + }), + ); + + expect(queryByRole('tooltip')).not.toBeInTheDocument(); + }); +}); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx index c25880a0b..695f3e1c9 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx @@ -1,11 +1,14 @@ import React from 'react'; +import SearchIcon from '@mui/icons-material/Search'; import { Box, FormControl, + InputAdornment, InputLabel, ListSubheader, MenuItem, Select, + TextField, } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { ChangedDuringSelect } from 'src/components/Shared/Filters/ChangedDuring/ChangedDuringSelect'; @@ -21,6 +24,7 @@ import { formatPartnerFilter, groupMadeByOptions, } from '../helpers'; +import { MadeByMenuItem } from './MadeByMenuItem'; const partnerOptions = [ ContactFilterPartnerEnum.GaveOneOrMore, @@ -29,6 +33,8 @@ const partnerOptions = [ ]; interface AddressFiltersProps { + search: string; + onSearchChange: (search: string) => void; partners: ContactFilterPartnerEnum; onPartnersChange: (partners: ContactFilterPartnerEnum) => void; changedDuring: ContactFilterChangedDuringEnum | null; @@ -43,6 +49,8 @@ interface AddressFiltersProps { } export const AddressFilters: React.FC = ({ + search, + onSearchChange, partners, onPartnersChange, changedDuring, @@ -65,6 +73,25 @@ export const AddressFilters: React.FC = ({ return ( + onSearchChange(event.target.value)} + sx={{ flex: 2, minWidth: 0 }} + slotProps={{ + inputLabel: { shrink: true }, + input: { + startAdornment: ( + + + + ), + }, + }} + /> {t('Partner')} @@ -126,9 +153,13 @@ export const AddressFilters: React.FC = ({ )} {mpdxOptions.map((option) => ( - + {option.label} - + ))} diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/MadeByMenuItem.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/MadeByMenuItem.tsx new file mode 100644 index 000000000..769496fa1 --- /dev/null +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/MadeByMenuItem.tsx @@ -0,0 +1,34 @@ +import React, { forwardRef } from 'react'; +import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; +import { MenuItem, MenuItemProps, Tooltip } from '@mui/material'; + +interface MadeByMenuItemProps extends MenuItemProps { + tooltip?: string; +} + +// The Select shows the chosen item's children as its value, so the info icon stays outside children. +export const MadeByMenuItem = forwardRef( + ({ tooltip, children, ...props }, ref) => { + if (!tooltip) { + return ( + + {children} + + ); + } + + return ( + + + {children} + + + + ); + }, +); +MadeByMenuItem.displayName = 'MadeByMenuItem'; diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx index caa5d07c2..34bb88dd5 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx @@ -2,6 +2,8 @@ import React, { useState } from 'react'; import { Box, Typography } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { AddressHistoryModal } from 'src/components/Shared/AddressHistoryModal/AddressHistoryModal'; +import { AddressChangeEmptyState } from './AddressChangeEmptyState/AddressChangeEmptyState'; +import { AddressChangeSearchEmptyState } from './AddressChangeEmptyState/AddressChangeSearchEmptyState'; import { AddressChangeHistoryQueryVariables, useAddressChangeHistoryQuery, @@ -49,6 +51,7 @@ export const ChangeHistoryAddresses: React.FC = ({ startDate: filters.dateRange?.startDate?.toISODate() ?? undefined, endDate: filters.dateRange?.endDate?.toISODate() ?? undefined, madeBy: filters.madeBy ? [filters.madeBy] : undefined, + search: filters.debouncedSearch || undefined, }; const { data, previousData, loading, error, fetchMore, refetch } = useAddressChangeHistoryQuery({ variables }); @@ -79,6 +82,8 @@ export const ChangeHistoryAddresses: React.FC = ({ }} > = ({ onRetry={retry} history={history} dateRange={filters.dateRange} - emptyStateFilter={filters.emptyStateFilter} + emptyState={ + filters.debouncedSearch ? ( + + ) : ( + + ) + } loadMoreFailed={loadMoreFailed} onRetryLoadMore={fetchNextPage} onEndReached={loadMore} diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx new file mode 100644 index 000000000..e83bee273 --- /dev/null +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx @@ -0,0 +1,180 @@ +import { ThemeProvider } from '@mui/material/styles'; +import { LocalizationProvider } from '@mui/x-date-pickers'; +import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; +import { render, waitFor, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { Settings } from 'luxon'; +import { VirtuosoMockContext } from 'react-virtuoso'; +import TestRouter from '__tests__/util/TestRouter'; +import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; +import matchMediaMock from '__tests__/util/matchMediaMock'; +import { ContactPanelProvider } from 'src/components/Shared/ContactPanelProvider/ContactPanelProvider'; +import { UserPreferenceContext } from 'src/components/User/Preferences/UserPreferenceProvider'; +import theme from 'src/theme'; +import { AddressChangeHistoryQuery } from './AddressChangeHistory.generated'; +import { ChangeHistoryAddresses } from './ChangeHistoryAddresses'; +import { + currentUserId, + mockAddressChangeHistory, +} from './ChangeHistoryAddressesMock'; + +const accountListId = 'account-list-1'; +const mutationSpy = jest.fn(); + +type History = AddressChangeHistoryQuery['addressChangeHistory']; + +const emptyHistory: History = { + ...mockAddressChangeHistory, + nodes: [], + contactIds: [], + totalCount: 0, + automaticCount: 0, +}; + +const TestComponent: React.FC<{ history?: History }> = ({ + history = mockAddressChangeHistory, +}) => ( + + + + + + + + + + + + + + + +); + +describe('ChangeHistoryAddresses search', () => { + const nowMillis = Settings.now; + beforeEach(() => { + matchMediaMock({ pointer: 'fine' }); + Settings.now = () => new Date(2026, 9, 14, 15).valueOf(); + }); + afterEach(() => { + Settings.now = nowMillis; + }); + + const searchFor = ( + { getByRole }: ReturnType, + search: string, + ) => userEvent.type(getByRole('searchbox', { name: 'Search' }), search); + + it('sends the search with the other filters once typing stops', async () => { + const utils = render(); + await utils.findByText('4 were automatic'); + + searchFor(utils, ' Smith '); + + await waitFor(() => + expect(mutationSpy).toHaveGraphqlOperation('AddressChangeHistory', { + accountListId, + search: 'Smith', + startDate: '2025-10-14', + endDate: '2026-10-14', + }), + ); + expect(mutationSpy).not.toHaveGraphqlOperation('AddressChangeHistory', { + search: 'Smi', + }); + }); + + it('keeps the search on later pages, which the CSV export also loads', async () => { + const utils = render( + , + ); + await utils.findByText('4 were automatic'); + mutationSpy.mockClear(); + + searchFor(utils, 'Smith'); + + await waitFor(() => + expect(mutationSpy).toHaveGraphqlOperation('AddressChangeHistory', { + search: 'Smith', + after: 'cursor-1', + }), + ); + }); + + it('shows the search empty state, then widens only the date range', async () => { + const utils = render(); + searchFor(utils, 'Smith'); + + expect( + await utils.findByRole('heading', { + name: 'No address changes for "Smith" in the last 12 months', + }), + ).toBeInTheDocument(); + + mutationSpy.mockClear(); + userEvent.click(utils.getByRole('button', { name: 'Search all dates' })); + + expect( + await utils.findByRole('heading', { + name: 'No address changes for "Smith"', + }), + ).toBeInTheDocument(); + expect( + utils.getByRole('combobox', { name: 'Changed during' }), + ).toHaveTextContent('Any time'); + expect(utils.getByRole('searchbox', { name: 'Search' })).toHaveValue( + 'Smith', + ); + await waitFor(() => + expect(mutationSpy).toHaveGraphqlOperation('AddressChangeHistory', { + accountListId, + search: 'Smith', + startDate: undefined, + endDate: undefined, + }), + ); + }); + + it('clears the search and every filter', async () => { + const utils = render(); + userEvent.click(utils.getByRole('combobox', { name: 'Partner' })); + userEvent.click( + within(await utils.findByRole('listbox')).getByRole('option', { + name: 'Lost Partners', + }), + ); + searchFor(utils, 'Smith'); + + userEvent.click( + await utils.findByRole('button', { name: 'Clear filters' }), + ); + + expect(utils.getByRole('searchbox', { name: 'Search' })).toHaveValue(''); + expect(utils.getByRole('combobox', { name: 'Partner' })).toHaveTextContent( + 'All Partners', + ); + expect( + utils.getByRole('combobox', { name: 'Changed during' }), + ).toHaveTextContent('Last 12 Months'); + expect( + utils.getByRole('combobox', { name: 'Change made by' }), + ).toHaveTextContent('Anyone'); + expect( + await utils.findByText('No address changes in the last 12 months'), + ).toBeInTheDocument(); + }); +}); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryResults/ChangeHistoryResults.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryResults/ChangeHistoryResults.tsx index 0fe3ffde9..41f02db85 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryResults/ChangeHistoryResults.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryResults/ChangeHistoryResults.tsx @@ -3,10 +3,6 @@ import { ApolloError } from '@apollo/client'; import { Alert, Box, Button, CircularProgress } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { DateRange } from 'src/components/Shared/Filters/ChangedDuring/changedDuring'; -import { - AddressChangeEmptyState, - AddressChangeFilter, -} from '../AddressChangeEmptyState/AddressChangeEmptyState'; import { AddressChangeHistoryQuery } from '../AddressChangeHistory.generated'; import { AddressChangeSummary } from '../AddressChangeSummary/AddressChangeSummary'; import { AddressChangeTable } from '../AddressChangeTable/AddressChangeTable'; @@ -19,7 +15,7 @@ interface ChangeHistoryResultsProps { onRetry: () => void; history: AddressChangeHistoryQuery['addressChangeHistory'] | undefined; dateRange: DateRange | null; - emptyStateFilter: AddressChangeFilter; + emptyState: React.ReactElement; loadMoreFailed: boolean; onRetryLoadMore: () => void; onEndReached: () => void; @@ -33,7 +29,7 @@ export const ChangeHistoryResults: React.FC = ({ onRetry, history, dateRange, - emptyStateFilter, + emptyState, loadMoreFailed, onRetryLoadMore, onEndReached, @@ -66,7 +62,7 @@ export const ChangeHistoryResults: React.FC = ({ return null; } if (!history.totalCount) { - return ; + return emptyState; } return ( diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.test.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.test.ts index 3ca04cb30..1957fb318 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.test.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.test.ts @@ -67,7 +67,12 @@ describe('groupMadeByOptions', () => { mpdx: [ { value: 'user:user-2', label: 'Jane Smith' }, { value: 'user:user-1', label: 'You' }, - { value: 'unknown_user', label: 'Not recorded (before Nov 2026)' }, + { + value: 'unknown_user', + label: 'Not recorded (before Nov 2026)', + tooltip: + "MPDX started saving who made each change in Nov 2026. Changes made in MPDX before then don't have a name.", + }, ], }); }); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts index b327e2c8c..1df4a1d19 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts @@ -46,6 +46,7 @@ export const formatMadeByOption = ( interface MadeByMenuItem { value: string; label: string; + tooltip?: string; } export const groupMadeByOptions = ( @@ -56,6 +57,11 @@ export const groupMadeByOptions = ( const toMenuItem = (option: MadeByOption): MadeByMenuItem => ({ value: option.id, label: formatMadeByOption(option, currentUserId, t), + ...(option.type === AddressChangeMadeByEnum.UnknownUser && { + tooltip: t( + "MPDX started saving who made each change in Nov 2026. Changes made in MPDX before then don't have a name.", + ), + }), }); const [sourceOptions, mpdxOptions] = partition( options, diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts index 81e2e7628..1bd3530ab 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts @@ -5,6 +5,7 @@ import { getChangedDuringRange, } from 'src/components/Shared/Filters/ChangedDuring/changedDuring'; import { ContactFilterPartnerEnum } from 'src/graphql/types.generated'; +import { useDebouncedValue } from 'src/hooks/useDebounce'; import { AddressChangeFilter } from './AddressChangeEmptyState/AddressChangeEmptyState'; const getEmptyStateFilter = ( @@ -22,19 +23,21 @@ const getEmptyStateFilter = ( : 'other'; }; +const searchDebounceMs = 500; +const defaultPartners = ContactFilterPartnerEnum.GaveOneOrMore; +const defaultChangedDuring = ContactFilterChangedDuringEnum.Last12Months; + export const useAddressChangeFilters = () => { - const [partners, setPartners] = useState( - ContactFilterPartnerEnum.GaveOneOrMore, - ); + const [search, setSearch] = useState(''); + const debouncedSearch = useDebouncedValue(search, searchDebounceMs).trim(); + const [partners, setPartners] = useState(defaultPartners); const [changedDuring, setChangedDuring] = - useState( - ContactFilterChangedDuringEnum.Last12Months, - ); + useState(defaultChangedDuring); const [customRange, setCustomRange] = useState(null); const [madeBy, setMadeBy] = useState(null); const dateRange = getChangedDuringRange(changedDuring, customRange); const emptyStateFilter = getEmptyStateFilter( - partners !== ContactFilterPartnerEnum.GaveOneOrMore || !!madeBy, + partners !== defaultPartners || !!madeBy, changedDuring, ); @@ -43,7 +46,22 @@ export const useAddressChangeFilters = () => { setChangedDuring(ContactFilterChangedDuringEnum.Custom); }; + const searchAllDates = () => setChangedDuring(null); + + const clearFilters = () => { + setSearch(''); + setPartners(defaultPartners); + setChangedDuring(defaultChangedDuring); + setCustomRange(null); + setMadeBy(null); + }; + return { + search, + setSearch, + debouncedSearch, + searchAllDates, + clearFilters, partners, setPartners, changedDuring, From 02104c85d0e1770516154fe50ebef40c4e49f8aa Mon Sep 17 00:00:00 2001 From: Jeff Clay <91073628+jeff-clay@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:42:40 -0800 Subject: [PATCH 4/6] Wrap Change history filters on narrow screens Co-Authored-By: Claude Opus 5.5 --- .../AddressFilters/AddressFilters.tsx | 10 +++++----- .../ChangeHistoryAddresses/ChangeHistoryAddresses.tsx | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx index 695f3e1c9..dd5d750c2 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/AddressFilters/AddressFilters.tsx @@ -72,7 +72,7 @@ export const AddressFilters: React.FC = ({ ); return ( - + = ({ placeholder={t('Partner name or address')} value={search} onChange={(event) => onSearchChange(event.target.value)} - sx={{ flex: 2, minWidth: 0 }} + sx={{ flex: '2 1 240px' }} slotProps={{ inputLabel: { shrink: true }, input: { @@ -92,7 +92,7 @@ export const AddressFilters: React.FC = ({ }, }} /> - + {t('Partner')} @@ -110,7 +110,7 @@ export const AddressFilters: React.FC = ({ ))} - + {t('Changed during')} @@ -124,7 +124,7 @@ export const AddressFilters: React.FC = ({ onCustomRangeApply={onDateRangeChange} /> - + {t('Change made by')} diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx index 34bb88dd5..7e2a4e9cd 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddresses.tsx @@ -78,7 +78,9 @@ export const ChangeHistoryAddresses: React.FC = ({ Date: Mon, 30 Nov 2026 15:29:18 -0800 Subject: [PATCH 5/6] Apply cleared search at once; tighten search tests Co-Authored-By: Claude Opus 5.5 --- .../ChangeHistoryAddressesSearch.test.tsx | 29 ++++++++++++++++--- .../ChangeHistoryAddresses/helpers.ts | 6 ++-- .../useAddressChangeFilters.ts | 4 ++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx index e83bee273..b8f0f611a 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx @@ -93,7 +93,7 @@ describe('ChangeHistoryAddresses search', () => { }); }); - it('keeps the search on later pages, which the CSV export also loads', async () => { + it('keeps the search when loading the next page', async () => { const utils = render( { }), ); searchFor(utils, 'Smith'); + await utils.findByRole('button', { name: 'Clear filters' }); + mutationSpy.mockClear(); - userEvent.click( - await utils.findByRole('button', { name: 'Clear filters' }), - ); + userEvent.click(utils.getByRole('button', { name: 'Clear filters' })); expect(utils.getByRole('searchbox', { name: 'Search' })).toHaveValue(''); expect(utils.getByRole('combobox', { name: 'Partner' })).toHaveTextContent( @@ -176,5 +176,26 @@ describe('ChangeHistoryAddresses search', () => { expect( await utils.findByText('No address changes in the last 12 months'), ).toBeInTheDocument(); + // The cleared search must not linger in a request with the reset filters + expect(mutationSpy).not.toHaveGraphqlOperation('AddressChangeHistory', { + search: 'Smith', + }); + }); + + it('ignores a search of only spaces', async () => { + const utils = render(); + await utils.findByText('No address changes in the last 12 months'); + mutationSpy.mockClear(); + + searchFor(utils, ' '); + + await waitFor(() => + expect(mutationSpy).not.toHaveGraphqlOperation('AddressChangeHistory', { + search: '', + }), + ); + expect( + utils.getByText('No address changes in the last 12 months'), + ).toBeInTheDocument(); }); }); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts index 1df4a1d19..5a734a991 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/helpers.ts @@ -43,7 +43,7 @@ export const formatMadeByOption = ( return option.label; }; -interface MadeByMenuItem { +interface MadeByMenuOption { value: string; label: string; tooltip?: string; @@ -53,8 +53,8 @@ export const groupMadeByOptions = ( options: MadeByOption[], currentUserId: string | undefined, t: TFunction, -): { automatic: MadeByMenuItem[]; mpdx: MadeByMenuItem[] } => { - const toMenuItem = (option: MadeByOption): MadeByMenuItem => ({ +): { automatic: MadeByMenuOption[]; mpdx: MadeByMenuOption[] } => { + const toMenuItem = (option: MadeByOption): MadeByMenuOption => ({ value: option.id, label: formatMadeByOption(option, currentUserId, t), ...(option.type === AddressChangeMadeByEnum.UnknownUser && { diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts index 1bd3530ab..b8511be5b 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts @@ -29,7 +29,9 @@ const defaultChangedDuring = ContactFilterChangedDuringEnum.Last12Months; export const useAddressChangeFilters = () => { const [search, setSearch] = useState(''); - const debouncedSearch = useDebouncedValue(search, searchDebounceMs).trim(); + const typedSearch = useDebouncedValue(search, searchDebounceMs).trim(); + // Clearing applies at once, so a cleared search never goes out with reset filters + const debouncedSearch = search.trim() ? typedSearch : ''; const [partners, setPartners] = useState(defaultPartners); const [changedDuring, setChangedDuring] = useState(defaultChangedDuring); From 9b50a79ddc3afbee54f49e625ab0d2f0ef9661a5 Mon Sep 17 00:00:00 2001 From: Jeff Clay <91073628+jeff-clay@users.noreply.github.com> Date: Mon, 30 Nov 2026 15:36:00 -0800 Subject: [PATCH 6/6] Keep cleared search cleared; label tab count for screen readers Co-Authored-By: Claude Opus 5.5 --- public/locales/en/translation.json | 2 + .../ChangeHistoryAddressesSearch.test.tsx | 27 ++++- .../useAddressChangeFilters.ts | 20 +++- .../MailingAddresses.test.tsx | 8 ++ .../MailingAddressesTabLabel.tsx | 101 ++++++++++-------- 5 files changed, 103 insertions(+), 55 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 1a2165799..1e538370d 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -274,6 +274,8 @@ "{{count}} Selected_other": "{{count}} Selected", "{{count}} staff_one": "{{count}} staff", "{{count}} staff_other": "{{count}} staff", + "{{count}} to confirm_one": "{{count}} to confirm", + "{{count}} to confirm_other": "{{count}} to confirm", "{{count}} were automatic_one": "{{count}} was automatic", "{{count}} were automatic_other": "{{count}} were automatic", "{{count}} years_one": "{{count}} years", diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx index b8f0f611a..9ef404665 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/ChangeHistoryAddressesSearch.test.tsx @@ -189,13 +189,30 @@ describe('ChangeHistoryAddresses search', () => { searchFor(utils, ' '); - await waitFor(() => - expect(mutationSpy).not.toHaveGraphqlOperation('AddressChangeHistory', { - search: '', - }), - ); + // Past the debounce, so a search that was going to be sent has been + await new Promise((resolve) => setTimeout(resolve, 600)); + expect(mutationSpy).not.toHaveGraphqlOperation('AddressChangeHistory', { + search: ' ', + }); expect( utils.getByText('No address changes in the last 12 months'), ).toBeInTheDocument(); }); + + it('does not bring back a cleared search when typing again right away', async () => { + const utils = render(); + searchFor(utils, 'Smith'); + await utils.findByRole('button', { name: 'Clear filters' }); + + userEvent.click(utils.getByRole('button', { name: 'Clear filters' })); + searchFor(utils, 'J'); + + // The cached "Smith" results would show at once if the old search came back + expect( + utils.queryByRole('heading', { name: /"Smith"/ }), + ).not.toBeInTheDocument(); + expect( + await utils.findByRole('heading', { name: /"J"/ }), + ).toBeInTheDocument(); + }); }); diff --git a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts index b8511be5b..162479dd3 100644 --- a/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts +++ b/src/components/Tool/MailingAddresses/ChangeHistoryAddresses/useAddressChangeFilters.ts @@ -5,7 +5,7 @@ import { getChangedDuringRange, } from 'src/components/Shared/Filters/ChangedDuring/changedDuring'; import { ContactFilterPartnerEnum } from 'src/graphql/types.generated'; -import { useDebouncedValue } from 'src/hooks/useDebounce'; +import { useDebouncedCallback } from 'src/hooks/useDebounce'; import { AddressChangeFilter } from './AddressChangeEmptyState/AddressChangeEmptyState'; const getEmptyStateFilter = ( @@ -28,10 +28,20 @@ const defaultPartners = ContactFilterPartnerEnum.GaveOneOrMore; const defaultChangedDuring = ContactFilterChangedDuringEnum.Last12Months; export const useAddressChangeFilters = () => { - const [search, setSearch] = useState(''); - const typedSearch = useDebouncedValue(search, searchDebounceMs).trim(); - // Clearing applies at once, so a cleared search never goes out with reset filters - const debouncedSearch = search.trim() ? typedSearch : ''; + const [search, setSearchText] = useState(''); + const [debouncedSearch, setDebouncedSearch] = useState(''); + const applySearch = useDebouncedCallback( + (value: string) => setDebouncedSearch(value.trim()), + searchDebounceMs, + ); + const setSearch = (value: string) => { + setSearchText(value); + applySearch(value); + // Clearing applies at once, so a cleared search never goes out with reset filters + if (!value.trim()) { + setDebouncedSearch(''); + } + }; const [partners, setPartners] = useState(defaultPartners); const [changedDuring, setChangedDuring] = useState(defaultChangedDuring); diff --git a/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx b/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx index e7ef3d23d..78c8ae515 100644 --- a/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx +++ b/src/components/Tool/MailingAddresses/MailingAddresses.test.tsx @@ -71,6 +71,14 @@ describe('MailingAddresses', () => { }, ); + it('tells screen readers what the count means', async () => { + const { findByRole } = render(); + + expect( + await findByRole('tab', { name: /Confirm addresses 18 to confirm/ }), + ).toBeInTheDocument(); + }); + it('hides the badge when there are no contacts to confirm', async () => { const { findByTestId, queryByTestId } = render(); diff --git a/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx b/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx index 15b1eb296..b07a09f83 100644 --- a/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx +++ b/src/components/Tool/MailingAddresses/MailingAddressesTabLabel.tsx @@ -1,7 +1,9 @@ import React from 'react'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import { Box, Typography } from '@mui/material'; -import { styled } from '@mui/material/styles'; +import { SxProps, Theme, styled } from '@mui/material/styles'; +import { visuallyHidden } from '@mui/utils'; +import { useTranslation } from 'react-i18next'; const CountBadge = styled(Box)(({ theme }) => ({ backgroundColor: theme.palette.progressBarYellow.main, @@ -27,53 +29,62 @@ interface MailingAddressesTabLabelProps { export const MailingAddressesTabLabel: React.FC< MailingAddressesTabLabelProps -> = ({ icon, iconBackground, title, description, count, selected }) => ( - - - {icon} - - - +> = ({ icon, iconBackground, title, description, count, selected }) => { + const { t } = useTranslation(); + + return ( + + + {icon} + + + + + {title} + + {!!count && ( + <> + + {count < 100 ? count : '99+'} + + }> + {t('{{count}} to confirm', { count })} + + + )} + - {title} + {description} - {!!count && ( - - {count < 100 ? count : '99+'} - - )} - - {description} - + {!selected && ( + + )} - {!selected && ( - - )} - -); + ); +};