Skip to content

Commit

Permalink
Merge pull request #22639 from Expensify/beaman-removeReportParticipa…
Browse files Browse the repository at this point in the history
…ntsArray

Replace `report.participants` with `*.participantAccountIDs` (Pt 1)
  • Loading branch information
AndrewGable authored Jul 17, 2023
2 parents 2ebf127 + 293da4f commit 798016a
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 138 deletions.
14 changes: 7 additions & 7 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const propTypes = {
iouType: PropTypes.string,

/** Selected participants from MoneyRequestModal with login / accountID */
participants: PropTypes.arrayOf(optionPropTypes).isRequired,
selectedParticipants: PropTypes.arrayOf(optionPropTypes).isRequired,

/** Payee of the money request with login */
payeePersonalDetails: optionPropTypes,
Expand Down Expand Up @@ -130,14 +130,14 @@ function MoneyRequestConfirmationList(props) {
];
}, [props.hasMultipleParticipants, props.iouAmount, props.iouCurrencyCode, translate]);

const selectedParticipants = useMemo(() => _.filter(props.participants, (participant) => participant.selected), [props.participants]);
const selectedParticipants = useMemo(() => _.filter(props.selectedParticipants, (participant) => participant.selected), [props.selectedParticipants]);
const payeePersonalDetails = useMemo(() => props.payeePersonalDetails || props.currentUserPersonalDetails, [props.payeePersonalDetails, props.currentUserPersonalDetails]);
const canModifyParticipants = !props.isReadOnly && props.canModifyParticipants && props.hasMultipleParticipants;
const shouldDisableWhoPaidSection = canModifyParticipants;

