Skip to content

Commit

Permalink
Merge pull request #3234 from NCI-Agency/fix-spurious-autosave
Browse files Browse the repository at this point in the history
Fix spurious auto-save
  • Loading branch information
VassilIordanov authored Oct 6, 2020
2 parents e9e62b1 + 2339706 commit e4f96a1
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions client/src/pages/reports/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ const ReportForm = ({
resetForm,
setSubmitting
}) => {
// need up-to-date copies of these in the autosave handler
Object.assign(autoSaveSettings, { dirty, values, touched })
if (!autoSaveSettings.timeoutId) {
// Schedule the auto-save timer
const autosaveHandler = () =>
autoSave({ setFieldValue, setFieldTouched, resetForm })
autoSaveSettings.timeoutId = window.setTimeout(
autosaveHandler,
autoSaveSettings.autoSaveTimeout.asMilliseconds()
)
}

if (!validateFieldDebounced) {
validateFieldDebounced = _debounce(validateField, 400)
}
Expand Down Expand Up @@ -445,19 +457,7 @@ const ReportForm = ({
queryVars: {}
}
}
// need up-to-date copies of these in the autosave handler
autoSaveSettings.dirty = dirty
autoSaveSettings.values = values
autoSaveSettings.touched = touched
if (!autoSaveSettings.timeoutId) {
// Schedule the auto-save timer
const autosaveHandler = () =>
autoSave({ setFieldValue, setFieldTouched, resetForm })
autoSaveSettings.timeoutId = window.setTimeout(
autosaveHandler,
autoSaveSettings.autoSaveTimeout.asMilliseconds()
)
}

// Only the author can delete a report, and only in DRAFT.
const canDelete =
!!values.uuid &&
Expand Down Expand Up @@ -976,7 +976,7 @@ const ReportForm = ({
onChange={value =>
setFieldValue(
"reportSensitiveInformation.text",
value,
value || null,
true
)}
widget={
Expand Down

0 comments on commit e4f96a1

Please sign in to comment.