Skip to content

Commit

Permalink
Only reuse necessary params from the route.
Browse files Browse the repository at this point in the history
Update strings for replacements modal to reflect updated workflow.
  • Loading branch information
rtibbles committed Jun 16, 2024
1 parent 8610882 commit 672237d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
<NotEnoughResourcesModal
v-if="showNotEnoughResourcesModal"
:selectedQuestions="selectedActiveQuestions"
:availableResources="replacementQuestionPool"
:availableQuestions="replacementQuestionPool"
@close="showNotEnoughResourcesModal = false"
@addResources="redirectToSelectResources"
/>
Expand Down Expand Up @@ -567,6 +567,13 @@
}
},
methods: {
getCurrentRouteParams() {
return {
classId: this.$route.params.classId,
quizId: this.$route.params.quizId,
sectionIndex: this.$route.params.sectionIndex,
};
},
setActiveSection(sectionIndex = null) {
if (sectionIndex === null) {
sectionIndex = 0;
Expand All @@ -575,7 +582,10 @@
throw new Error(`Section with id ${sectionIndex} not found; cannot be set as active.`);
}
if (sectionIndex !== this.activeSectionIndex) {
this.$router.push({ ...this.$route, params: { ...this.$route.params, sectionIndex } });
this.$router.push({
...this.$route,
params: { ...this.getCurrentRouteParams(), sectionIndex },
});
}
},
handleConfirmDelete() {
Expand All @@ -598,21 +608,28 @@
if (this.replacementQuestionPool.length < this.selectedActiveQuestions.length) {
this.showNotEnoughResourcesModal = true;
} else {
const sectionIndex = this.activeSectionIndex;
this.$router.push({ name: PageNames.QUIZ_REPLACE_QUESTIONS, params: { sectionIndex } });
this.$router.push({
name: PageNames.QUIZ_REPLACE_QUESTIONS,
params: this.getCurrentRouteParams(),
});
}
},
handleActiveSectionAction(opt) {
const sectionIndex = this.activeSectionIndex;
switch (opt.id) {
case 'edit':
this.$router.push({ name: PageNames.QUIZ_SECTION_EDITOR, params: { sectionIndex } });
this.$router.push({
name: PageNames.QUIZ_SECTION_EDITOR,
params: this.getCurrentRouteParams(),
});
break;
case 'delete':
this.showDeleteConfirmation = true;
break;
case 'plus':
this.$router.push({ name: PageNames.QUIZ_SELECT_RESOURCES, params: { sectionIndex } });
this.$router.push({
name: PageNames.QUIZ_SELECT_RESOURCES,
params: this.getCurrentRouteParams(),
});
break;
}
},
Expand Down Expand Up @@ -671,7 +688,7 @@
openSelectResources() {
this.$router.push({
name: PageNames.QUIZ_SELECT_RESOURCES,
params: { ...this.$route.params },
params: this.getCurrentRouteParams(),
});
},
deleteQuestions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
<KModal
:title="notEnoughReplacementsTitle$()"
>
<p>
<p v-if="availableQuestions.length">
{{
notEnoughReplacementsMessage$({
selected: selectedQuestions.length,
available: availableResources.length,
available: availableQuestions.length,
})
}}
</p>
<p v-if="availableResources.length">
<p v-else>
{{ noReplacementsMessage$() }}
</p>
<p v-if="availableQuestions.length">
{{
addMoreResourcesWithNonEmptyPool$({
available: availableResources.length,
})
addMoreQuestionsWithNonEmptyPool$()
}}
</p>
<p v-else>
{{ addMoreResourcesWithEmptyPool$() }}
{{ addMoreQuestionsWithEmptyPool$() }}
</p>
<template #actions>
<KButtonGroup>
Expand All @@ -32,7 +33,7 @@
primary
@click="() => $emit('addResources')"
>
{{ addResourcesAction$() }}
{{ addQuestions$() }}
</KButton>
</KButtonGroup>
</template>
Expand All @@ -50,27 +51,29 @@
setup() {
const {
goBackAction$,
addResourcesAction$,
addQuestions$,
notEnoughReplacementsTitle$,
notEnoughReplacementsMessage$,
addMoreResourcesWithEmptyPool$,
addMoreResourcesWithNonEmptyPool$,
addMoreQuestionsWithEmptyPool$,
addMoreQuestionsWithNonEmptyPool$,
noReplacementsMessage$,
} = enhancedQuizManagementStrings;
return {
goBackAction$,
addResourcesAction$,
addQuestions$,
notEnoughReplacementsTitle$,
notEnoughReplacementsMessage$,
addMoreResourcesWithEmptyPool$,
addMoreResourcesWithNonEmptyPool$,
addMoreQuestionsWithEmptyPool$,
addMoreQuestionsWithNonEmptyPool$,
noReplacementsMessage$,
};
},
props: {
selectedQuestions: {
type: Array,
required: true,
},
availableResources: {
availableQuestions: {
type: Array,
required: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@
clearSelectedQuestions();
router.replace({
name: PageNames.EXAM_CREATION_ROOT,
params: { ...this.$route.params },
params: {
classId: this.$route.params.classId,
quizId: this.$route.params.quizId,
sectionIndex: this.$route.params.sectionIndex,
},
});
this.$store.dispatch('createSnackbar', numberOfQuestionsReplaced$({ count }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@
if (option === 'EDIT_DETAILS') {
this.$router.push({
name: PageNames.EXAM_CREATION_ROOT,
params: { ...this.$route.params },
params: {
classId: this.$route.params.classId,
quizId: this.$route.params.quizId,
sectionIndex: 0,
},
query: this.defaultBackLinkQuery,
});
}
Expand Down
13 changes: 9 additions & 4 deletions packages/kolibri-common/strings/enhancedQuizManagementStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,23 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag
context:
'Title of modal when a user tries to replace more questions than are available in the pool',
},
noReplacementsMessage: {
message:
'There are no more similar questions available to replace the selected questions with.',
},
notEnoughReplacementsMessage: {
message:
"You've selected { selected, number } { selected, plural, one { question } other { questions } } to replace, but {available, plural, =0 { don't have questions } one { only have 1 question } other { only have { available } questions } } available to replace them with.",
context:
'Message of modal when a user tries to replace more questions than are available in the pool',
},
addMoreResourcesWithEmptyPool: {
message: 'Please add more resources to this section.',
addMoreQuestionsWithEmptyPool: {
message: 'You can add more questions, or delete existing questions.',
context: 'Message of modal when a user tries to replace questions but the pool is empty',
},
addMoreResourcesWithNonEmptyPool: {
message: 'Please add more resources to this section, or go back and select fewer questions',
addMoreQuestionsWithNonEmptyPool: {
message:
'You can add more questions, delete existing questions, or go back and select fewer questions',
context:
'Message of modal when a user tries to replace more questions than are available in the pool',
},
Expand Down

0 comments on commit 672237d

Please sign in to comment.