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

Fix multiple options getting selected on SearchPage, NewGroupPage #12906

Merged
merged 13 commits into from
Nov 22, 2022
13 changes: 9 additions & 4 deletions src/pages/NewChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ class NewChatPage extends Component {
*/
getSections(maxParticipantsReached) {
const sections = [];
let indexOffset = 0;

if (this.props.isGroupChat) {
sections.push({
title: undefined,
data: this.state.selectedOptions,
shouldShow: !_.isEmpty(this.state.selectedOptions),
indexOffset: 0,
indexOffset,
});
indexOffset += this.state.selectedOptions.length;

if (maxParticipantsReached) {
return sections;
Expand All @@ -107,22 +110,24 @@ class NewChatPage extends Component {
title: this.props.translate('common.recents'),
data: recentReportsWithoutSelected,
shouldShow: !_.isEmpty(recentReportsWithoutSelected),
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += recentReportsWithoutSelected.length;
jasperhuangg marked this conversation as resolved.
Show resolved Hide resolved

sections.push({
title: this.props.translate('common.contacts'),
data: personalDetailsWithoutSelected,
shouldShow: !_.isEmpty(personalDetailsWithoutSelected),
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += personalDetailsWithoutSelected.length;

if (hasUnselectedUserToInvite) {
sections.push(({
title: undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: 0,
indexOffset,
}));
}

Expand Down
10 changes: 7 additions & 3 deletions src/pages/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,32 @@ class SearchPage extends Component {
*/
getSections() {
const sections = [];
let indexOffset = 0;

if (this.state.recentReports.length > 0) {
sections.push(({
data: this.state.recentReports,
shouldShow: true,
indexOffset: 0,
indexOffset,
}));
indexOffset += this.state.recentReports.length;
}

if (this.state.personalDetails.length > 0) {
sections.push(({
data: this.state.personalDetails,
shouldShow: true,
indexOffset: this.state.recentReports.length,
indexOffset,
}));
indexOffset += this.state.recentReports.length;
jasperhuangg marked this conversation as resolved.
Show resolved Hide resolved
}

if (this.state.userToInvite) {
sections.push(({
undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: 0,
indexOffset,
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,30 @@ class IOUParticipantsRequest extends Component {
*/
getSections() {
const sections = [];
let indexOffset = 0;

sections.push({
title: this.props.translate('common.recents'),
data: this.state.recentReports,
shouldShow: !_.isEmpty(this.state.recentReports),
indexOffset: 0,
indexOffset,
});
indexOffset += this.state.recentReports.length;

sections.push({
title: this.props.translate('common.contacts'),
data: this.state.personalDetails,
shouldShow: !_.isEmpty(this.state.personalDetails),
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += this.state.personalDetails.length;

if (this.state.userToInvite && !OptionsListUtils.isCurrentUser(this.state.userToInvite)) {
sections.push({
undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
}

Expand Down
19 changes: 9 additions & 10 deletions src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ class IOUParticipantsSplit extends Component {
*/
getSections(maxParticipantsReached) {
const sections = [];
let indexOffset = 0;

sections.push({
title: undefined,
data: this.props.participants,
shouldShow: true,
indexOffset: 0,
indexOffset,
});
indexOffset += this.props.participants.length;

if (maxParticipantsReached) {
return sections;
Expand All @@ -102,28 +105,24 @@ class IOUParticipantsSplit extends Component {
title: this.props.translate('common.recents'),
data: this.state.recentReports,
shouldShow: !_.isEmpty(this.state.recentReports),

// takes the sum off the length of all data
// (this.state.selectedOptions) in previous sections
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += this.state.recentReports.length;

sections.push({
title: this.props.translate('common.contacts'),
data: this.state.personalDetails,
shouldShow: !_.isEmpty(this.state.personalDetails),

// takes the sum off the length of all data
// (this.state.selectedOptions, this.state.recentReports) in previous sections
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += this.state.personalDetails.length;

if (this.state.userToInvite && !OptionsListUtils.isCurrentUser(this.state.userToInvite)) {
sections.push(({
undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
}));
}

Expand Down
10 changes: 7 additions & 3 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ class WorkspaceInvitePage extends React.Component {
*/
getSections() {
const sections = [];
let indexOffset = 0;

sections.push({
title: undefined,
data: this.state.selectedOptions,
shouldShow: true,
indexOffset: 0,
indexOffset,
});
indexOffset += this.state.selectedOptions.length;

// Filtering out selected users from the search results
const filterText = _.reduce(this.state.selectedOptions, (str, {login}) => `${str} ${login}`, '');
Expand All @@ -148,15 +151,16 @@ class WorkspaceInvitePage extends React.Component {
title: this.props.translate('common.contacts'),
data: personalDetailsWithoutSelected,
shouldShow: !_.isEmpty(personalDetailsWithoutSelected),
indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0),
indexOffset,
});
indexOffset += personalDetailsWithoutSelected.length;

if (hasUnselectedUserToInvite) {
sections.push(({
title: undefined,
data: [this.state.userToInvite],
shouldShow: true,
indexOffset: 0,
indexOffset,
}));
}

Expand Down