const optionSelectorSections = useMemo(() => {
const sections = [];
const unselectedParticipants = _.filter(props.participants, (participant) => !participant.selected);
const unselectedParticipants = _.filter(props.selectedParticipants, (participant) => !participant.selected);
if (props.hasMultipleParticipants) {
const formattedSelectedParticipants = getParticipantsWithAmount(selectedParticipants);
const formattedParticipantsList = _.union(formattedSelectedParticipants, unselectedParticipants);
Expand Down Expand Up @@ -166,14 +166,14 @@ function MoneyRequestConfirmationList(props) {
} else {
sections.push({
title: translate('common.to'),
data: props.participants,
data: props.selectedParticipants,
shouldShow: true,
indexOffset: 0,
});
}
return sections;
}, [
props.participants,
props.selectedParticipants,
props.hasMultipleParticipants,
props.iouAmount,
props.iouCurrencyCode,
Expand Down Expand Up @@ -250,7 +250,7 @@ function MoneyRequestConfirmationList(props) {

const shouldShowSettlementButton = props.iouType === CONST.IOU.MONEY_REQUEST_TYPE.SEND;
const shouldDisableButton = selectedParticipants.length === 0;
const recipient = props.participants[0] || {};
const recipient = props.selectedParticipants[0] || {};

return shouldShowSettlementButton ? (
<SettlementButton
Expand All @@ -271,7 +271,7 @@ function MoneyRequestConfirmationList(props) {
options={splitOrRequestOptions}
/>
);
}, [confirm, props.participants, props.bankAccountRoute, props.iouCurrencyCode, props.iouType, props.isReadOnly, props.policyID, selectedParticipants, splitOrRequestOptions]);
}, [confirm, props.selectedParticipants, props.bankAccountRoute, props.iouCurrencyCode, props.iouType, props.isReadOnly, props.policyID, selectedParticipants, splitOrRequestOptions]);

return (
<OptionsSelector
Expand Down
81 changes: 25 additions & 56 deletions src/libs/E2E/apiMocks/openApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['concierge@expensify.com'],
participantAccountIDs: [22],
isPinned: true,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-03 06:45:00',
Expand All @@ -1625,7 +1625,7 @@ export default () => ({
chatType: 'policyExpenseChat',
ownerAccountID: 17,
policyID: 'C28C2634DD7226B8',
participants: ['applausetester@applause.expensifail.com', 'applausetester+perf2@applause.expensifail.com'],
participantAccountIDs: [20, 17],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-11-03 20:30:55.599',
Expand All @@ -1647,7 +1647,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['applausetester+ihchat4@applause.expensifail.com'],
participantAccountIDs: [14],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-02 20:03:42',
Expand All @@ -1669,7 +1669,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake3@gmail.com'],
participantAccountIDs: [4],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-11-04 21:18:00.038',
Expand All @@ -1691,7 +1691,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake3@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'],
participantAccountIDs: [4, 16, 18, 19],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-01 20:48:16',
Expand All @@ -1713,7 +1713,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake1@gmail.com', 'fake2@gmail.com', 'fake3@gmail.com', 'fake4@gmail.com', 'fake5@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'],
participantAccountIDs: [2, 1, 4, 3, 5, 16, 18, 19],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-01 20:49:11',
Expand All @@ -1735,7 +1735,7 @@ export default () => ({
chatType: 'policyExpenseChat',
ownerAccountID: 17,
policyID: '1CE001C4B9F3CA54',
participants: ['fake3@gmail.com', 'applausetester+perf2@applause.expensifail.com'],
participantAccountIDs: [4, 17],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-16 12:30:57',
Expand All @@ -1757,7 +1757,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['applausetester+ihchat4@applause.expensifail.com', 'fake6@gmail.com'],
participantAccountIDs: [14, 16],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-02 20:03:41',
Expand All @@ -1779,7 +1779,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake6@gmail.com'],
participantAccountIDs: [16],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-12-09 10:17:18.362',
Expand All @@ -1802,7 +1802,7 @@ export default () => ({
chatType: 'policyRoom',
ownerAccountID: 0,
policyID: 'C28C2634DD7226B8',
participants: ['applausetester+pd1005@applause.expensifail.com'],
participantAccountIDs: [15],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-10-12 17:47:45.228',
Expand All @@ -1824,7 +1824,7 @@ export default () => ({
chatType: 'policyAnnounce',
ownerAccountID: 0,
policyID: 'A6511FF8D2EE7661',
participants: ['applausetester+perf2@applause.expensifail.com'],
participantAccountIDs: [17],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand All @@ -1846,7 +1846,7 @@ export default () => ({
chatType: 'policyExpenseChat',
ownerAccountID: 17,
policyID: 'A6511FF8D2EE7661',
participants: ['applausetester+perf2@applause.expensifail.com'],
participantAccountIDs: [17],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand All @@ -1868,13 +1868,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: [
'concierge@expensify.com',
'applausetester+0901abb@applause.expensifail.com',
'andreylazutkinutest@gmail.com',
'applausetester+0704sveta@applause.expensifail.com',
'fake3@gmail.com',
],
participantAccountIDs: [22, 10, 6, 8, 4],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-11-03 20:48:58.815',
Expand All @@ -1896,7 +1890,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['applausetester+42222abb@applause.expensifail.com'],
participantAccountIDs: [12],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-12-01 08:05:11.009',
Expand All @@ -1918,7 +1912,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake1@gmail.com'],
participantAccountIDs: [2],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand All @@ -1940,7 +1934,7 @@ export default () => ({
chatType: 'policyRoom',
ownerAccountID: 0,
policyID: 'C28C2634DD7226B8',
participants: ['applausetester+pd1005@applause.expensifail.com'],
participantAccountIDs: [15],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-10-12 12:20:00.668',
Expand All @@ -1962,7 +1956,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['christoph+hightraffic@margelo.io'],
participantAccountIDs: [21],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-12-16 18:14:00.208',
Expand All @@ -1985,7 +1979,7 @@ export default () => ({
chatType: 'policyRoom',
ownerAccountID: 0,
policyID: 'C28C2634DD7226B8',
participants: ['applausetester+pd1005@applause.expensifail.com'],
participantAccountIDs: [15],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-11-29 12:38:15.985',
Expand All @@ -2009,7 +2003,7 @@ export default () => ({
chatType: 'domainAll',
ownerAccountID: 99,
policyID: '_FAKE_',
participants: ['applausetester+bernardo@applause.expensifail.com'],
participantAccountIDs: [13],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-11-29 21:08:00.793',
Expand All @@ -2031,16 +2025,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: [
'andreylazutkinutest@gmail.com',
'fake1@gmail.com',
'applausetester+0707abb@applause.expensifail.com',
'fake3@gmail.com',
'fake5@gmail.com',
'applausetester+0604lsn@applause.expensifail.com',
'andreylazutkinutest+0904@gmail.com',
'applausetester+1904lsn@applause.expensifail.com',
],
participantAccountIDs: [6, 2, 9, 4, 5, 7, 100, 11],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand All @@ -2062,7 +2047,7 @@ export default () => ({
chatType: 'policyAdmins',
ownerAccountID: 0,
policyID: 'A6511FF8D2EE7661',
participants: ['applausetester+perf2@applause.expensifail.com'],
participantAccountIDs: [17],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand All @@ -2084,16 +2069,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: [
'concierge@expensify.com',
'andreylazutkinutest@gmail.com',
'fake1@gmail.com',
'svetlanalazutkinautest+0211@gmail.com',
'applausetester+0707abb@applause.expensifail.com',
'fake3@gmail.com',
'fake5@gmail.com',
'applausetester+0604lsn@applause.expensifail.com',
],
participantAccountIDs: [22, 6, 2, 23, 9, 4, 5, 7],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-09-15 12:57:59.526',
Expand All @@ -2116,14 +2092,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: [
'concierge@expensify.com',
'andreylazutkinutest@gmail.com',
'fake3@gmail.com',
'fake5@gmail.com',
'tayla.lay@team.expensify.com',
'andreylazutkinutest+160956@gmail.com',
],
participantAccountIDs: [22, 6, 4, 5, 24, 101],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-09-16 11:12:46.739',
Expand All @@ -2145,7 +2114,7 @@ export default () => ({
chatType: 'policyRoom',
ownerAccountID: 0,
policyID: 'C28C2634DD7226B8',
participants: ['applausetester+pd1005@applause.expensifail.com'],
participantAccountIDs: [15],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-10-12 12:46:43.577',
Expand All @@ -2167,7 +2136,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake5@gmail.com'],
participantAccountIDs: [5],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/E2E/apiMocks/openReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default () => ({
chatType: '',
ownerAccountID: 0,
policyID: '_FAKE_',
participants: ['fake1@gmail.com', 'fake2@gmail.com', 'fake3@gmail.com', 'fake4@gmail.com', 'fake5@gmail.com', 'fake6@gmail.com', 'fake7@gmail.com', 'fake8@gmail.com'],
participantAccountIDs: [2, 1, 4, 3, 5, 16, 18, 19],
isPinned: false,
lastReadCreated: '1980-01-01 00:00:00.000',
lastVisibleActionCreated: '2022-08-01 20:49:11',
Expand Down
15 changes: 14 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Onyx.connect({
callback: (val) => (loginList = _.isEmpty(val) ? {} : val),
});

let allPersonalDetails;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (allPersonalDetails = _.isEmpty(val) ? {} : val),
});

let preferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
Expand Down Expand Up @@ -339,7 +345,14 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic

Array.prototype.push.apply(searchTerms, chatRoomSubtitle.split(/[,\s]/));
} else {
searchTerms = searchTerms.concat(report.participants);
const participantAccountIDs = report.participantAccountIDs || [];
for (let i = 0; i < participantAccountIDs.length; i++) {
const accountID = participantAccountIDs[i];

if (allPersonalDetails[accountID] && allPersonalDetails[accountID].login) {
searchTerms = searchTerms.concat(allPersonalDetails[accountID].login);
}
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2139,14 +2139,14 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep

/**
* Attempts to find a report in onyx with the provided list of participants. Does not include threads
* @param {Array} newParticipantList
* @param {Array<Number>} newParticipantList
* @returns {Array|undefined}
*/
function getChatByParticipants(newParticipantList) {
newParticipantList.sort();
return _.find(allReports, (report) => {
// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
if (!report || !report.participantAccountIDs || isChatThread(report)) {
if (!report || _.isEmpty(report.participantAccountIDs) || isChatThread(report)) {
return false;
}

Expand All @@ -2168,7 +2168,7 @@ function getChatByParticipantsByLoginList(participantsLoginList) {
participantsLoginList.sort();
return _.find(allReports, (report) => {
// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
if (!report || !report.participants || isThread(report)) {
if (!report || _.isEmpty(report.participantAccountIDs) || isThread(report)) {
return false;
}

Expand Down Expand Up @@ -2340,7 +2340,7 @@ function canRequestMoney(report) {

/**
* @param {Object} report
* @param {Array} reportParticipants
* @param {Array<Number>} reportParticipants
* @param {Array} betas
* @returns {Array}
*/
Expand Down
Loading

0 comments on commit 798016a

Please sign in to comment.