Skip to content

Commit

Permalink
Merge pull request #21049 from code-dot-org/student-ordering
Browse files Browse the repository at this point in the history
Manage students table: Show rows in reverse added order
  • Loading branch information
caleybrock committed Mar 7, 2018
2 parents 1ee0527 + 9f1cd34 commit 3565523
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions apps/src/templates/manageStudents/manageStudentsRedux.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const saveAllStudents = () => {
const state = getState().manageStudents;

// Currently, every update is an individual call to the server.
const currentlyEditedData = convertStudentDataToArray(state.editingData);
const currentlyEditedData = Object.values(state.editingData);
let studentsToSave = currentlyEditedData.filter(student => student.rowType === RowType.STUDENT);
studentsToSave.forEach((student) => {
if (student.name !== '') {
Expand All @@ -122,7 +122,7 @@ export const saveAllStudents = () => {
});

// Adding students can be saved together.
const arrayOfEditedData = convertStudentDataToArray(state.editingData);
const arrayOfEditedData = Object.values(state.editingData);
const newStudentsToAdd = arrayOfEditedData
.filter(student => student.rowType === RowType.NEW_STUDENT)
.map(student => student.id);
Expand All @@ -144,7 +144,7 @@ export const addStudents = (studentIds) => {
dispatch(startSavingStudent(studentIds[i]));
}

const arrayOfEditedData = convertStudentDataToArray(state.editingData);
const arrayOfEditedData = Object.values(state.editingData);
const filteredData = arrayOfEditedData.filter(student => studentIds.includes(student.id));
addStudentOnServer(filteredData,
state.sectionId, (error, data) => {
Expand Down Expand Up @@ -415,7 +415,7 @@ export const convertStudentServerData = (studentData, loginType, sectionId) => {
// component to display
// TODO(caleybrock): memoize this - sections could be a few thousand students
export const convertStudentDataToArray = (studentData) => {
return Object.values(studentData);
return Object.values(studentData).reverse();
};

// Make a post request to edit a student.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ describe('manageStudentsRedux', () => {
});

describe('convertStudentDataToArray', () => {
it('converts studentData to an array of student objects', () => {
it('converts studentData to an array of student objects in reverse order', () => {
const studentDataArray = convertStudentDataToArray(studentEmailData);
assert.equal(studentDataArray.length, 3);
assert.equal(studentDataArray[0], studentEmailData[1]);
assert.equal(studentDataArray[0], studentEmailData[3]);
assert.equal(studentDataArray[1], studentEmailData[2]);
assert.equal(studentDataArray[2], studentEmailData[3]);
assert.equal(studentDataArray[2], studentEmailData[1]);
});
});

Expand Down

0 comments on commit 3565523

Please sign in to comment.