-
Notifications
You must be signed in to change notification settings - Fork 694
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
EQM: On first save, update the quiz's ID when redirecting #12283
EQM: On first save, update the quiz's ID when redirecting #12283
Conversation
Build Artifacts
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, but I think it could live somewhere else, and we do need the checking to prevent redundant navigation errors.
this.$router.replace({ | ||
name: PageNames.EXAM_CREATION_ROOT, | ||
params: { | ||
classId: this.$route.params.classId, | ||
quizId: exam.id, | ||
}, | ||
}); | ||
// Update the quiz with the new id - there won't be if this is a new quiz, | ||
// this ensures the quiz is kept up-to-date since we're replacing the route | ||
this.updateQuiz({ id: exam.id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems right - although maybe this should live inside the useQuizCreation composable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried putting it at the end of saveQuiz but it wasn't working so I tried this... I think that maybe the issue was that I wasn't returning the exam in the then
callback on the ExamResource.saveModel
-- I've pushed an update that seems to work better there.
@@ -174,16 +174,16 @@ | |||
}, | |||
}); | |||
} else { | |||
if (this.$route.params.quizId === exam.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should remove this - but we should coerce them both to strings for the comparison because for draft exams the exam.id will be an integer, but the route parameter will be a string.
When I did a subsequent save, not having this here led me to get a redundant navigation error from the replace below.
@@ -323,7 +323,12 @@ export default function useQuizCreation() { | |||
finalQuiz.question_sources = questionSourcesWithoutResourcePool; | |||
} | |||
|
|||
return ExamResource.saveModel({ id, data: finalQuiz }); | |||
return ExamResource.saveModel({ id, data: finalQuiz }).then(exam => { | |||
if (!get(_quiz).id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this maybe be if (!id || id !== exam.id) {
id
here being assigned to the get(_quiz).id
up above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably if id
is undefined then it won't equal exam.id
either, so the falsy check might be redundant.
But yeah, using the id that we already grabbed in the outer scope feels safer, just in case we're accidentally mutating state for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool - I was getting mixed up a bit around the use of "new"
for the route until they save the quiz but get(_quiz).id
will always be null/undefined
here eh?
2e4ce17
to
7f4614c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, have manually tested creating a new quiz, saving it. Updating it again, and saving again. Everything is working as expected with no errors.
Summary
Fixes #12263
When the
new
quiz is saved, since we replace the route, we need to also update the ID of the quiz so that subsequent saves are updating the quiz rather than trying to save the same quiz anew.Reviewer guidance