Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/Search/SearchBulkActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
} else {
selectedAllMatchingItemsCount = isExpenseType ? Math.max(allMatchingItemsCount - excludedItemsCount, 0) : allMatchingItemsCount;
}
const selectionButtonText = translate('workspace.common.selected', {
count: areAllMatchingItemsSelected ? selectedAllMatchingItemsCount : selectedItemsCount,
});
const shouldShowAllMatchingItemsSelected = isExpenseType && areAllMatchingItemsSelected && Object.keys(excludedTransactions).length === 0;
const selectionButtonText = shouldShowAllMatchingItemsSelected
? translate('search.exportAll.allMatchingItemsSelected')
: translate('workspace.common.selected', {
count: areAllMatchingItemsSelected ? selectedAllMatchingItemsCount : selectedItemsCount,
});

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Search/SearchSelectionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ function SearchSelectionProvider({children}: SearchSelectionProviderProps) {
excludedTransactions[key] = transaction;
}
}
for (const key of Object.keys(selectedTransactions)) {
for (const [key, transaction] of Object.entries(selectedTransactions)) {
if (!Object.hasOwn(prevState.selectedTransactions, key) && Object.hasOwn(excludedTransactions, key)) {
delete excludedTransactions[key];
}
if (!Object.hasOwn(prevState.selectedTransactions, key) && transaction.isSelectedViaGroup && transaction.groupKey) {
delete excludedTransactions[transaction.groupKey];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to make sure I'm understanding this right, this is here so that if a user Select All Matching, the remove a transaction, when they re select the transaction it treats as Select All Matching is applyed again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. All-matching mode remains active; this removes the stale parent-group exclusion when the group is reselected, allowing the button to return to “All matching items selected.” This is covered by a regression test.

}
}
} else if (!areAllMatchingItemsSelected) {
excludedTransactions = {};
Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9486,6 +9486,7 @@ Fügen Sie weitere Ausgabelimits hinzu, um den Cashflow Ihres Unternehmens zu sc
exportedTo: 'Exportiert nach',
exportAll: {
selectAllMatchingItems: 'Alle passenden Einträge auswählen',
allMatchingItemsSelected: 'Alle passenden Elemente ausgewählt',
selectAllOnThisPage: 'Alle auf dieser Seite auswählen',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9701,6 +9701,7 @@ ${reportName}`,
exportedTo: 'Εξήχθη σε',
exportAll: {
selectAllMatchingItems: 'Επιλέξτε όλα τα στοιχεία που ταιριάζουν',
allMatchingItemsSelected: 'Έχουν επιλεγεί όλα τα στοιχεία που ταιριάζουν',
selectAllOnThisPage: 'Επιλέξτε όλα σε αυτή τη σελίδα',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9636,6 +9636,7 @@ const translations = {
exportedTo: 'Exported to',
exportAll: {
selectAllMatchingItems: 'Select all matching items',
allMatchingItemsSelected: 'All matching items selected',
selectAllOnThisPage: 'Select all on this page',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9338,6 +9338,7 @@ ${reportName}`,
exportedTo: 'Exported to',
exportAll: {
selectAllMatchingItems: 'Seleccionar todos los elementos coincidentes',
allMatchingItemsSelected: 'Todos los elementos coincidentes seleccionados',
selectAllOnThisPage: 'Seleccionar todo en esta página',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9516,6 +9516,7 @@ Ajoutez davantage de règles de dépenses pour protéger la trésorerie de l’e
exportedTo: 'Exporté vers',
exportAll: {
selectAllMatchingItems: 'Sélectionnez tous les éléments correspondants',
allMatchingItemsSelected: 'Tous les éléments correspondants sont sélectionnés',
selectAllOnThisPage: 'Tout sélectionner sur cette page',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9450,6 +9450,7 @@ Aggiungi altre regole di spesa per proteggere il flusso di cassa aziendale.`,
exportedTo: 'Esportato in',
exportAll: {
selectAllMatchingItems: 'Seleziona tutti gli elementi corrispondenti',
allMatchingItemsSelected: 'Tutti gli elementi corrispondenti selezionati',
selectAllOnThisPage: 'Seleziona tutto in questa pagina',
},
errors: {
Expand Down
2 changes: 1 addition & 1 deletion src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9313,7 +9313,7 @@ ${reportName}`,
description: 'おっと、アイテムがたくさんありますね!まとめて整理して、間もなくConciergeからファイルをお送りします。',
},
exportedTo: 'エクスポート先',
exportAll: {selectAllMatchingItems: '一致する項目をすべて選択', selectAllOnThisPage: 'このページのすべてを選択'},
exportAll: {selectAllMatchingItems: '一致する項目をすべて選択', allMatchingItemsSelected: '一致する項目をすべて選択済み', selectAllOnThisPage: 'このページのすべてを選択'},
errors: {
pleaseSelectDatesForBothFromAndTo: '開始日と終了日の両方を選択してください',
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9401,6 +9401,7 @@ er bestedingsregels toe om de kasstroom van het bedrijf te beschermen.`,
exportedTo: 'Geëxporteerd naar',
exportAll: {
selectAllMatchingItems: 'Selecteer alle overeenkomende items',
allMatchingItemsSelected: 'Alle overeenkomende items geselecteerd',
selectAllOnThisPage: 'Selecteer alles op deze pagina',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9438,6 +9438,7 @@ Dodaj więcej zasad wydatków, żeby chronić płynność finansową firmy.`,
exportedTo: 'Wyeksportowano do',
exportAll: {
selectAllMatchingItems: 'Zaznacz wszystkie pasujące elementy',
allMatchingItemsSelected: 'Zaznaczono wszystkie pasujące elementy',
selectAllOnThisPage: 'Zaznacz wszystko na tej stronie',
},
errors: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9404,6 +9404,7 @@ Adicione mais regras de gasto para proteger o fluxo de caixa da empresa.`,
exportedTo: 'Exportado para',
exportAll: {
selectAllMatchingItems: 'Selecionar todos os itens correspondentes',
allMatchingItemsSelected: 'Todos os itens correspondentes selecionados',
selectAllOnThisPage: 'Selecionar tudo nesta página',
},
chartTitles: {
Expand Down
2 changes: 1 addition & 1 deletion src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9067,7 +9067,7 @@ ${reportName}`,
description: '哇,项目真不少!我们会把它们打包好,Concierge 很快就会给你发送一个文件。',
},
exportedTo: '已导出到',
exportAll: {selectAllMatchingItems: '选择所有匹配的项目', selectAllOnThisPage: '选择本页全部内容'},
exportAll: {selectAllMatchingItems: '选择所有匹配的项目', allMatchingItemsSelected: '已选择所有匹配的项目', selectAllOnThisPage: '选择本页全部内容'},
errors: {
pleaseSelectDatesForBothFromAndTo: '请选择起始和结束日期',
},
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/Search/LazyGroupSelectionTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const renderSelection = () =>
renderHook(
() => ({
...useSearchSelectionContext(),
...useSearchSelectionActions(),
...useSearchRowSelectionActions(),
}),
{wrapper: Wrapper},
Expand Down Expand Up @@ -228,6 +229,31 @@ describe('Lazily loaded group selection', () => {
expect(result.current.selectedTransactions['2']?.isSelected).toBe(true);
});

it('clears the parent exclusion when an expanded group is reselected', async () => {
const {result} = renderSelection();

await act(async () => {
result.current.toggleAll();
result.current.selectAllMatchingItems(true);
await waitForBatchedUpdatesWithAct();
});
await act(async () => {
result.current.toggle(categoryGroup, []);
await waitForBatchedUpdatesWithAct();
});
expect(result.current.excludedTransactions[GROUP_KEY]).toBeDefined();

await act(async () => {
result.current.toggle(categoryGroup, loadedChildren);
await waitForBatchedUpdatesWithAct();
});

expect(result.current.excludedTransactions).toEqual({});
expect(result.current.selectedTransactions['1']?.isSelected).toBe(true);
expect(result.current.selectedTransactions['2']?.isSelected).toBe(true);
expect(result.current.areAllMatchingItemsSelected).toBe(true);
});

it('refreshes an excluded expense when its live row changes', async () => {
const {result, rerender} = renderFlatSelection();
await excludeFlatExpense(result);
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/Search/SearchBulkActionsButtonTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let mockExcludedTransactions: SelectedTransactions = {};
let mockSearchCount: number | undefined;
let mockSearchIsLoading = false;
let mockIsOffline = false;
let mockAreAllMatchingItemsSelected = true;

jest.mock('@components/ButtonWithDropdownMenu', () => ({
__esModule: true,
Expand Down Expand Up @@ -75,7 +76,7 @@ jest.mock('@components/Search/SearchContext', () => ({
selectedTransactions: {tx1: {isSelected: true}},
excludedTransactions: mockExcludedTransactions,
selectedReports: [],
areAllMatchingItemsSelected: true,
areAllMatchingItemsSelected: mockAreAllMatchingItemsSelected,
}),
useSearchResultsContext: () => ({
currentSearchResults: {search: {count: mockSearchCount, isLoading: mockSearchIsLoading}},
Expand Down Expand Up @@ -130,22 +131,23 @@ describe('SearchBulkActionsButton all-matching label', () => {
mockSearchCount = undefined;
mockSearchIsLoading = false;
mockIsOffline = false;
mockAreAllMatchingItemsSelected = true;
});

it('falls back to the selected count and keeps loading while the server count is missing', () => {
it('shows the all-matching label and keeps loading while the server count is missing', () => {
mockSearchIsLoading = true;

render(<SearchBulkActionsButton queryJSON={queryJSON} />);

expect(getButtonProps()).toEqual({customText: 'workspace.common.selected:1', isLoading: true});
expect(getButtonProps()).toEqual({customText: 'search.exportAll.allMatchingItemsSelected', isLoading: true});
});

it('shows the server count when it arrives and there are no exclusions', () => {
it('keeps the all-matching label when the server count arrives and there are no exclusions', () => {
mockSearchCount = 172;

render(<SearchBulkActionsButton queryJSON={queryJSON} />);

expect(getButtonProps()).toEqual({customText: 'workspace.common.selected:172', isLoading: false});
expect(getButtonProps()).toEqual({customText: 'search.exportAll.allMatchingItemsSelected', isLoading: false});
});

it('shows the exact count after an item is excluded', () => {
Expand All @@ -157,6 +159,14 @@ describe('SearchBulkActionsButton all-matching label', () => {
expect(getButtonProps()).toEqual({customText: 'workspace.common.selected:171', isLoading: false});
});

it('keeps the numeric label for page-only selection', () => {
mockAreAllMatchingItemsSelected = false;

render(<SearchBulkActionsButton queryJSON={queryJSON} />);

expect(getButtonProps()).toEqual({customText: 'workspace.common.selected:1', isLoading: false});
});

it('keeps loading when an exclusion exists before the count arrives', () => {
mockSearchIsLoading = true;
mockExcludedTransactions = {tx2: makeTransaction()};
Expand Down
Loading