Convert "Rename Group" modal to React component#7673
Convert "Rename Group" modal to React component#7673david-yz-liu merged 17 commits intoMarkUsProject:masterfrom
Conversation
Pull Request Test Coverage Report for Build 18077046745Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
| renameGroup = (grouping_id, group_name) => { | ||
| this.setState({ | ||
| isRenameGroupDialogOpen: true, | ||
| groupingId: grouping_id, |
There was a problem hiding this comment.
Adding a groupingId state is good, but a better name is renameGroupingId. For any new state you add, you should initialize it in the constructor.
| this.setState({ | ||
| isRenameGroupDialogOpen: true, | ||
| groupingId: grouping_id, | ||
| groupName: group_name, |
There was a problem hiding this comment.
Similarly, groupName is better named renameGroupName. This state can be passed into the modal component to initialize the starting value of the group name for the input. This is a better initial value than the empty string. (I realize that this is actually an update to the original behaviour, but it's a fairly small one and coincides nicely with the refactoring changes you're making.)
| url: Routes.rename_group_course_group_path(this.props.course_id, this.state.groupingId), | ||
| data: { | ||
| new_groupname: newGroupName, | ||
| assignment_id: this.props.assignment_id, |
There was a problem hiding this comment.
The assignment_id parameter should be necessary, just the new_groupname param
david-yz-liu
left a comment
There was a problem hiding this comment.
@freyazjiner in addition to the inline comments, please add additional tests so that you have 100% code coverage on the new module. Remember that you can run tests with coverage locally with the --coverage flag.
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (this.props.isOpen && !prevProps.isOpen && this.props.currentGroupName) { |
There was a problem hiding this comment.
For props that correspond to input field values, "initial" is a better word than "current". So initialGroupName rather than currentGroupName.
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| groupName: "", |
There was a problem hiding this comment.
Also, it's good practice to also use the prop in the constructor to set the initial state value (even if the prop value is initially the empty string; that could change in the future).
| Routes.rename_group_course_group_path(this.props.course_id, grouping_id) | ||
| ); | ||
| modal_rename.open(); | ||
| renameGroup = (grouping_id, group_name) => { |
There was a problem hiding this comment.
I noticed when testing that the modal did not exhibit the correct behaviour: what I was looking for in my previous comment is for the input to autofill based on the group selected. Instead, the input still appears blank.
The problem is not with the new prop (initialGroupName), but rather how this function is being used. You modified the function signature to take an additional parameter group_name, which is good, but have not actually modified how this function is called. In general, make sure to be careful when changing function signatures: you need to check both the function definition and everywhere the function is called.
david-yz-liu
left a comment
There was a problem hiding this comment.
Nice work, @freyazjiner!
Proposed Changes
(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)
This PR modernizes the group renaming interface by replacing the old modal with a React component implementation.
Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)