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 2 edit workshop bugs discovered in React class refactor #18114

Merged
merged 2 commits into from Oct 4, 2017

Conversation

aoby
Copy link
Contributor

@aoby aoby commented Oct 4, 2017

I discovered 2 long-standing bugs :( while testing React refactors here.

1: Multiple sessions couldn't be deleted at once

Bug:

sessions-removal-bug

Fix:

sessions-removal-fixed

2. the last available facilitator couldn't be added

Bug:

last-facilitator-bug

Fix:

last-facilitator-fixed

It also still works correctly when none are available:
image

Or when no course is selected:
image

… sessions couldn't be deleted at once, and the last available facilitator couldn't be added
filteredAvailableFacilitators = this.props.availableFacilitators.filter(availableFacilitator => {
return !this.props.facilitators.find(f => f.id === availableFacilitator.id);
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this out of the map on line 71 is just an optimization, not related to the bugs, but it seems like a good idea. There's really no need to recompute this available list for each row.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good extraction. One syntax nit - could express the outer arrow function here with an expression too.

filteredAvailableFacilitators = this.props.availableFacilitators.filter(availableFacilitator =>
  !this.props.facilitators.find(f => f.id === availableFacilitator.id);
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, good call 👍 Will do

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fixes!

filteredAvailableFacilitators = this.props.availableFacilitators.filter(availableFacilitator => {
return !this.props.facilitators.find(f => f.id === availableFacilitator.id);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good extraction. One syntax nit - could express the outer arrow function here with an expression too.

filteredAvailableFacilitators = this.props.availableFacilitators.filter(availableFacilitator =>
  !this.props.facilitators.find(f => f.id === availableFacilitator.id);
);

if (i === facilitators.length - 1 && facilitators.length < MAX_FACILITATORS &&
this.props.facilitators[i].id > 0 && filteredAvailableFacilitators.length > 1 ) {
this.props.facilitators[i].id > 0 && filteredAvailableFacilitators.length >= 1 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be another bug here - if the placeholder id is -1, shouldn't the third condition here be this.props.facilitators[i] >= 0 not > 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails ids start at 1, so in this case either way will work. I'd be happy to change it to >= 0 if you think that's more readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it's due to the underlying MySql auto increment, but anyway this is the behavior - our ids always start with 1.

@aoby aoby merged commit 6cae333 into staging Oct 4, 2017
@aoby aoby deleted the pd-workshop-bug-fixes branch October 4, 2017 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants