Skip to content

Commit

Permalink
Merge pull request #30471 from Expensify/marcaaron-searchForWorkspace
Browse files Browse the repository at this point in the history
Add server-side report searching for task destination and money requests
  • Loading branch information
srikarparsi authored Oct 31, 2023
2 parents 5b5d465 + 0de33e3 commit 02ad2fc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import _ from 'underscore';
import OptionsSelector from '@components/OptionsSelector';
import refPropTypes from '@components/refPropTypes';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useNetwork from '@hooks/useNetwork';
import * as Report from '@libs/actions/Report';
import * as Browser from '@libs/Browser';
import compose from '@libs/compose';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -59,6 +61,9 @@ const propTypes = {
/** Whether the money request is a distance request or not */
isDistanceRequest: PropTypes.bool,

/** Whether we are searching for reports in the server */
isSearchingForReports: PropTypes.bool,

...withLocalizePropTypes,
};

Expand All @@ -70,6 +75,7 @@ const defaultProps = {
reports: {},
betas: [],
isDistanceRequest: false,
isSearchingForReports: false,
};

function MoneyRequestParticipantsSelector({
Expand All @@ -85,13 +91,15 @@ function MoneyRequestParticipantsSelector({
safeAreaPaddingBottomStyle,
iouType,
isDistanceRequest,
isSearchingForReports,
}) {
const [searchTerm, setSearchTerm] = useState('');
const [newChatOptions, setNewChatOptions] = useState({
recentReports: [],
personalDetails: [],
userToInvite: null,
});
const {isOffline} = useNetwork();

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

Expand Down Expand Up @@ -244,6 +252,14 @@ function MoneyRequestParticipantsSelector({
});
}, [betas, reports, participants, personalDetails, translate, searchTerm, setNewChatOptions, iouType, isDistanceRequest]);

// 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 All @@ -262,18 +278,20 @@ function MoneyRequestParticipantsSelector({
selectedOptions={participants}
value={searchTerm}
onSelectRow={addSingleParticipant}
onChangeText={setSearchTerm}
onChangeText={setSearchTermAndSearchInServer}
ref={forwardedRef}
headerMessage={headerMessage}
boldStyle
shouldShowConfirmButton={shouldShowConfirmButton && isAllowedToSplit}
confirmButtonText={translate('iou.addToSplit')}
onConfirmSelection={navigateToSplit}
textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')}
textInputAlert={isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''}
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
shouldShowOptions={isOptionsDataReady}
shouldPreventDefaultFocusOnSelectRow={!Browser.isMobile()}
shouldDelayFocus
isLoadingNewOptions={isSearchingForReports}
/>
</View>
);
Expand Down Expand Up @@ -305,5 +323,9 @@ export default compose(
betas: {
key: ONYXKEYS.BETAS,
},
isSearchingForReports: {
key: ONYXKEYS.IS_SEARCHING_FOR_REPORTS,
initWithStoredValues: false,
},
}),
)(MoneyRequestParticipantsSelectorWithRef);
30 changes: 24 additions & 6 deletions src/pages/tasks/TaskShareDestinationSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import OptionsSelector from '@components/OptionsSelector';
import ScreenWrapper from '@components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useNetwork from '@hooks/useNetwork';
import * as Report from '@libs/actions/Report';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand All @@ -32,21 +34,26 @@ const propTypes = {
/** All reports shared with the user */
reports: PropTypes.objectOf(reportPropTypes),

/** Whether we are searching for reports in the server */
isSearchingForReports: PropTypes.bool,

...withLocalizePropTypes,
};

const defaultProps = {
betas: [],
personalDetails: {},
reports: {},
isSearchingForReports: false,
};

function TaskShareDestinationSelectorModal(props) {
const [searchValue, setSearchValue] = useState('');
const [headerMessage, setHeaderMessage] = useState('');
const [filteredRecentReports, setFilteredRecentReports] = useState([]);

const {isSearchingForReports} = props;
const optionRef = useRef();
const {isOffline} = useNetwork();

const filteredReports = useMemo(() => {
const reports = {};
Expand Down Expand Up @@ -78,10 +85,6 @@ function TaskShareDestinationSelectorModal(props) {
};
}, [updateOptions]);

const onChangeText = (newSearchTerm = '') => {
setSearchValue(newSearchTerm);
};

const getSections = () => {
const sections = [];
let indexOffset = 0;
Expand Down Expand Up @@ -111,7 +114,16 @@ function TaskShareDestinationSelectorModal(props) {
}
};

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

const sections = getSections();

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -129,16 +141,18 @@ function TaskShareDestinationSelectorModal(props) {
sections={sections}
value={searchValue}
onSelectRow={selectReport}
onChangeText={onChangeText}
onChangeText={setSearchTermAndSearchInServer}
headerMessage={headerMessage}
hideSection
Headers
showTitleTooltip
shouldShowOptions={didScreenTransitionEnd}
textInputLabel={props.translate('optionsSelector.nameEmailOrPhoneNumber')}
textInputAlert={isOffline ? `${props.translate('common.youAppearToBeOffline')} ${props.translate('search.resultsAreLimited')}` : ''}
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
autoFocus={false}
ref={optionRef}
isLoadingNewOptions={isSearchingForReports}
/>
</View>
</>
Expand All @@ -163,5 +177,9 @@ export default compose(
betas: {
key: ONYXKEYS.BETAS,
},
isSearchingForReports: {
key: ONYXKEYS.IS_SEARCHING_FOR_REPORTS,
initWithStoredValues: false,
},
}),
)(TaskShareDestinationSelectorModal);

0 comments on commit 02ad2fc

Please sign in to comment.