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

Conversation

nucleogenesis
Copy link
Member

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

  • If you save a newly created quiz, then click "Save and close" or "Save" after that, you should not see errors.

@github-actions github-actions bot added APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) DEV: frontend SIZE: very small labels Jun 13, 2024
Copy link
Member

@rtibbles rtibbles left a 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 });
Copy link
Member

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?

Copy link
Member Author

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) {
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.

@@ -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?

@nucleogenesis nucleogenesis force-pushed the fix--eqm-can-save-and-save-and-close branch from 2e4ce17 to 7f4614c Compare June 14, 2024 19:51
Copy link
Member

@rtibbles rtibbles left a 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.

@rtibbles rtibbles merged commit 464a831 into learningequality:develop Jun 14, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) DEV: frontend SIZE: small SIZE: very small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EQM: Cannot "Save & Close" directly after "Save"-ing a quiz
2 participants