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

perf: filter Share Logs options #40285

Merged
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
16 changes: 14 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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 @@ -2450,7 +2450,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 @@ -2510,6 +2518,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
Loading