Skip to content

Commit

Permalink
Merge pull request #40285 from callstack-internal/perf/share-logs-fil…
Browse files Browse the repository at this point in the history
…ter-options

perf: filter Share Logs options
  • Loading branch information
roryabraham authored Jul 18, 2024
2 parents eb6ca6d + c6f97d5 commit d54373e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
16 changes: 14 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: bo
type FilterOptionsConfig = Pick<
GetOptionsConfig,
'sortByReportTypeInSearch' | 'canInviteUser' | 'betas' | 'selectedOptions' | 'excludeUnknownUsers' | 'excludeLogins' | 'maxRecentReportsToShow'
> & {preferChatroomsOverThreads?: boolean};
> & {preferChatroomsOverThreads?: boolean; includeChatRoomsByParticipants?: boolean};

type HasText = {
text?: string;
Expand Down Expand Up @@ -2473,7 +2473,15 @@ function getFirstKeyForList(data?: Option[] | null) {
* Filters options based on the search input value
*/
function filterOptions(options: Options, searchInputValue: string, config?: FilterOptionsConfig): Options {
const {sortByReportTypeInSearch = false, canInviteUser = true, betas = [], maxRecentReportsToShow = 0, excludeLogins = [], preferChatroomsOverThreads = false} = config ?? {};
const {
sortByReportTypeInSearch = false,
canInviteUser = true,
betas = [],
maxRecentReportsToShow = 0,
excludeLogins = [],
preferChatroomsOverThreads = false,
includeChatRoomsByParticipants = false,
} = config ?? {};
if (searchInputValue.trim() === '' && maxRecentReportsToShow > 0) {
return {...options, recentReports: options.recentReports.slice(0, maxRecentReportsToShow)};
}
Expand Down Expand Up @@ -2533,6 +2541,10 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
if (item.subtitle) {
values.push(item.subtitle);
}

if (includeChatRoomsByParticipants) {
values = values.concat(getParticipantsLoginsArray(item));
}
}

if (!item.isChatRoom) {
Expand Down
46 changes: 34 additions & 12 deletions src/pages/settings/AboutPage/ShareLogList/BaseShareLogList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,52 @@ function BaseShareLogList({onAttachLogToReport}: BaseShareLogListProps) {
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});
const {options, areOptionsInitialized} = useOptionsList();

const searchOptions = useMemo(() => {
const defaultOptions = useMemo(() => {
if (!areOptionsInitialized) {
return {
recentReports: [],
personalDetails: [],
userToInvite: undefined,
userToInvite: null,
currentUserOption: null,
categoryOptions: [],
tagOptions: [],
taxRatesOptions: [],
headerMessage: '',
};
}
const {
recentReports: localRecentReports,
personalDetails: localPersonalDetails,
userToInvite: localUserToInvite,
} = OptionsListUtils.getShareLogOptions(options, debouncedSearchValue.trim(), betas ?? []);
const shareLogOptions = OptionsListUtils.getShareLogOptions(options, '', betas ?? []);

const header = OptionsListUtils.getHeaderMessage((localRecentReports?.length || 0) + (localPersonalDetails?.length || 0) !== 0, !!localUserToInvite, debouncedSearchValue);
const header = OptionsListUtils.getHeaderMessage(
(shareLogOptions.recentReports.length || 0) + (shareLogOptions.personalDetails.length || 0) !== 0,
!!shareLogOptions.userToInvite,
'',
);

return {
recentReports: localRecentReports,
personalDetails: localPersonalDetails,
userToInvite: localUserToInvite,
...shareLogOptions,
headerMessage: header,
};
}, [areOptionsInitialized, options, debouncedSearchValue, betas]);
}, [areOptionsInitialized, options, betas]);

const searchOptions = useMemo(() => {
if (debouncedSearchValue.trim() === '') {
return defaultOptions;
}

const filteredOptions = OptionsListUtils.filterOptions(defaultOptions, debouncedSearchValue, {
includeChatRoomsByParticipants: true,
preferChatroomsOverThreads: true,
sortByReportTypeInSearch: true,
});

const headerMessage = OptionsListUtils.getHeaderMessage(
(filteredOptions.recentReports?.length || 0) + (filteredOptions.personalDetails?.length || 0) !== 0,
!!filteredOptions.userToInvite,
debouncedSearchValue.trim(),
);

return {...filteredOptions, headerMessage};
}, [debouncedSearchValue, defaultOptions]);

const sections = useMemo(() => {
const sectionsList = [];
Expand Down

0 comments on commit d54373e

Please sign in to comment.