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
ManageStudentsTable: save all functional #20954
Conversation
cd34b91
to
0fada6c
Compare
83328be
to
882d5a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few tiny little edits, but LGTM! Congrats on being so close to finishing the overhaul of this table!
apps/i18n/common/en_us.json
Outdated
"manageStudentsNotificationCannotAdd": "You could not add student to your section. Please try again or refresh the page.", | ||
"manageStudentsNotificationAddSuccess": "You added 1 student to your section.", | ||
"manageStudentsNotificationCannotAdd": "You could not add {numStudents} students to your section. Please try again or refresh the page.", | ||
"manageStudentsNotificationAddSuccess": "You added {numStudents} students to your section.", | ||
"manageStudentsNotificationSuccess": "Success!", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: Do we want this string to have "student(s)" for cases when numStudents is 1?
@@ -51,11 +51,16 @@ const blankNewStudentRow = { | |||
}; | |||
|
|||
// Initial state for the manageStudents redux store. | |||
|
|||
// addStatus should be an object with the follow keys | |||
// status - AddStatus enum descripting the result of the add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: "following keys" and "describing"?
} | ||
}, | ||
addStatus: AddStatus.SUCCESS, | ||
addStatus: {status: AddStatus.SUCCESS, numStudents: action.numStudents} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When should we have spaces in braces { like this } and when should we not {like this}? I see both in our codebase, and I don't know think the styleguide has a ruling. 🤷🏼♀️ just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently they are both okay: https://github.com/code-dot-org/code-dot-org/blob/staging/STYLEGUIDE.md#js-object-curly-spacing
@@ -338,7 +338,7 @@ describe('manageStudentsRedux', () => { | |||
assert.deepEqual(nextState.editingData[0], {...expectedBlankRow, loginType: 'picture'}); | |||
}); | |||
|
|||
it('addStudentSuccess updates studentData,removes editingData, and adds new blank row', () => { | |||
it('addStudentsSuccess updates studentData,removes editingData, and adds new blank row', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: space before "removes"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very elegant solution, changing addStudent
to addStudents
throughout and wrapping the single-student cases as needed. Looks like there are some test failures to deal with?
"manageStudentsNotificationCannotAdd": "You could not add student to your section. Please try again or refresh the page.", | ||
"manageStudentsNotificationAddSuccess": "You added 1 student to your section.", | ||
"manageStudentsNotificationCannotAdd": "You could not add {numStudents, plural, one {1 student} other {# students}} to your section. Please try again or refresh the page.", | ||
"manageStudentsNotificationAddSuccess": "You added {numStudents, plural, one {1 student} other {# students}} to your section.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}), dispatch => ({ | ||
saveAllStudents() { | ||
dispatch(saveAllStudents()); | ||
}, | ||
}))(ManageStudentsTable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good place for the propsFromDispatch shorthand:
export default connect(state => ({
loginType: state.manageStudents.loginType,
// Other propsFromState stuff...
}), {
// If you just pass an object of action creators as the second argument to connect,
// react-redux assumes they're all simple pass-throughs like this:
// saveAllStudents: (...args) => dispatch(saveAllStudents(...args)),
saveAllStudents,
})(ManageStudentsTable);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave this one as it. I find it confusing to understand what's going without the explicit call.
|
||
// addStatus should be an object with the following keys | ||
// status - AddStatus enum describing the result of the add | ||
// numStudents - number of students that were attempted to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why doesn't it have these keys in its initial state?
- This is a thing Immutable.js is really good at 😁 but not sure it's worth pivoting right now.
dispatch(startSavingStudent(studentId)); | ||
addStudentOnServer(state.editingData[studentId], state.sectionId, (error, data) => { | ||
|
||
// Currently, every update is an individual call to the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to change this later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for V2. I think it could be useful to think about changing the API once we create the "edit all" feature.
const currentlyEditedData = convertStudentDataToArray(state.editingData); | ||
let studentsToSave = currentlyEditedData.filter(student => student.rowType === RowType.STUDENT); | ||
for (let i = 0; i<studentsToSave.length; i++) { | ||
dispatch(saveStudent(studentsToSave[i].id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: My personal preference for straightforward iterations like this is
studentsToSave.forEach(student => dispatch(saveStudent(student.id)));
// Adding students can be saved together. | ||
const arrayOfEditedData = convertStudentDataToArray(state.editingData); | ||
const newStudentsToAdd = arrayOfEditedData.filter(student => student.rowType === RowType.NEW_STUDENT).map( | ||
student => student.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
age: updatedStudentsInfo[i].age, | ||
gender: updatedStudentsInfo[i].gender, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a map
operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops missed this one - but will follow up.
Behind
manageStudents
experiment and does not currently effect current user changes."Save all" button now works: adds `RowType.NEW_STUDENT` and saves `RowType.STUDENT` that are currently being edited. Does not save the add row.
Technically: expand addStudent and saveStudent to handle a set of students, and add a save all function.
Redux tests updated appropriately