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

Hide automated accounts from Recent sections of Split Money/Request Money #4648

Merged
merged 10 commits into from
Aug 18, 2021
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
1 change: 1 addition & 0 deletions src/CONST.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
selectedOptions = [],
maxRecentReportsToShow = 0,
excludeConcierge = false,
excludeChronos = false,
excludeReceipts = false,
excludeDefaultRooms = false,
includeMultipleParticipantReports = false,
includePersonalDetails = false,
Expand Down Expand Up @@ -384,6 +386,14 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
loginOptionsToExclude.push({login: CONST.EMAIL.CONCIERGE});
}

if (excludeChronos) {
loginOptionsToExclude.push({login: CONST.EMAIL.CHRONOS});
}

if (excludeReceipts) {
loginOptionsToExclude.push({login: CONST.EMAIL.RECEIPTS});
}

if (includeRecentReports) {
for (let i = 0; i < allReportOptions.length; i++) {
// Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value
Expand Down Expand Up @@ -468,6 +478,7 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
&& personalDetailsOptions.length === 0
&& _.every(selectedOptions, option => option.login !== searchValue)
&& ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue))
&& (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue))
&& (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas))
) {
// If the phone number doesn't have an international code then let's prefix it with the
Expand Down Expand Up @@ -527,15 +538,22 @@ function getSearchOptions(
* @param {Object} reports
* @param {Object} personalDetails
* @param {String} searchValue
* @param {Boolean} excludeConcierge
* @param {Object} excludedOptions
* @param {Boolean} excludedOptions.excludeConcierge
* @param {Boolean} excludedOptions.excludeChronos
* @param {Boolean} excludedOptions.excludeReceipts
* @param {Array<String>} betas
* @returns {Object}
*/
function getNewChatOptions(
reports,
personalDetails,
searchValue = '',
excludeConcierge,
{
excludeConcierge = false,
excludeChronos = false,
excludeReceipts = true,
} = {},
betas,
) {
return getOptions(reports, personalDetails, {}, 0, {
Expand All @@ -546,6 +564,8 @@ function getNewChatOptions(
includeRecentReports: true,
maxRecentReportsToShow: 5,
excludeConcierge,
excludeChronos,
excludeReceipts,
});
}

Expand Down Expand Up @@ -588,7 +608,10 @@ function getIOUConfirmationOptionsFromParticipants(
* @param {Object} personalDetails
* @param {String} searchValue
* @param {Array} selectedOptions
* @param {Boolean} excludeConcierge
* @param {Object} excludedOptions
* @param {Boolean} excludedOptions.excludeConcierge
* @param {Boolean} excludedOptions.excludeChronos
* @param {Boolean} excludedOptions.excludeReceipts
* @param {Array<String>} betas
* @returns {Object}
*/
Expand All @@ -597,7 +620,11 @@ function getNewGroupOptions(
personalDetails,
searchValue = '',
selectedOptions = [],
excludeConcierge,
{
excludeConcierge = false,
excludeChronos = false,
excludeReceipts = true,
} = {},
betas,
) {
return getOptions(reports, personalDetails, {}, 0, {
Expand All @@ -610,6 +637,8 @@ function getNewGroupOptions(
includeMultipleParticipantReports: false,
maxRecentReportsToShow: 5,
excludeConcierge,
excludeChronos,
excludeReceipts,
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/pages/NewChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class NewChatPage extends Component {
props.reports,
props.personalDetails,
'',
false,
{
excludeConcierge: false,
excludeChronos: false,
excludeReceipts: true,
},
props.betas,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class IOUParticipantsRequest extends Component {
props.reports,
props.personalDetails,
'',
true,
{
excludeConcierge: true,
excludeChronos: true,
excludeReceipts: true,
},
props.betas,
);

Expand Down Expand Up @@ -128,7 +132,11 @@ class IOUParticipantsRequest extends Component {
this.props.reports,
this.props.personalDetails,
searchValue,
true,
{
excludeConcierge: true,
excludeChronos: true,
excludeReceipts: true,
},
this.props.betas,
);
this.setState({
Expand Down
18 changes: 15 additions & 3 deletions src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class IOUParticipantsSplit extends Component {
props.personalDetails,
'',
props.participants,
true,
{
excludeConcierge: true,
excludeChronos: true,
excludeReceipts: true,
},
props.betas,
);

Expand Down Expand Up @@ -183,7 +187,11 @@ class IOUParticipantsSplit extends Component {
this.props.personalDetails,
isOptionInList ? prevState.searchValue : '',
newSelectedOptions,
true,
{
excludeConcierge: true,
excludeChronos: true,
excludeReceipts: true,
},
this.props.betas,
);
return {
Expand Down Expand Up @@ -220,7 +228,11 @@ class IOUParticipantsSplit extends Component {
this.props.personalDetails,
searchValue,
[],
true,
{
excludeConcierge: true,
excludeChronos: true,
excludeReceipts: true,
},
this.props.betas,
);
this.setState({
Expand Down
129 changes: 127 additions & 2 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ describe('OptionsListUtils', () => {
},
};

const REPORTS_WITH_CHRONOS = {
...REPORTS,
11: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 1,
isPinned: false,
reportID: 10,
participants: ['chronos@expensify.com'],
reportName: 'Chronos',
unreadActionCount: 1,
},
};

const REPORTS_WITH_RECEIPTS = {
...REPORTS,
12: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 1,
isPinned: false,
reportID: 10,
participants: ['receipts@expensify.com'],
reportName: 'Receipts',
unreadActionCount: 1,
},
};

const PERSONAL_DETAILS_WITH_CONCIERGE = {
...PERSONAL_DETAILS,

Expand All @@ -171,6 +197,24 @@ describe('OptionsListUtils', () => {
},
};

const PERSONAL_DETAILS_WITH_CHRONOS = {
...PERSONAL_DETAILS,

'chronos@expensify.com': {
displayName: 'Chronos',
login: 'chronos@expensify.com',
},
};

const PERSONAL_DETAILS_WITH_RECEIPTS = {
...PERSONAL_DETAILS,

'receipts@expensify.com': {
displayName: 'Receipts',
login: 'receipts@expensify.com',
},
};

// Set the currently logged in user, report data, and personal details
beforeAll(() => {
Onyx.init({
Expand Down Expand Up @@ -273,7 +317,9 @@ describe('OptionsListUtils', () => {
);

// Test by excluding Concierge from the results
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, '', true);
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, '', {excludeConcierge: true},
);

// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS);
Expand All @@ -282,6 +328,32 @@ describe('OptionsListUtils', () => {
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);

// Test by excluding Chronos from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, '', {excludeChronos: true},
);

// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);

// Test by excluding Receipts from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, '', {excludeReceipts: true},
);

// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});

it('getNewGroupOptions()', () => {
Expand Down Expand Up @@ -402,7 +474,9 @@ describe('OptionsListUtils', () => {
PERSONAL_DETAILS_WITH_CONCIERGE,
'',
[],
true,
{
excludeConcierge: true,
},
);

// We should expect all the personalDetails to show (minus the 5 that are already showing,
Expand All @@ -418,6 +492,57 @@ describe('OptionsListUtils', () => {
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);


// Test by excluding Chronos from the results
results = OptionsListUtils.getNewGroupOptions(
REPORTS_WITH_CHRONOS,
PERSONAL_DETAILS_WITH_CHRONOS,
'',
[],
{
excludeChronos: true,
},
);

// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);

// Test by excluding Receipts from the results
results = OptionsListUtils.getNewGroupOptions(
REPORTS_WITH_RECEIPTS,
PERSONAL_DETAILS_WITH_RECEIPTS,
'',
[],
{
excludeReceipts: true,
},
);

// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});

it('getSidebarOptions() with default priority mode', () => {
Expand Down