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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
archivedReportsIDList: archivedReportsIdSet,
isActionLoadingSet,
cardFeeds,
shouldSkipActionFiltering: true,
});
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
}
Expand Down
21 changes: 0 additions & 21 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ type GetReportSectionsParams = {
allTransactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
bankAccountList: OnyxEntry<OnyxTypes.BankAccountList>;
reportActions?: Record<string, OnyxTypes.ReportAction[]>;
shouldSkipActionFiltering?: boolean;
};

const transactionColumnNamesToSortingProperty: TransactionSorting = {
Expand Down Expand Up @@ -244,21 +243,10 @@ const expenseStatusActionMapping = {
[CONST.SEARCH.STATUS.EXPENSE.ALL]: () => true,
};

const actionFilterMapping = {
[CONST.SEARCH.ACTION_FILTERS.SUBMIT]: expenseStatusActionMapping[CONST.SEARCH.STATUS.EXPENSE.DRAFTS],
[CONST.SEARCH.ACTION_FILTERS.APPROVE]: expenseStatusActionMapping[CONST.SEARCH.STATUS.EXPENSE.OUTSTANDING],
[CONST.SEARCH.ACTION_FILTERS.PAY]: expenseStatusActionMapping[CONST.SEARCH.STATUS.EXPENSE.APPROVED],
[CONST.SEARCH.ACTION_FILTERS.EXPORT]: () => true,
};

function isValidExpenseStatus(status: unknown): status is ValueOf<typeof CONST.SEARCH.STATUS.EXPENSE> {
return typeof status === 'string' && status in expenseStatusActionMapping;
}

function isValidActionFilter(action: unknown): action is ValueOf<typeof CONST.SEARCH.ACTION_FILTERS> {
return typeof action === 'string' && action in actionFilterMapping;
}

function getExpenseStatusOptions(translate: LocalizedTranslate): Array<MultiSelectItem<SingularSearchStatus>> {
return [
{text: translate('common.unreported'), value: CONST.SEARCH.STATUS.EXPENSE.UNREPORTED},
Expand Down Expand Up @@ -379,7 +367,6 @@ type GetSectionsParams = {
isActionLoadingSet?: ReadonlySet<string>;
cardFeeds?: OnyxCollection<OnyxTypes.CardFeeds>;
allTransactionViolations?: OnyxCollection<OnyxTypes.TransactionViolation[]>;
shouldSkipActionFiltering?: boolean;
};

/**
Expand Down Expand Up @@ -1730,7 +1717,6 @@ function getReportSections({
allTransactionViolations,
bankAccountList,
reportActions = {},
shouldSkipActionFiltering = false,
}: GetReportSectionsParams): [TransactionGroupListItemType[], number] {
const shouldShowMerchant = getShouldShowMerchant(data);

Expand Down Expand Up @@ -1795,11 +1781,6 @@ function getReportSections({
shouldShow = isValidExpenseStatus(status) ? expenseStatusActionMapping[status](reportItem) : false;
}
}
const actionFromQuery = queryJSON?.flatFilters?.find((filter) => filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.ACTION)?.filters?.at(0)?.value;

if (!shouldSkipActionFiltering && actionFromQuery && isValidActionFilter(actionFromQuery)) {
shouldShow = shouldShow && actionFilterMapping[actionFromQuery](reportItem);
}
}

if (shouldShow) {
Expand Down Expand Up @@ -2114,7 +2095,6 @@ function getSections({
isActionLoadingSet,
cardFeeds,
allTransactionViolations,
shouldSkipActionFiltering,
}: GetSectionsParams) {
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
return getReportActionsSections(data);
Expand All @@ -2136,7 +2116,6 @@ function getSections({
allTransactionViolations,
bankAccountList,
reportActions,
shouldSkipActionFiltering,
});
}

Expand Down
72 changes: 0 additions & 72 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {setOptimisticDataForTransactionThreadPreview} from '@userActions/Search'
import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import type {CardFeedForDisplay} from '@src/libs/CardFeedUtils';
import * as SearchQueryUtils from '@src/libs/SearchQueryUtils';
import * as SearchUIUtils from '@src/libs/SearchUIUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand All @@ -49,10 +48,6 @@ jest.mock('@userActions/Search', () => ({
...jest.requireActual<typeof SearchUtils>('@userActions/Search'),
setOptimisticDataForTransactionThreadPreview: jest.fn(),
}));
jest.mock('@src/libs/SearchQueryUtils', () => ({
...jest.requireActual<typeof SearchQueryUtils>('@src/libs/SearchQueryUtils'),
getCurrentSearchQueryJSON: jest.fn(),
}));

const adminAccountID = 18439984;
const adminEmail = 'admin@policy.com';
Expand Down Expand Up @@ -2241,73 +2236,6 @@ describe('SearchUIUtils', () => {
});
});

describe('Test getSections with shouldSkipActionFiltering option', () => {
beforeEach(() => {
// Mock getCurrentSearchQueryJSON to return a query with action filter
(SearchQueryUtils.getCurrentSearchQueryJSON as jest.Mock).mockReturnValue({
type: 'expense-report',
filters: {
operator: 'and',
left: {operator: 'eq', left: 'action', right: 'approve'},
},
flatFilters: [
{
key: 'action',
filters: [{operator: 'eq', value: 'approve'}],
},
],
});
});

afterEach(() => {
(SearchQueryUtils.getCurrentSearchQueryJSON as jest.Mock).mockClear();
});

it('should return all expense reports when shouldSkipActionFiltering is true', () => {
const result = SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT,
data: searchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
shouldSkipActionFiltering: true,
})[0] as TransactionGroupListItemType[];

expect(result.length).toBe(4); // All expense reports returned
});

it('should return only filtered expense reports when shouldSkipActionFiltering is false', () => {
const result = SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT,
data: searchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
shouldSkipActionFiltering: false,
})[0] as TransactionGroupListItemType[];

expect(result.length).toBe(2); // Only filtered expense reports returned
});

it('should apply default filtering behavior when shouldSkipActionFiltering is undefined', () => {
const result = SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT,
data: searchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
})[0] as TransactionGroupListItemType[];

expect(result.length).toBe(2); // Default behavior applies filtering
});
});

describe('Test getSortedSections', () => {
it('should return getSortedReportActionData result when type is CHAT', () => {
const sortedActions = SearchUIUtils.getSortedSections(
Expand Down
Loading