Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no result found doesn't show when the search found nothing in categorize expense #40748

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
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Is there any convention for passing the default value vis-a-vis undefined? undefined looks better but I see passing default values at almost all places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not aware if there is any convention for that, but I also agree it's better to set it as undefined so it uses the default value. If the default value changes, we don't need to update the value we pass.

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
Loading