Skip to content
Open
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
27 changes: 13 additions & 14 deletions src/components/Search/SearchBulkActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,21 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
}, [excludedTransactions, selectedTransactions, isExpenseReportType, searchData]);

const allMatchingItemsCount = currentSearchResults?.search?.count;
let selectedAllMatchingItemsCount: number | undefined;
if (excludedItemsCount > 0) {
if (typeof allMatchingItemsCount === 'number') {
selectedAllMatchingItemsCount = Math.max(allMatchingItemsCount - excludedItemsCount, 0);
} else if (isExpenseType && isOffline) {
selectedAllMatchingItemsCount = selectedItemsCount;
}
}
const isAllMatchingItemsCountLoading = areAllMatchingItemsSelected && typeof allMatchingItemsCount !== 'number' && !isOffline && !!currentSearchResults?.search?.isLoading;
let selectionButtonText: string;
if (areAllMatchingItemsSelected) {
const count = isExpenseType ? selectedAllMatchingItemsCount : allMatchingItemsCount;
selectionButtonText = typeof count !== 'number' ? translate('search.exportAll.allMatchingItemsSelected') : translate('workspace.common.selected', {count});
const hasSearchErrors = Object.keys(currentSearchResults?.errors ?? {}).length > 0;
// The server count is the only source for how many items "select all" covers, so keep the button loading until it
// arrives. Offline or on error it never will, so fall back to the count of the items we do have selected.
const isAllMatchingItemsCountLoading = areAllMatchingItemsSelected && typeof allMatchingItemsCount !== 'number' && !isOffline && !hasSearchErrors;
// Excluded items only map onto the server count for expenses. For expense reports an excluded transaction doesn't
// necessarily drop its whole report from the results, so the server count is used as-is there.
let selectedAllMatchingItemsCount: number;
if (typeof allMatchingItemsCount !== 'number') {
selectedAllMatchingItemsCount = selectedItemsCount;
} else {
selectionButtonText = translate('workspace.common.selected', {count: selectedItemsCount});
selectedAllMatchingItemsCount = isExpenseType ? Math.max(allMatchingItemsCount - excludedItemsCount, 0) : allMatchingItemsCount;
}
const selectionButtonText = translate('workspace.common.selected', {
count: areAllMatchingItemsSelected ? selectedAllMatchingItemsCount : selectedItemsCount,
});

return (
<>
Expand Down
1 change: 0 additions & 1 deletion src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9144,7 +9144,6 @@ 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: 0 additions & 1 deletion src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9376,7 +9376,6 @@ ${reportName}`,
exportedTo: 'Εξήχθη σε',
exportAll: {
selectAllMatchingItems: 'Επιλέξτε όλα τα στοιχεία που ταιριάζουν',
allMatchingItemsSelected: 'Έχουν επιλεγεί όλα τα στοιχεία που ταιριάζουν',
selectAllOnThisPage: 'Επιλέξτε όλα σε αυτή τη σελίδα',
},
errors: {
Expand Down
1 change: 0 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9291,7 +9291,6 @@ 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: 0 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8992,7 +8992,6 @@ El plan Controlar empieza en 9 $ por miembro activo al mes.`,
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: 0 additions & 1 deletion src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9180,7 +9180,6 @@ 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: 0 additions & 1 deletion src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9116,7 +9116,6 @@ 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 @@ -8996,7 +8996,7 @@ ${reportName}`,
description: 'おっと、アイテムがたくさんありますね!まとめて整理して、間もなくConciergeからファイルをお送りします。',
},
exportedTo: 'エクスポート先',
exportAll: {selectAllMatchingItems: '一致する項目をすべて選択', allMatchingItemsSelected: '一致する項目をすべて選択済み', selectAllOnThisPage: 'このページのすべてを選択'},
exportAll: {selectAllMatchingItems: '一致する項目をすべて選択', selectAllOnThisPage: 'このページのすべてを選択'},
errors: {
pleaseSelectDatesForBothFromAndTo: '開始日と終了日の両方を選択してください',
},
Expand Down
1 change: 0 additions & 1 deletion src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9076,7 +9076,6 @@ 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: 0 additions & 1 deletion src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9065,7 +9065,6 @@ 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: 0 additions & 1 deletion src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9070,7 +9070,6 @@ 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 @@ -8761,7 +8761,7 @@ ${reportName}`,
description: '哇,项目真不少!我们会把它们打包好,Concierge 很快就会给你发送一个文件。',
},
exportedTo: '已导出到',
exportAll: {selectAllMatchingItems: '选择所有匹配的项目', allMatchingItemsSelected: '已选择所有匹配的项目', selectAllOnThisPage: '选择本页全部内容'},
exportAll: {selectAllMatchingItems: '选择所有匹配的项目', selectAllOnThisPage: '选择本页全部内容'},
errors: {
pleaseSelectDatesForBothFromAndTo: '请选择起始和结束日期',
},
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Search/SearchBulkActionsButtonTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ describe('SearchBulkActionsButton all-matching label', () => {
mockIsOffline = false;
});

it('keeps the production loading state while totals are requested', () => {
it('falls back to the selected count and keeps loading while the server count is missing', () => {
mockSearchIsLoading = true;

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

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

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

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

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

it('shows the exact count after an item is excluded', () => {
Expand All @@ -163,7 +163,7 @@ describe('SearchBulkActionsButton all-matching label', () => {

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

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

it('shows the loaded selected count when an expense is excluded offline before the server count is available', () => {
Expand All @@ -180,7 +180,7 @@ describe('SearchBulkActionsButton all-matching label', () => {

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

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

it('uses the unmodified server count for expense reports', () => {
Expand Down
Loading