Resolve gradebook settings discrepancy

Uses strings for Gradebook settings booleans

Test plan:
    - Repeat the following with enhanced_gradebook_filters on and off
    - Change the following settings in Gradebook
    - show_concluded_enrollments
    - show_inactive_enrollments
    - show_unpublished_assignments
    - show_separate_first_last_names
    - view_ungraded_as_zero
    - These should successfully save and be reflected on reload

flag=enhanced_gradebook_filters

Closes EVAL-2145

Change-Id: I4bdf6be890b914a8ed6fd436114dcefa689fdad9
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/282208
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Product-Review: Jody Sailor
Reviewed-by: Spencer Olson <solson@instructure.com>
Reviewed-by: Dustin Cowles <dustin.cowles@instructure.com>
This commit is contained in:
Aaron Shafovaloff 2022-01-06 15:25:11 -06:00
parent 1e24613571
commit 1201c9a860
9 changed files with 137 additions and 142 deletions

View File

@ -2819,7 +2819,7 @@ QUnit.module('Gradebook#updateCurrentSection', {
setSelectedSection: sinon.stub()
}
sandbox.stub(this.gradebook.dataLoader, 'reloadStudentDataForSectionFilterChange')
sinon.spy(this.gradebook, 'saveSettings')
sinon.stub(this.gradebook, 'saveSettings').callsFake(() => Promise.resolve())
sandbox.stub(this.gradebook, 'updateSectionFilterVisibility')
},
@ -2844,8 +2844,8 @@ test('includes the selected section when updating the post grades store', functi
strictEqual(sectionId, '2001')
})
test('re-renders the section filter', function () {
this.gradebook.updateCurrentSection('2001')
test('re-renders the section filter', async function () {
await this.gradebook.updateCurrentSection('2001')
strictEqual(this.gradebook.updateSectionFilterVisibility.callCount, 1)
})
@ -2885,8 +2885,8 @@ test('has no effect when the section has not changed', function () {
)
})
test('reloads student data after saving settings', function () {
this.gradebook.updateCurrentSection('2001')
test('reloads student data after saving settings', async function () {
await this.gradebook.updateCurrentSection('2001')
strictEqual(this.gradebook.dataLoader.reloadStudentDataForSectionFilterChange.callCount, 1)
})
@ -4531,7 +4531,9 @@ QUnit.module('Gradebook Assignment Student Visibility', moduleHooks => {
let saveSettingsStub
hooks.beforeEach(() => {
saveSettingsStub = sinon.stub(gradebook, 'saveSettings')
saveSettingsStub = sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
})
hooks.afterEach(() => {
@ -4938,9 +4940,7 @@ QUnit.module('Gradebook#toggleEnrollmentFilter', {
}
}
sandbox.stub(this.gradebook.dataLoader, 'reloadStudentDataForEnrollmentFilterChange')
sandbox.stub(this.gradebook, 'saveSettings').callsFake((_data, callback) => {
callback()
})
sandbox.stub(this.gradebook, 'saveSettings').callsFake(() => Promise.resolve())
}
})
@ -4958,20 +4958,20 @@ test('saves settings', function () {
strictEqual(this.gradebook.saveSettings.callCount, 1)
})
test('updates the student column header', function () {
this.gradebook.toggleEnrollmentFilter('inactive')
test('updates the student column header', async function () {
await this.gradebook.toggleEnrollmentFilter('inactive')
strictEqual(this.gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 1)
})
test('includes the "student" column id when updating column headers', function () {
this.gradebook.toggleEnrollmentFilter('inactive')
test('includes the "student" column id when updating column headers', async function () {
await this.gradebook.toggleEnrollmentFilter('inactive')
const [columnIds] =
this.gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.lastCall.args
deepEqual(columnIds, ['student'])
})
test('reloads student data after saving settings', function () {
this.gradebook.toggleEnrollmentFilter('inactive')
test('reloads student data after saving settings', async function () {
await this.gradebook.toggleEnrollmentFilter('inactive')
strictEqual(this.gradebook.dataLoader.reloadStudentDataForEnrollmentFilterChange.callCount, 1)
})
@ -5070,9 +5070,7 @@ QUnit.module('Gradebook "Enter Grades as" Setting', suiteHooks => {
QUnit.module('#updateEnterGradesAsSetting', hooks => {
hooks.beforeEach(() => {
sinon.stub(gradebook, 'saveSettings').callsFake((_data, callback) => {
callback()
})
sinon.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
sinon.stub(gradebook.gradebookGrid, 'invalidate')
sinon.stub(gradebook.gradebookGrid.gridSupport.columns, 'updateColumnHeaders')
})
@ -5091,36 +5089,34 @@ QUnit.module('Gradebook "Enter Grades as" Setting', suiteHooks => {
strictEqual(gradebook.saveSettings.callCount, 1)
})
test('saves gradebooks settings after updating the "enter grades as" setting', () => {
gradebook.saveSettings.callsFake(() => {
equal(gradebook.getEnterGradesAsSetting('2301'), 'percent')
})
gradebook.updateEnterGradesAsSetting('2301', 'percent')
test('saves gradebooks settings after updating the "enter grades as" setting', async () => {
await gradebook.updateEnterGradesAsSetting('2301', 'percent')
equal(gradebook.getEnterGradesAsSetting('2301'), 'percent')
})
test('updates the column header for the related assignment column', () => {
gradebook.updateEnterGradesAsSetting('2301', 'percent')
test('updates the column header for the related assignment column', async () => {
await gradebook.updateEnterGradesAsSetting('2301', 'percent')
strictEqual(gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 1)
})
test('updates the column header with the assignment column id', () => {
gradebook.updateEnterGradesAsSetting('2301', 'percent')
test('updates the column header with the assignment column id', async () => {
await gradebook.updateEnterGradesAsSetting('2301', 'percent')
const [columnIds] =
gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.lastCall.args
deepEqual(columnIds, ['assignment_2301'])
})
test('updates the column header after settings have been saved', () => {
gradebook.saveSettings.callsFake((_data, callback) => {
strictEqual(gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 0)
callback()
strictEqual(gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 1)
})
test('updates the column header after settings have been saved', async () => {
strictEqual(gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 0)
gradebook.updateEnterGradesAsSetting('2301', 'percent')
await gradebook.saveSettings.callsFake(() => {
return Promise.resolve()
})
strictEqual(gradebook.gradebookGrid.gridSupport.columns.updateColumnHeaders.callCount, 1)
})
test('invalidates the grid', () => {
gradebook.updateEnterGradesAsSetting('2301', 'percent')
test('invalidates the grid', async () => {
await gradebook.updateEnterGradesAsSetting('2301', 'percent')
strictEqual(gradebook.gradebookGrid.invalidate.callCount, 1)
})
@ -5411,7 +5407,9 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
const gradebook = createGradebook()
gradebook.gridDisplaySettings.showUnpublishedAssignments = false
sandbox.stub(gradebook, 'updateColumnsAndRenderViewOptionsMenu')
sandbox.stub(gradebook, 'saveSettings')
sandbox
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
gradebook.toggleUnpublishedAssignments()
strictEqual(gradebook.gridDisplaySettings.showUnpublishedAssignments, true)
@ -5421,7 +5419,7 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
const gradebook = createGradebook()
gradebook.gridDisplaySettings.showUnpublishedAssignments = true
sandbox.stub(gradebook, 'updateColumnsAndRenderViewOptionsMenu')
sandbox.stub(gradebook, 'saveSettings')
sandbox.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
gradebook.toggleUnpublishedAssignments()
strictEqual(gradebook.gridDisplaySettings.showUnpublishedAssignments, false)
@ -5435,7 +5433,9 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
.callsFake(() => {
strictEqual(gradebook.gridDisplaySettings.showUnpublishedAssignments, false)
})
sandbox.stub(gradebook, 'saveSettings')
sandbox
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
gradebook.toggleUnpublishedAssignments()
strictEqual(stubFn.callCount, 1)
@ -5447,7 +5447,9 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
gradebook,
'updateColumnsAndRenderViewOptionsMenu'
)
const saveSettingsStub = sandbox.stub(gradebook, 'saveSettings')
const saveSettingsStub = sandbox
.stub(gradebook, 'saveSettings')
.callsFake(() => Promise.resolve())
gradebook.toggleUnpublishedAssignments()
sinon.assert.callOrder(updateColumnsAndRenderViewOptionsMenuStub, saveSettingsStub)
@ -5457,7 +5459,9 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
const settings = {show_unpublished_assignments: 'true'}
const gradebook = createGradebook({settings})
sandbox.stub(gradebook, 'updateColumnsAndRenderViewOptionsMenu')
const saveSettingsStub = sandbox.stub(gradebook, 'saveSettings')
const saveSettingsStub = sandbox
.stub(gradebook, 'saveSettings')
.callsFake(() => Promise.resolve())
gradebook.toggleUnpublishedAssignments()
const [{showUnpublishedAssignments}] = saveSettingsStub.firstCall.args
@ -5483,7 +5487,7 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
server.restore()
})
test('calls saveSettings and rolls back on failure', () => {
test('calls saveSettings and rolls back on failure', async () => {
const server = sinon.fakeServer.create({respondImmediately: true})
const options = {settings_update_url: '/course/1/gradebook_settings'}
server.respondWith('POST', options.settings_update_url, [
@ -5501,7 +5505,7 @@ QUnit.module('Gradebook#toggleUnpublishedAssignments', () => {
stubFn.onSecondCall().callsFake(() => {
strictEqual(gradebook.gridDisplaySettings.showUnpublishedAssignments, true)
})
gradebook.toggleUnpublishedAssignments()
await gradebook.toggleUnpublishedAssignments()
strictEqual(stubFn.callCount, 2)
server.restore()
})
@ -6047,7 +6051,9 @@ QUnit.module('Gradebook', () => {
})
sinon.spy(gradebook, 'setFilterColumnsBySetting')
sinon.stub(gradebook, 'saveSettings')
sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
sinon.stub(gradebook, 'resetGrading')
sinon.stub(gradebook, 'sortGridRows')
sinon.stub(gradebook, 'updateFilteredContentInfo')
@ -9784,9 +9790,7 @@ QUnit.module('Gradebook#toggleShowSeparateFirstLastNames', hooks => {
}
})
sandbox.stub(gradebook, 'saveSettings').callsFake((_data, callback) => {
callback()
})
sandbox.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
})
test('toggles showSeparateFirstLastNames to true when false', () => {
@ -9843,9 +9847,7 @@ QUnit.module('Gradebook#toggleViewUngradedAsZero', hooks => {
}
})
sandbox.stub(gradebook, 'saveSettings').callsFake((_data, callback) => {
callback()
})
sandbox.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
})
test('toggles viewUngradedAsZero to true when false', () => {
@ -10157,8 +10159,8 @@ QUnit.module('Gradebook#handleViewOptionsUpdated', hooks => {
const [courseId, params] = GradebookApi.saveUserSettings.lastCall.args
strictEqual(courseId, '100')
strictEqual(params.colors.dropped, '#000000')
strictEqual(params.show_unpublished_assignments, true)
strictEqual(params.view_ungraded_as_zero, true)
strictEqual(params.show_unpublished_assignments, 'true')
strictEqual(params.view_ungraded_as_zero, 'true')
})
test('does not call saveUserSettings if no value has changed', async () => {
@ -10364,14 +10366,14 @@ QUnit.module('Gradebook#saveSettings', () => {
test('calls the provided successFn if the request succeeds', async () => {
saveUserSettingsStub.resolves({})
await gradebook.saveSettings({}, successFn, errorFn)
await gradebook.saveSettings({}).then(successFn).catch(errorFn)
strictEqual(successFn.callCount, 1)
ok(errorFn.notCalled)
})
test('calls the provided errorFn if the request fails', async () => {
saveUserSettingsStub.rejects(new Error(':('))
await gradebook.saveSettings({}, successFn, errorFn)
await gradebook.saveSettings({}).then(successFn).catch(errorFn)
strictEqual(errorFn.callCount, 1)
ok(successFn.notCalled)
})

View File

@ -40,9 +40,9 @@ QUnit.module('Gradebook Grid Column Filtering', suiteHooks => {
},
...options
})
sinon.stub(gradebook, 'saveSettings').callsFake((settings, onSuccess = () => {}) => {
onSuccess(settings)
})
sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
}
function createContextModules() {

View File

@ -44,7 +44,9 @@ QUnit.module('GradebookGrid AssignmentCellFormatter', suiteHooks => {
['F', 0.0]
]
gradebook = createGradebook({default_grading_standard: defaultGradingScheme})
sinon.stub(gradebook, 'saveSettings')
sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
formatter = new AssignmentCellFormatter(gradebook)
gradebook.setAssignments({

View File

@ -53,8 +53,14 @@ QUnit.module('GradebookGrid StudentLastNameColumnHeaderRenderer', suiteHooks =>
login_handle_name: 'a_jones',
sis_name: 'Example SIS'
})
sinon.stub(gradebook, 'saveSettings')
renderer = new StudentColumnHeaderRenderer(gradebook, StudentLastNameColumnHeader, 'student_lastname')
sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
renderer = new StudentColumnHeaderRenderer(
gradebook,
StudentLastNameColumnHeader,
'student_lastname'
)
})
suiteHooks.afterEach(() => {
@ -64,7 +70,10 @@ QUnit.module('GradebookGrid StudentLastNameColumnHeaderRenderer', suiteHooks =>
QUnit.module('#render()', () => {
test('renders the StudentLastNameColumnHeader to the given container node', () => {
render()
ok($container.innerText.includes('Student Last Name'), 'the "Student Last Name" header is rendered')
ok(
$container.innerText.includes('Student Last Name'),
'the "Student Last Name" header is rendered'
)
})
})
@ -107,7 +116,9 @@ QUnit.module('GradebookGrid StudentColumnHeaderRenderer', suiteHooks => {
login_handle_name: 'a_jones',
sis_name: 'Example SIS'
})
sinon.stub(gradebook, 'saveSettings')
sinon
.stub(gradebook, 'saveSettings')
.callsFake((_context_id, gradebook_settings) => Promise.resolve(gradebook_settings))
renderer = new StudentColumnHeaderRenderer(gradebook, StudentColumnHeader, 'student')
})
@ -257,8 +268,8 @@ QUnit.module('GradebookGrid StudentColumnHeaderRenderer', suiteHooks => {
strictEqual(component.props.studentGroupsEnabled, false)
})
test('includes the selected enrollment filters', () => {
gradebook.toggleEnrollmentFilter('concluded')
test('includes the selected enrollment filters', async () => {
await gradebook.toggleEnrollmentFilter('concluded')
render()
deepEqual(component.props.selectedEnrollmentFilters, ['concluded'])
})

View File

@ -120,9 +120,7 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
function createGradebookAndAddData(options) {
gradebook = createGradebook(options)
sinon.stub(gradebook, 'saveSettings').callsFake((settings, onSuccess = () => {}) => {
onSuccess(settings)
})
sinon.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
gradebook.initialize()
addGridData()
}
@ -605,9 +603,7 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
]
}
})
sinon.stub(gradebook, 'saveSettings').callsFake((settings, onSuccess = () => {}) => {
onSuccess(settings)
})
sinon.stub(gradebook, 'saveSettings').callsFake(() => Promise.resolve())
})
test('excludes assignment group columns when setting is disabled', () => {
@ -677,8 +673,8 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
gradebook.getAssignment('2302').published = false
})
test('removes unpublished assignment columns when filtered', () => {
gradebook.toggleUnpublishedAssignments()
test('removes unpublished assignment columns when filtered', async () => {
await gradebook.toggleUnpublishedAssignments()
const expectedOrder = [
'assignment_2301',
'assignment_group_2201',
@ -688,8 +684,8 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
deepEqual(gridSpecHelper.listScrollableColumnIds(), expectedOrder)
})
test('removes unrelated assignment columns when filtering by assignment group', () => {
gradebook.updateCurrentAssignmentGroup('2202')
test('removes unrelated assignment columns when filtering by assignment group', async () => {
await gradebook.updateCurrentAssignmentGroup('2202')
const expectedOrder = [
'assignment_2302',
'assignment_group_2201',
@ -699,8 +695,8 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
deepEqual(gridSpecHelper.listScrollableColumnIds(), expectedOrder)
})
test('removes unrelated assignment columns when filtering by grading period', () => {
gradebook.updateCurrentGradingPeriod('1401')
test('removes unrelated assignment columns when filtering by grading period', async () => {
await gradebook.updateCurrentGradingPeriod('1401')
const expectedOrder = [
'assignment_2301',
'assignment_group_2201',
@ -710,9 +706,9 @@ QUnit.module('Gradebook Grid Columns', suiteHooks => {
deepEqual(gridSpecHelper.listScrollableColumnIds(), expectedOrder)
})
test('does not duplicate the total column when filtering by grading period', () => {
test('does not duplicate the total column when filtering by grading period', async () => {
gradebook.freezeTotalGradeColumn()
gradebook.updateCurrentGradingPeriod('1401')
await gradebook.updateCurrentGradingPeriod('1401')
const totalGradeColumns = gridSpecHelper
.listFrozenColumnIds()
.filter(id => id === 'total_grade')

View File

@ -53,19 +53,7 @@ QUnit.module('Gradebook', suiteHooks => {
})
function saveSettings(additionalSettings = {}) {
return new Promise(resolve => {
gradebook.saveSettings(
additionalSettings,
(...args) => {
onSuccess(...args)
resolve()
},
(...args) => {
onFailure(...args)
resolve()
}
)
})
return gradebook.saveSettings(additionalSettings).then(onSuccess).catch(onFailure)
}
function getSavedSettings() {

View File

@ -1619,7 +1619,7 @@ class Gradebook extends React.Component {
if (currentSection !== sectionId) {
this.setFilterRowsBySetting('sectionId', sectionId)
this.postGradesStore.setSelectedSection(sectionId)
return this.saveSettings({}, () => {
return this.saveSettings({}).then(() => {
this.updateSectionFilterVisibility()
return this.dataLoader.reloadStudentDataForSectionFilterChange()
})
@ -1670,7 +1670,7 @@ class Gradebook extends React.Component {
groupId = groupId === '0' ? null : groupId
if (this.getFilterRowsBySetting('studentGroupId') !== groupId) {
this.setFilterRowsBySetting('studentGroupId', groupId)
return this.saveSettings({}, () => {
return this.saveSettings({}).then(() => {
this.updateStudentGroupFilterVisibility()
return this.dataLoader.reloadStudentDataForStudentGroupFilterChange()
})
@ -2916,22 +2916,18 @@ class Gradebook extends React.Component {
})
}
saveSettings(
{
selectedViewOptionsFilters = this.listSelectedViewOptionsFilters(),
showConcludedEnrollments = this.getEnrollmentFilters().concluded,
showInactiveEnrollments = this.getEnrollmentFilters().inactive,
showUnpublishedAssignments = this.gridDisplaySettings.showUnpublishedAssignments,
showSeparateFirstLastNames = this.gridDisplaySettings.showSeparateFirstLastNames,
studentColumnDisplayAs = this.getSelectedPrimaryInfo(),
studentColumnSecondaryInfo = this.getSelectedSecondaryInfo(),
sortRowsBy = this.getSortRowsBySetting(),
viewUngradedAsZero = this.gridDisplaySettings.viewUngradedAsZero,
colors = this.state.gridColors
} = {},
successFn,
errorFn
) {
saveSettings({
selectedViewOptionsFilters = this.listSelectedViewOptionsFilters(),
showConcludedEnrollments = this.getEnrollmentFilters().concluded,
showInactiveEnrollments = this.getEnrollmentFilters().inactive,
showUnpublishedAssignments = this.gridDisplaySettings.showUnpublishedAssignments,
showSeparateFirstLastNames = this.gridDisplaySettings.showSeparateFirstLastNames,
studentColumnDisplayAs = this.getSelectedPrimaryInfo(),
studentColumnSecondaryInfo = this.getSelectedSecondaryInfo(),
sortRowsBy = this.getSortRowsBySetting(),
viewUngradedAsZero = this.gridDisplaySettings.viewUngradedAsZero,
colors = this.state.gridColors
} = {}) {
if (!(selectedViewOptionsFilters.length > 0)) {
selectedViewOptionsFilters.push('')
}
@ -2940,27 +2936,27 @@ class Gradebook extends React.Component {
enter_grades_as: this.gridDisplaySettings.enterGradesAs,
filter_columns_by: underscore(this.gridDisplaySettings.filterColumnsBy),
selected_view_options_filters: selectedViewOptionsFilters,
show_concluded_enrollments: showConcludedEnrollments,
show_inactive_enrollments: showInactiveEnrollments,
show_unpublished_assignments: showUnpublishedAssignments,
show_separate_first_last_names: showSeparateFirstLastNames,
show_concluded_enrollments: showConcludedEnrollments ? 'true' : 'false',
show_inactive_enrollments: showInactiveEnrollments ? 'true' : 'false',
show_unpublished_assignments: showUnpublishedAssignments ? 'true' : 'false',
show_separate_first_last_names: showSeparateFirstLastNames ? 'true' : 'false',
student_column_display_as: studentColumnDisplayAs,
student_column_secondary_info: studentColumnSecondaryInfo,
filter_rows_by: underscore(this.gridDisplaySettings.filterRowsBy),
sort_rows_by_column_id: sortRowsBy.columnId,
sort_rows_by_setting_key: sortRowsBy.settingKey,
sort_rows_by_direction: sortRowsBy.direction,
view_ungraded_as_zero: viewUngradedAsZero,
view_ungraded_as_zero: viewUngradedAsZero ? 'true' : 'false',
colors
}
}
if (this.options.enhanced_gradebook_filters) {
return GradebookApi.saveUserSettings(this.options.context_id, data.gradebook_settings)
.then(successFn)
.catch(errorFn)
} else {
return $.ajaxJSON(this.options.settings_update_url, 'PUT', data, successFn, errorFn)
return new Promise((resolve, reject) => {
$.ajaxJSON(this.options.settings_update_url, 'PUT', data, resolve, reject)
})
}
}
@ -3777,16 +3773,13 @@ class Gradebook extends React.Component {
const toggleableAction = () => {
this.gridDisplaySettings.showUnpublishedAssignments =
!this.gridDisplaySettings.showUnpublishedAssignments
return this.updateColumnsAndRenderViewOptionsMenu()
this.updateColumnsAndRenderViewOptionsMenu()
}
toggleableAction()
return this.saveSettings(
{
showUnpublishedAssignments: this.gridDisplaySettings.showUnpublishedAssignments
},
() => {},
toggleableAction
) // on success, do nothing since the render happened earlier
// on success, do nothing since the render happened earlier
return this.saveSettings({
showUnpublishedAssignments: this.gridDisplaySettings.showUnpublishedAssignments
}).catch(toggleableAction)
}
initShowSeparateFirstLastNames(showSeparateFirstLastNames = false) {
@ -3800,13 +3793,10 @@ class Gradebook extends React.Component {
return this.updateColumnsAndRenderViewOptionsMenu() && this.renderActionMenu()
}
toggleableAction()
return this.saveSettings(
{
showSeparateFirstLastNames: this.gridDisplaySettings.showSeparateFirstLastNames
},
() => {},
toggleableAction
) // on success, do nothing since the render happened earlier
// on success, do nothing since the render happened earlier
return this.saveSettings({
showSeparateFirstLastNames: this.gridDisplaySettings.showSeparateFirstLastNames
}).catch(toggleableAction)
// this pattern keeps the ui snappier rather than waiting for ajax call to complete
}
@ -3821,11 +3811,10 @@ class Gradebook extends React.Component {
this.updateAllTotalColumns()
}
toggleableAction()
return this.saveSettings(
{viewUngradedAsZero: this.gridDisplaySettings.viewUngradedAsZero},
() => {},
toggleableAction
) // on success, do nothing since the render happened earlier
// on success, do nothing since the render happened earlier
return this.saveSettings({
viewUngradedAsZero: this.gridDisplaySettings.viewUngradedAsZero
}).catch(toggleableAction)
}
assignmentsLoadedForCurrentView() {
@ -4096,7 +4085,7 @@ class Gradebook extends React.Component {
this.setState({gridColors: statusColors(this.gridDisplaySettings.colors)})
return successFn()
}
return this.saveSettings({colors}, setAndRenderColors, errorFn)
return this.saveSettings({colors}).then(setAndRenderColors).catch(errorFn)
}
listAvailableViewOptionsFilters() {
@ -4127,7 +4116,7 @@ class Gradebook extends React.Component {
return this.gridDisplaySettings.selectedViewOptionsFilters
}
toggleEnrollmentFilter(enrollmentFilter, skipApply) {
toggleEnrollmentFilter(enrollmentFilter, skipApply = false) {
this.getEnrollmentFilters()[enrollmentFilter] = !this.getEnrollmentFilters()[enrollmentFilter]
if (!skipApply) {
return this.applyEnrollmentFilter()
@ -4142,7 +4131,9 @@ class Gradebook extends React.Component {
applyEnrollmentFilter() {
const showInactive = this.getEnrollmentFilters().inactive
const showConcluded = this.getEnrollmentFilters().concluded
return this.saveSettings({showInactive, showConcluded}, this.updateStudentHeadersAndReloadData)
return this.saveSettings({showInactive, showConcluded}).then(
this.updateStudentHeadersAndReloadData
)
}
getEnrollmentFilters() {
@ -4180,7 +4171,7 @@ class Gradebook extends React.Component {
updateEnterGradesAsSetting(assignmentId, value) {
this.setEnterGradesAsSetting(assignmentId, value)
return this.saveSettings({}, () => {
return this.saveSettings({}).then(() => {
this.gradebookGrid.gridSupport.columns.updateColumnHeaders([
getAssignmentColumnId(assignmentId)
])

View File

@ -47,9 +47,9 @@ function updateSubmission(courseId, assignmentId, userId, submission) {
return axios.put(url, {submission: underscore(submission), include: ['visibility']})
}
function saveUserSettings(courseId, settings) {
function saveUserSettings(courseId, gradebook_settings) {
const url = `/api/v1/courses/${courseId}/gradebook_settings`
return axios.put(url, {gradebook_settings: settings})
return axios.put(url, {gradebook_settings})
}
function updateColumnOrder(courseId, columnOrder) {

View File

@ -27,6 +27,11 @@ function constructRelativeUrl({path, params}: {path: string; params: {[k: string
return `${path}?${queryString}`
}
// https://fetch.spec.whatwg.org/#requestinit
interface RequestInit {
signal?: AbortSignal
}
export type DoFetchApiOpts = {
path: string
method?: string