Skip to content

Commit

Permalink
Merge pull request #53056 from margelo/cleanup/filterOptions-getOptio…
Browse files Browse the repository at this point in the history
…ns-usage

cleanup: consolidate all `getFilteredOptions` and `getOptions` calls into one function `getOptions`
  • Loading branch information
aldo-expensify authored Nov 28, 2024
2 parents ecaa321 + fb5bf7c commit 988608f
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
if (!areOptionsInitialized || !isScreenTransitionEnd) {
return defaultListOptions;
}
return OptionsListUtils.getSearchOptions(options, '', undefined, false);
return OptionsListUtils.getSearchOptions(options, undefined, false);
}, [areOptionsInitialized, isScreenTransitionEnd, options]);

const chatOptions = useMemo(() => {
Expand Down
18 changes: 11 additions & 7 deletions src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
return defaultListOptions;
}

return OptionsListUtils.getFilteredOptions({
reports: options.reports,
personalDetails: options.personalDetails,
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS,
maxRecentReportsToShow: 0,
});
return OptionsListUtils.getOptions(
{
reports: options.reports,
personalDetails: options.personalDetails,
},
{
selectedOptions,
excludeLogins: CONST.EXPENSIFY_EMAILS,
maxRecentReportsToShow: 0,
},
);
}, [areOptionsInitialized, options.personalDetails, options.reports, selectedOptions]);

const chatOptions = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps)
if (!areOptionsInitialized) {
return {recentReports: [], personalDetails: [], userToInvite: null, currentUserOption: null};
}
return OptionsListUtils.getSearchOptions(options, '', betas ?? []);
return OptionsListUtils.getSearchOptions(options, betas ?? []);
}, [areOptionsInitialized, betas, options]);

const filteredOptions = useMemo(() => {
Expand Down
19 changes: 11 additions & 8 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function SearchRouterList(
if (!areOptionsInitialized) {
return defaultListOptions;
}
return OptionsListUtils.getSearchOptions(options, '', betas ?? []);
return OptionsListUtils.getSearchOptions(options, betas ?? []);
}, [areOptionsInitialized, betas, options]);

const typeAutocompleteList = Object.values(CONST.SEARCH.DATA_TYPES);
Expand All @@ -140,13 +140,16 @@ function SearchRouterList(
return [];
}

const filteredOptions = OptionsListUtils.getFilteredOptions({
reports: options.reports,
personalDetails: options.personalDetails,
excludeLogins: CONST.EXPENSIFY_EMAILS,
maxRecentReportsToShow: 0,
includeSelfDM: true,
});
const filteredOptions = OptionsListUtils.getOptions(
{
reports: options.reports,
personalDetails: options.personalDetails,
},
{
excludeLogins: CONST.EXPENSIFY_EMAILS,
includeSelfDM: true,
},
);

// This cast is needed as something is incorrect in types OptionsListUtils.getOptions around l1490 and includeRecentReports types
const personalDetailsFromOptions = filteredOptions.personalDetails.map((option) => (option as SearchOption<PersonalDetails>).item);
Expand Down
Loading

0 comments on commit 988608f

Please sign in to comment.