Skip to content

Commit

Permalink
Merge pull request #34847 from Krishna2323/krishna2323/issue/34111
Browse files Browse the repository at this point in the history
fix: Selecting last possible member to group hides selected members.
  • Loading branch information
Beamanator authored Feb 1, 2024
2 parents b64b408 + ec468ed commit 70dd251
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
22 changes: 22 additions & 0 deletions src/hooks/useSearchTermAndSearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {Dispatch} from 'react';
import {useCallback} from 'react';
import * as Report from '@userActions/Report';

/**
* Hook for fetching reports when user updated search term and hasn't selected max number of participants
*/
const useSearchTermAndSearch = (setSearchTerm: Dispatch<React.SetStateAction<string>>, maxParticipantsReached: boolean) => {
const setSearchTermAndSearchInServer = useCallback(
(text = '') => {
if (text && !maxParticipantsReached) {
Report.searchInServer(text);
}
setSearchTerm(text);
},
[maxParticipantsReached, setSearchTerm],
);

return setSearchTermAndSearchInServer;
};

export default useSearchTermAndSearch;
7 changes: 4 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1923,14 +1923,15 @@ function formatSectionsFromSearchTerm(
selectedOptions: ReportUtils.OptionData[],
filteredRecentReports: ReportUtils.OptionData[],
filteredPersonalDetails: PersonalDetails[],
maxOptionsSelected: boolean,
indexOffset = 0,
personalDetails: OnyxEntry<PersonalDetailsList> = {},
shouldGetOptionDetails = false,
indexOffset = 0,
): SectionForSearchTerm {
// We show the selected participants at the top of the list when there is no search term
// We show the selected participants at the top of the list when there is no search term or maximum number of participants has already been selected
// However, if there is a search term we remove the selected participants from the top of the list unless they are part of the search results
// This clears up space on mobile views, where if you create a group with 4+ people you can't see the selected participants and the search results at the same time
if (searchTerm === '') {
if (searchTerm === '' || maxOptionsSelected) {
return {
section: {
title: undefined,
Expand Down
11 changes: 4 additions & 7 deletions src/pages/NewChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useNetwork from '@hooks/useNetwork';
import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import compose from '@libs/compose';
Expand Down Expand Up @@ -64,6 +65,8 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);

const maxParticipantsReached = selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;
const setSearchTermAndSearchInServer = useSearchTermAndSearch(setSearchTerm, maxParticipantsReached);

const headerMessage = OptionsListUtils.getHeaderMessage(
filteredPersonalDetails.length + filteredRecentReports.length !== 0,
Boolean(filteredUserToInvite),
Expand All @@ -77,7 +80,7 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i
const sectionsList = [];
let indexOffset = 0;

const formatResults = OptionsListUtils.formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecentReports, filteredPersonalDetails, {}, false, indexOffset);
const formatResults = OptionsListUtils.formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecentReports, filteredPersonalDetails, maxParticipantsReached, indexOffset);
sectionsList.push(formatResults.section);
indexOffset = formatResults.newIndexOffset;

Expand Down Expand Up @@ -227,12 +230,6 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i
updateOptions();
}, [didScreenTransitionEnd, updateOptions]);

// When search term updates we will fetch any reports
const setSearchTermAndSearchInServer = useCallback((text = '') => {
Report.searchInServer(text);
setSearchTerm(text);
}, []);

const {inputCallbackRef} = useAutoFocusInput();

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import SelectCircle from '@components/SelectCircle';
import SelectionList from '@components/SelectionList';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Report from '@libs/actions/Report';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -88,6 +88,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
const offlineMessage = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';

const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;
const setSearchTermAndSearchInServer = useSearchTermAndSearch(setSearchTerm, maxParticipantsReached);

/**
* Returns the sections needed for the OptionsSelector
Expand Down Expand Up @@ -133,9 +134,10 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
participants,
chatOptions.recentReports,
chatOptions.personalDetails,
maxParticipantsReached,
indexOffset,
personalDetails,
true,
indexOffset,
);
newSections.push(formatResults.section);
indexOffset = formatResults.newIndexOffset;
Expand Down Expand Up @@ -243,14 +245,6 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
[maxParticipantsReached, newChatOptions, participants, searchTerm],
);

// When search term updates we will fetch any reports
const setSearchTermAndSearchInServer = useCallback((text = '') => {
if (text.length) {
Report.searchInServer(text);
}
setSearchTerm(text);
}, []);

// Right now you can't split a request with a workspace and other additional participants
// This is getting properly fixed in https://github.com/Expensify/App/issues/27508, but as a stop-gap to prevent
// the app from crashing on native when you try to do this, we'll going to hide the button if you have a workspace and other participants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import SelectCircle from '@components/SelectCircle';
import SelectionList from '@components/SelectionList';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useSearchTermAndSearch from '@hooks/useSearchTermAndSearch';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Report from '@libs/actions/Report';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import reportPropTypes from '@pages/reportPropTypes';
Expand Down Expand Up @@ -89,6 +89,9 @@ function MoneyRequestParticipantsSelector({
const {isOffline} = useNetwork();
const personalDetails = usePersonalDetails();

const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;
const setSearchTermAndSearchInServer = useSearchTermAndSearch(setSearchTerm, maxParticipantsReached);

const offlineMessage = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';

const newChatOptions = useMemo(() => {
Expand Down Expand Up @@ -124,8 +127,6 @@ function MoneyRequestParticipantsSelector({
};
}, [betas, reports, participants, personalDetails, searchTerm, iouType, isDistanceRequest]);

const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;

/**
* Returns the sections needed for the OptionsSelector
*
Expand All @@ -140,9 +141,10 @@ function MoneyRequestParticipantsSelector({
participants,
newChatOptions.recentReports,
newChatOptions.personalDetails,
maxParticipantsReached,
indexOffset,
personalDetails,
true,
indexOffset,
);
newSections.push(formatResults.section);
indexOffset = formatResults.newIndexOffset;
Expand Down Expand Up @@ -259,12 +261,6 @@ function MoneyRequestParticipantsSelector({
[maxParticipantsReached, newChatOptions.personalDetails.length, newChatOptions.recentReports.length, newChatOptions.userToInvite, participants, searchTerm],
);

// When search term updates we will fetch any reports
const setSearchTermAndSearchInServer = useCallback((text = '') => {
Report.searchInServer(text);
setSearchTerm(text);
}, []);

// Right now you can't split a request with a workspace and other additional participants
// This is getting properly fixed in https://github.com/Expensify/App/issues/27508, but as a stop-gap to prevent
// the app from crashing on native when you try to do this, we'll going to show error message if you have a workspace and other participants
Expand Down

0 comments on commit 70dd251

Please sign in to comment.