Skip to content

Commit 245b81d

Browse files
authored
Merge pull request #24019 from Thanos30/fix/task-share-destination-fixes
2 parents b08bf66 + 18daf91 commit 245b81d

File tree

5 files changed

+48
-49
lines changed

5 files changed

+48
-49
lines changed

src/libs/OptionsListUtils.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ function getOptions(
615615
includeThreads = false,
616616
includeTasks = false,
617617
includeMoneyRequests = false,
618+
excludeUnknownUsers = false,
618619
},
619620
) {
620621
if (!isPersonalDetailsReady(personalDetails)) {
@@ -796,7 +797,8 @@ function getOptions(
796797
((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue) && !Str.endsWith(searchValue, CONST.SMS.DOMAIN)) ||
797798
(parsedPhoneNumber.possible && Str.isValidPhone(LoginUtils.getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number.input)))) &&
798799
!_.find(loginOptionsToExclude, (loginOptionToExclude) => loginOptionToExclude.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase()) &&
799-
(searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas))
800+
(searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) &&
801+
!excludeUnknownUsers
800802
) {
801803
// Generates an optimistic account ID for new users not yet saved in Onyx
802804
const optimisticAccountID = UserUtils.generateAccountID(searchValue);
@@ -966,17 +968,32 @@ function getNewChatOptions(reports, personalDetails, betas = [], searchValue = '
966968
*
967969
*/
968970

969-
function getShareDestinationOptions(reports, personalDetails, betas = [], searchValue = '', selectedOptions = [], excludeLogins = [], includeOwnedWorkspaceChats = true) {
971+
function getShareDestinationOptions(
972+
reports,
973+
personalDetails,
974+
betas = [],
975+
searchValue = '',
976+
selectedOptions = [],
977+
excludeLogins = [],
978+
includeOwnedWorkspaceChats = true,
979+
excludeUnknownUsers = true,
980+
) {
970981
return getOptions(reports, personalDetails, {
971982
betas,
972983
searchInputValue: searchValue.trim(),
973984
selectedOptions,
974-
maxRecentReportsToShow: 5,
985+
maxRecentReportsToShow: 0, // Unlimited
975986
includeRecentReports: true,
976987
includeMultipleParticipantReports: true,
977-
includePersonalDetails: true,
988+
includePersonalDetails: false,
989+
showChatPreviewLine: true,
990+
forcePolicyNamePreview: true,
991+
includeThreads: true,
992+
includeMoneyRequests: true,
993+
includeTasks: true,
978994
excludeLogins,
979995
includeOwnedWorkspaceChats,
996+
excludeUnknownUsers,
980997
});
981998
}
982999

src/libs/ReportUtils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ function isConciergeChatReport(report) {
460460
return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(report);
461461
}
462462

463+
/**
464+
* Returns true if this report has only one participant and it's an Expensify account.
465+
* @param {Object} report
466+
* @returns {Boolean}
467+
*/
468+
function isExpensifyOnlyParticipantInReport(report) {
469+
const reportParticipants = _.without(lodashGet(report, 'participantAccountIDs', []), currentUserAccountID);
470+
return lodashGet(report, 'participantAccountIDs', []).length === 1 && _.some(reportParticipants, (accountID) => _.contains(CONST.EXPENSIFY_ACCOUNT_IDS, accountID));
471+
}
472+
463473
/**
464474
* Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of accountIDs
465475
* by cross-referencing the accountIDs with personalDetails.
@@ -2862,6 +2872,7 @@ export {
28622872
getPolicyName,
28632873
getPolicyType,
28642874
isArchivedRoom,
2875+
isExpensifyOnlyParticipantInReport,
28652876
isPolicyExpenseChatAdmin,
28662877
isPolicyAdmin,
28672878
isPublicRoom,

src/pages/home/report/ReportActionCompose.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,9 @@ class ReportActionCompose extends React.Component {
450450
* @param {Array} reportParticipants
451451
* @returns {Boolean}
452452
*/
453-
getTaskOption(reportParticipants) {
453+
getTaskOption() {
454454
// We only prevent the task option from showing if it's a DM and the other user is an Expensify default email
455-
if (
456-
!Permissions.canUseTasks(this.props.betas) ||
457-
(lodashGet(this.props.report, 'participantAccountIDs', []).length === 1 && _.some(reportParticipants, (accountID) => _.contains(CONST.EXPENSIFY_ACCOUNT_IDS, accountID)))
458-
) {
455+
if (!Permissions.canUseTasks(this.props.betas) || ReportUtils.isExpensifyOnlyParticipantInReport(this.props.report)) {
459456
return [];
460457
}
461458

@@ -1116,7 +1113,7 @@ class ReportActionCompose extends React.Component {
11161113
anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM}}
11171114
menuItems={[
11181115
...this.getMoneyRequestOptions(reportParticipants),
1119-
...this.getTaskOption(reportParticipants),
1116+
...this.getTaskOption(),
11201117
{
11211118
icon: Expensicons.Paperclip,
11221119
text: this.props.translate('reportActionCompose.addAttachment'),

src/pages/tasks/TaskShareDestinationSelectorModal.js

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,27 @@ function TaskShareDestinationSelectorModal(props) {
4545
const [searchValue, setSearchValue] = useState('');
4646
const [headerMessage, setHeaderMessage] = useState('');
4747
const [filteredRecentReports, setFilteredRecentReports] = useState([]);
48-
const [filteredPersonalDetails, setFilteredPersonalDetails] = useState([]);
49-
const [filteredUserToInvite, setFilteredUserToInvite] = useState(null);
5048

5149
const filteredReports = useMemo(() => {
5250
const reports = {};
5351
_.keys(props.reports).forEach((reportKey) => {
54-
if (!ReportUtils.isAllowedToComment(props.reports[reportKey])) {
52+
if (
53+
!ReportUtils.isAllowedToComment(props.reports[reportKey]) ||
54+
ReportUtils.isArchivedRoom(props.reports[reportKey]) ||
55+
ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey])
56+
) {
5557
return;
5658
}
5759
reports[reportKey] = props.reports[reportKey];
5860
});
5961
return reports;
6062
}, [props.reports]);
6163
const updateOptions = useCallback(() => {
62-
const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getShareDestinationOptions(
63-
filteredReports,
64-
props.personalDetails,
65-
props.betas,
66-
searchValue.trim(),
67-
[],
68-
CONST.EXPENSIFY_EMAILS,
69-
true,
70-
);
71-
72-
setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0, Boolean(userToInvite), searchValue));
73-
74-
setFilteredUserToInvite(userToInvite);
64+
const {recentReports} = OptionsListUtils.getShareDestinationOptions(filteredReports, props.personalDetails, props.betas, searchValue.trim(), [], CONST.EXPENSIFY_EMAILS, true);
65+
66+
setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length !== 0, false, searchValue));
67+
7568
setFilteredRecentReports(recentReports);
76-
setFilteredPersonalDetails(personalDetails);
7769
}, [props, searchValue, filteredReports]);
7870

7971
useEffect(() => {
@@ -101,23 +93,6 @@ function TaskShareDestinationSelectorModal(props) {
10193
indexOffset += filteredRecentReports?.length;
10294
}
10395

104-
if (filteredPersonalDetails?.length > 0) {
105-
sections.push({
106-
data: filteredPersonalDetails,
107-
shouldShow: true,
108-
indexOffset,
109-
});
110-
indexOffset += filteredRecentReports?.length;
111-
}
112-
113-
if (filteredUserToInvite) {
114-
sections.push({
115-
data: [filteredUserToInvite],
116-
shouldShow: true,
117-
indexOffset,
118-
});
119-
}
120-
12196
return sections;
12297
};
12398

tests/unit/OptionsListUtilsTest.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,8 @@ describe('OptionsListUtils', () => {
570570
// When we pass an empty search value
571571
let results = OptionsListUtils.getShareDestinationOptions(REPORTS, PERSONAL_DETAILS, [], '');
572572

573-
// Then we should expect 5 recent reports to show because we're grabbing DM chats and group chats
574-
// because we've limited the number of recent reports to 5
575-
expect(results.recentReports.length).toBe(5);
573+
// Then we should expect all the recent reports to show but exclude the archived rooms
574+
expect(results.recentReports.length).toBe(_.size(REPORTS) - 1);
576575

577576
// When we pass a search value that doesn't match the group chat name
578577
results = OptionsListUtils.getShareDestinationOptions(REPORTS, PERSONAL_DETAILS, [], 'mutants');
@@ -590,8 +589,8 @@ describe('OptionsListUtils', () => {
590589
results = OptionsListUtils.getShareDestinationOptions(REPORTS_WITH_WORKSPACE_ROOMS, PERSONAL_DETAILS, [], '');
591590

592591
// Then we should expect the DMS, the group chats and the workspace room to show
593-
// We should expect 5 recent reports to show because we've limited the number of recent reports to 5
594-
expect(results.recentReports.length).toBe(5);
592+
// We should expect all the recent reports to show, excluding the archived rooms
593+
expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_WORKSPACE_ROOMS) - 1);
595594

596595
// When we search for a workspace room
597596
results = OptionsListUtils.getShareDestinationOptions(REPORTS_WITH_WORKSPACE_ROOMS, PERSONAL_DETAILS, [], 'Avengers Room');

0 commit comments

Comments
 (0)