Skip to content

Commit

Permalink
Merge pull request #40748 from bernhardoj/fix/40520-no-result-found-f…
Browse files Browse the repository at this point in the history
…or-invalid-search

Fix no result found doesn't show when the search found nothing in categorize expense
  • Loading branch information
thienlnam authored Apr 23, 2024
2 parents dadf0ba + 6462567 commit 0358841
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,7 @@ function getFilteredOptions(
includePolicyReportFieldOptions = false,
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includePersonalDetails = true,
) {
return getOptions(
{reports, personalDetails},
Expand All @@ -2016,7 +2017,7 @@ function getFilteredOptions(
searchInputValue: searchValue.trim(),
selectedOptions,
includeRecentReports: true,
includePersonalDetails: true,
includePersonalDetails,
maxRecentReportsToShow: 5,
excludeLogins,
includeOwnedWorkspaceChats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
const {isSmallScreenWidth} = useWindowDimensions();

const isIOUSplit = iouType === CONST.IOU.TYPE.SPLIT;
const isCategorizeOrShareAction = [CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action);

useEffect(() => {
Report.searchInServer(debouncedSearchTerm.trim());
Expand Down Expand Up @@ -117,15 +118,22 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
// sees the option to submit an expense from their admin on their own Workspace Chat.
(iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT,

(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && ![CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action),
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
false,
{},
[],
false,
{},
[],
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && ![CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action),
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
false,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
!isCategorizeOrShareAction,
);

const formatResults = OptionsListUtils.formatSectionsFromSearchTerm(
Expand All @@ -150,13 +158,11 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
shouldShow: chatOptions.recentReports.length > 0,
});

if (![CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action)) {
newSections.push({
title: translate('common.contacts'),
data: chatOptions.personalDetails,
shouldShow: chatOptions.personalDetails.length > 0,
});
}
newSections.push({
title: translate('common.contacts'),
data: chatOptions.personalDetails,
shouldShow: chatOptions.personalDetails.length > 0,
});

if (chatOptions.userToInvite && !OptionsListUtils.isCurrentUser(chatOptions.userToInvite)) {
newSections.push({
Expand Down Expand Up @@ -185,6 +191,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
personalDetails,
translate,
didScreenTransitionEnd,
isCategorizeOrShareAction,
]);

/**
Expand Down Expand Up @@ -349,13 +356,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
);

const isAllSectionsEmpty = lodashEvery(sections, (section) => section.data.length === 0);
if (
[CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action) &&
isAllSectionsEmpty &&
didScreenTransitionEnd &&
debouncedSearchTerm.trim() === '' &&
areOptionsInitialized
) {
if (isCategorizeOrShareAction && isAllSectionsEmpty && didScreenTransitionEnd && debouncedSearchTerm.trim() === '' && areOptionsInitialized) {
return renderEmptyWorkspaceView();
}

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,36 @@ describe('OptionsListUtils', () => {
expect(results.personalDetails[2].text).toBe('Captain America');
expect(results.personalDetails[3].text).toBe('Invisible Woman');

// When we don't include personal detail to the result
results = OptionsListUtils.getFilteredOptions(
[],
OPTIONS.personalDetails,
[],
'',
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
false,
);

// Then no personal detail options will be returned
expect(results.personalDetails.length).toBe(0);

// When we provide a search value that does not match any personal details
results = OptionsListUtils.getFilteredOptions(OPTIONS.reports, OPTIONS.personalDetails, [], 'magneto');

Expand Down

0 comments on commit 0358841

Please sign in to comment.