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

ManageStudentsTable: save all functional #20954

Merged
merged 8 commits into from Mar 2, 2018
Merged

ManageStudentsTable: save all functional #20954

merged 8 commits into from Mar 2, 2018

Conversation

caleybrock
Copy link
Contributor

@caleybrock caleybrock commented Mar 1, 2018

Behind manageStudents experiment and does not currently effect current user changes.

screen shot 2018-03-01 at 3 23 57 pm

"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

Copy link
Contributor

@Erin007 Erin007 left a 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!

"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!",
Copy link
Contributor

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
Copy link
Contributor

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}
};
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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', () => {
Copy link
Contributor

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"

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.

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.",
Copy link
Contributor

Choose a reason for hiding this comment

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

image

}), dispatch => ({
saveAllStudents() {
dispatch(saveAllStudents());
},
}))(ManageStudentsTable);
Copy link
Contributor

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);

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Why doesn't it have these keys in its initial state?
  2. 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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));
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Style nit: This is a long line, I'd break it across your chained method calls.

const newStudentsToAdd = arrayOfEditedData
  .filter(student => student.rowType === RowType.NEW_STUDENT)
  .map(student => student.id);

...also
combo_super_combo_finish

age: updatedStudentsInfo[i].age,
gender: updatedStudentsInfo[i].gender,
};
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@caleybrock caleybrock merged commit a3bac41 into staging Mar 2, 2018
@caleybrock caleybrock deleted the save-all-rows branch March 2, 2018 23:41
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

3 participants