save or reorder columns with api only when changed

fixes GRADE-638

QA Notes:

To create a custom column, open the Rails console:

   course = Course.find(<id of course>)
   course.custom_gradebook_columns.create(title: 'Example')

test plan:
 A. Select or create a Course
 B. Visit New Gradebook
 C. Open the Network tab in the browser dev tools

 D. With No Custom Columns
    1. Ensure there are no visible Custom Columns
    2. Move the Total Grade column to the Front (frozen section)
    3. Click-drag to reorder the Student and Total Grade columns
    4. Verify no network request was made to save column order
    5. Verify no network request was made to reorder columns

 E. With One Custom Column
    1. Create or Show the Notes column
    2. Click-drag to reorder any frozen columns
    4. Verify no network request was made to save column order
    5. Verify no network request was made to reorder columns

 F. With Multiple Custom Columns
    1. Create one additional custom column
    2. Refresh New Gradebook
    3. Click-drag to reorder the Student and Total Grade columns
       * They can be between custom columns
    4. Verify no network request was made to reorder columns
    5. Click-drag to reorder custom columns
    6. Verify a network request was made to reorder columns

 G. SlickGrid is Ignored
    * SlickGrid Drag & Drop triggers events even when column
      order is unchanged. No additional action should be taken in
      that event, so SlickGrid must be ignored.

    1. Click-drag any frozen column to the right, over the
       scrollable columns, then release the mouse
    2. Verify no network request was made to save column order
    3. Verify no network request was made to reorder columns

    4. Click-drag any frozen column, but release the mouse
       without actually changing its position
    5. Verify no network request was made to save column order
    6. Verify no network request was made to reorder columns

    7. Click-drag any scrollable column to the left, over the
       frozen columns, then release the mouse
    8. Verify no network request was made to save column order
    9. Verify no network request was made to reorder columns

   10. Click-drag any scrollable column, but release the mouse
       without actually changing its position
   11. Verify no network request was made to save column order
   12. Verify no network request was made to reorder columns

Change-Id: Idf9630f1e86f869159d67e9f2c835b6f2fce2dc8
Reviewed-on: https://gerrit.instructure.com/132010
Tested-by: Jenkins
Reviewed-by: Derek Bender <djbender@instructure.com>
Reviewed-by: Spencer Olson <solson@instructure.com>
QA-Review: Indira Pai <ipai@instructure.com>
Product-Review: Matt Goodwin <mattg@instructure.com>
This commit is contained in:
Jeremy Neander 2017-11-06 18:46:15 -06:00
parent a6e007a356
commit f63801368c
4 changed files with 45 additions and 14 deletions

View File

@ -342,11 +342,15 @@ define [
@gridData.columns.scrollable = columns.scrollable.map((column) -> column.id)
if !_.isEqual(currentFrozenIds, updatedFrozenIds)
customColumnIds = (column.customColumnId for column in columns.frozen when column.type == 'custom_column')
@reorderCustomColumns(customColumnIds)
.then =>
colsById = _(@gradebookContent.customColumns).indexBy (c) -> c.id
@gradebookContent.customColumns = _(customColumnIds).map (id) -> colsById[id]
currentFrozenColumns = currentFrozenIds.map((columnId) => @gridData.columns.definitions[columnId])
currentCustomColumnIds = (column.customColumnId for column in currentFrozenColumns when column.type == 'custom_column')
updatedCustomColumnIds = (column.customColumnId for column in columns.frozen when column.type == 'custom_column')
if !_.isEqual(currentCustomColumnIds, updatedCustomColumnIds)
@reorderCustomColumns(updatedCustomColumnIds)
.then =>
colsById = _(@gradebookContent.customColumns).indexBy (c) -> c.id
@gradebookContent.customColumns = _(updatedCustomColumnIds).map (id) -> colsById[id]
else
@saveCustomColumnOrder()

View File

@ -53,7 +53,14 @@ export default class Columns {
grid.onColumnsReordered.subscribe((sourceEvent, _object) => {
const event = sourceEvent.originalEvent || sourceEvent;
events.onColumnsReordered.trigger(event, gridSupport.columns.getColumns());
const columns = gridSupport.columns.getColumns();
const orderChanged = (
columns.frozen.some((column, index) => column.id !== gridData.columns.frozen[index]) ||
columns.scrollable.some((column, index) => column.id !== gridData.columns.scrollable[index])
);
if (orderChanged) {
events.onColumnsReordered.trigger(event, columns);
}
});
gridSupport.events.onColumnsResized.subscribe((_event, columns) => {

View File

@ -4303,20 +4303,23 @@ QUnit.module('Gradebook Grid Events', function (suiteHooks) {
hooks.beforeEach(() => {
gradebook = createGradebook();
allColumns = [
{ id: 'student' },
{ id: 'custom_col_2401' },
{ id: 'custom_col_2402' },
{ id: 'assignment_2301' },
{ id: 'assignment_2302' },
{ id: 'assignment_group_2201' },
{ id: 'assignment_group_2202' },
{ id: 'total_grade' }
{ id: 'student', type: 'student' },
{ id: 'custom_col_2401', type: 'custom_column', customColumnId: '2401' },
{ id: 'custom_col_2402', type: 'custom_column', customColumnId: '2402' },
{ id: 'assignment_2301', type: 'assignment' },
{ id: 'assignment_2302', type: 'assignment' },
{ id: 'assignment_group_2201', type: 'assignment_group' },
{ id: 'assignment_group_2202', type: 'assignment_group' },
{ id: 'total_grade', type: 'total_grade' }
];
columns = {
frozen: allColumns.slice(0, 3),
scrollable: allColumns.slice(3)
};
gradebook.gridData.columns.definitions = allColumns.reduce((map, column) => (
{ ...map, [column.id]: column }
), {});
gradebook.gridData.columns.frozen = columns.frozen.map(column => column.id);
gradebook.gridData.columns.scrollable = columns.scrollable.map(column => column.id);
@ -4333,6 +4336,13 @@ QUnit.module('Gradebook Grid Events', function (suiteHooks) {
strictEqual(gradebook.reorderCustomColumns.callCount, 1);
});
test('does not reorder custom columns when custom column order was not affected', () => {
columns.frozen = [allColumns[1], allColumns[0], allColumns[2]];
columns.scrollable = allColumns.slice(3, 8);
gradebook.gradebookGrid.events.onColumnsReordered.trigger(null, columns);
strictEqual(gradebook.reorderCustomColumns.callCount, 0);
});
test('stores custom column order when scrollable columns were reordered', () => {
columns.frozen = allColumns.slice(0, 3);
columns.scrollable = [allColumns[7], ...allColumns.slice(3, 7)];

View File

@ -252,6 +252,16 @@ QUnit.module('Gradebook Grid Columns', function (suiteHooks) {
];
deepEqual(reorderEventData.scrollable.map(column => column.id), expectedOrder);
});
test('does not trigger the "onColumnsReordered" event when column order did not change', function () {
const spy = sinon.spy();
gradebook.gradebookGrid.events.onColumnsReordered.subscribe(spy);
gridSpecHelper.updateColumnOrder([
'student', 'custom_col_2401', 'custom_col_2402', 'assignment_2301', 'assignment_2302',
'assignment_group_2201', 'assignment_group_2202', 'total_grade'
]);
strictEqual(spy.callCount, 0);
});
});
QUnit.module('when rearranging scrollable columns', function (hooks) {