Skip to content
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

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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?

updateQuiz({ id: exam.id });
}
return exam;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
},
});
} else {
if (this.$route.params.quizId === exam.id) {
Copy link
Member

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.

if (String(this.$route.params.quizId) === String(exam.id)) {
return;
}
this.$router.replace({
Expand Down
Loading