Skip to content

Commit

Permalink
enforce empty search term with non-empty options
Browse files Browse the repository at this point in the history
  • Loading branch information
c3024 committed Oct 14, 2024
1 parent 28b226d commit b69ea35
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 77 deletions.
89 changes: 63 additions & 26 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2205,34 +2205,71 @@ function getIOUConfirmationOptionsFromPayeePersonalDetail(personalDetail: OnyxEn
/**
* Build the options for the New Group view
*/
type FilteredOptionsParams = {
reports?: Array<SearchOption<Report>>;
personalDetails?: Array<SearchOption<PersonalDetails>>;
betas?: OnyxEntry<Beta[]>;
searchValue?: string;
selectedOptions?: Array<Partial<ReportUtils.OptionData>>;
excludeLogins?: string[];
includeOwnedWorkspaceChats?: boolean;
includeP2P?: boolean;
includeCategories?: boolean;
categories?: PolicyCategories;
recentlyUsedCategories?: string[];
includeTags?: boolean;
tags?: PolicyTags | Array<PolicyTag | SelectedTagOption>;
recentlyUsedTags?: string[];
canInviteUser?: boolean;
includeSelectedOptions?: boolean;
includeTaxRates?: boolean;
taxRates?: TaxRatesWithDefault;
maxRecentReportsToShow?: number;
includeSelfDM?: boolean;
includePolicyReportFieldOptions?: boolean;
policyReportFieldOptions?: string[];
recentlyUsedPolicyReportFieldOptions?: string[];
includeInvoiceRooms?: boolean;
action?: IOUAction;
sortByReportTypeInSearch?: boolean;
};

type FilteredOptionsParamsWithDefaultSearchValue = Omit<FilteredOptionsParams, 'searchValue'> & {searchValue?: ''};

type FilteredOptionsParamsWithoutOptions = Omit<FilteredOptionsParams, 'reports' | 'personalDetails'> & { reports?: []; personalDetails?: [] };

function getFilteredOptions(
reports: Array<SearchOption<Report>> = [],
personalDetails: Array<SearchOption<PersonalDetails>> = [],
betas: OnyxEntry<Beta[]> = [],
searchValue = '',
selectedOptions: Array<Partial<ReportUtils.OptionData>> = [],
excludeLogins: string[] = [],
includeOwnedWorkspaceChats = false,
includeP2P = true,
includeCategories = false,
categories: PolicyCategories = {},
recentlyUsedCategories: string[] = [],
includeTags = false,
tags: PolicyTags | Array<PolicyTag | SelectedTagOption> = {},
recentlyUsedTags: string[] = [],
canInviteUser = true,
includeSelectedOptions = false,
includeTaxRates = false,
maxRecentReportsToShow: number = CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
taxRates: TaxRatesWithDefault = {} as TaxRatesWithDefault,
includeSelfDM = false,
includePolicyReportFieldOptions = false,
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
sortByReportTypeInSearch = false,
params: FilteredOptionsParamsWithDefaultSearchValue | FilteredOptionsParamsWithoutOptions,
) {

const {
reports = [],
personalDetails = [],
betas = [],
searchValue = '',
selectedOptions = [],
excludeLogins = [],
includeOwnedWorkspaceChats = false,
includeP2P = true,
includeCategories = false,
categories = {},
recentlyUsedCategories = [],
includeTags = false,
tags = {},
recentlyUsedTags = [],
canInviteUser = true,
includeSelectedOptions = false,
includeTaxRates = false,
maxRecentReportsToShow = CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
taxRates = {} as TaxRatesWithDefault,
includeSelfDM = false,
includePolicyReportFieldOptions = false,
policyReportFieldOptions = [],
recentlyUsedPolicyReportFieldOptions = [],
includeInvoiceRooms = false,
action,
sortByReportTypeInSearch,
} = params;
return getOptions(
{reports, personalDetails},
{
Expand Down
35 changes: 10 additions & 25 deletions src/pages/EditReportFieldDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,22 @@ function EditReportFieldDropdownPage({onSubmit, fieldKey, fieldValue, fieldOptio
const [sections, headerMessage] = useMemo(() => {
const validFieldOptions = fieldOptions?.filter((option) => !!option)?.sort(localeCompare);

const {policyReportFieldOptions} = OptionsListUtils.getFilteredOptions(
[],
[],
[],
debouncedSearchValue,
[
const {policyReportFieldOptions} = OptionsListUtils.getFilteredOptions({
searchValue: debouncedSearchValue,
selectedOptions: [
{
keyForList: fieldValue,
searchText: fieldValue,
text: fieldValue,
},
],
[],
false,
false,
false,
{},
[],
false,
{},
[],
false,
false,
undefined,
CONST.IOU.MAX_RECENT_REPORTS_TO_SHOW,
undefined,
undefined,
true,
validFieldOptions,
recentlyUsedOptions,
);

includeP2P: false,
canInviteUser: false,
includePolicyReportFieldOptions: true,
policyReportFieldOptions: validFieldOptions,
recentlyUsedPolicyReportFieldOptions: recentlyUsedOptions,
});

const policyReportFieldData = policyReportFieldOptions?.[0]?.data ?? [];
const header = OptionsListUtils.getHeaderMessageForNonUserList(policyReportFieldData.length > 0, debouncedSearchValue);
Expand Down
39 changes: 13 additions & 26 deletions src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,40 +114,26 @@ function MoneyRequestParticipantsSelector({
};
}

const optionList = OptionsListUtils.getFilteredOptions(
options.reports,
options.personalDetails,
const optionList = OptionsListUtils.getFilteredOptions({
reports: options.reports,
personalDetails: options.personalDetails,
betas,
'',
participants as Participant[],
CONST.EXPENSIFY_EMAILS,
selectedOptions: participants as Participant[],
excludeLogins: CONST.EXPENSIFY_EMAILS,

// If we are using this component in the "Submit expense" or the combined submit/track flow then we pass the includeOwnedWorkspaceChats argument so that the current user
// sees the option to submit an expense from their admin on their own Workspace Chat.
(iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.CREATE || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT,
includeOwnedWorkspaceChats: (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.CREATE || iouType === CONST.IOU.TYPE.SPLIT) && action !== CONST.IOU.ACTION.SUBMIT,

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
false,
{},
[],
false,
{},
[],
includeP2P: (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
false,
false,
0,
undefined,
undefined,
undefined,
undefined,
undefined,
iouType === CONST.IOU.TYPE.INVOICE,
canInviteUser: (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && !isCategorizeOrShareAction,
includeInvoiceRooms: iouType === CONST.IOU.TYPE.INVOICE,
action,
isPaidGroupPolicy,
);
sortByReportTypeInSearch: isPaidGroupPolicy,
searchValue: '',
});

return optionList;
}, [
Expand All @@ -163,6 +149,7 @@ function MoneyRequestParticipantsSelector({
options.reports,
participants,
isPaidGroupPolicy,
debouncedSearchTerm
]);

const chatOptions = useMemo(() => {
Expand Down

0 comments on commit b69ea35

Please sign in to comment.