Skip to content

Commit

Permalink
Merge pull request #12363 from rtibbles/delenda_sectio
Browse files Browse the repository at this point in the history
Prevents errors on section deletion
  • Loading branch information
rtibbles authored Jun 27, 2024
2 parents 4e93fc0 + b53eb57 commit 3ad4d68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
10 changes: 6 additions & 4 deletions kolibri/plugins/coach/assets/src/composables/useQuizCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,16 @@ export default function useQuizCreation() {
.slice(0, get(activeSectionIndex))
.concat(get(allSections).slice(get(activeSectionIndex) + 1)),
);

/** @type {ComputedRef<QuizQuestion[]>} All questions in the active section's `questions` property
* those which are currently set to be used in the section */
const activeQuestions = computed(() => get(activeSection)?.questions || []);

/** @type {ComputedRef<Object.<string, QuizExercise>>}
* A map of exercise id to exercise for the currently active section */
const activeResourceMap = computed(() => {
const map = {};
for (const question of get(activeSection).questions) {
for (const question of get(activeQuestions)) {
if (!map[question.exercise_id]) {
map[question.exercise_id] = _exerciseMap[question.exercise_id];
}
Expand All @@ -369,9 +374,6 @@ export default function useQuizCreation() {
/** @type {ComputedRef<QuizExercise[]>} The active section's exercises */
const activeResourcePool = computed(() => Object.values(get(activeResourceMap)));

/** @type {ComputedRef<QuizQuestion[]>} All questions in the active section's `questions` property
* those which are currently set to be used in the section */
const activeQuestions = computed(() => get(activeSection).questions);
/** @type {ComputedRef<String[]>}
* All QuizQuestion.items the user selected for the active section */
const selectedActiveQuestions = computed(() => get(_selectedQuestionIds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@
@cancel="showDeleteConfirmation = true"
@submit="handleConfirmDelete"
>
<!-- TODO Use `displaySectionTitle` here once #12274 is merged as that PR
changes how we handle section indexing, which is needed for displaySectionTitle -->
{{ deleteConfirmation$({ section_title: activeSection.section_title }) }}
{{
deleteConfirmation$({
section_title: displaySectionTitle(activeSection, activeSectionIndex),
})
}}
</KModal>
</div>

Expand Down Expand Up @@ -568,15 +570,16 @@
}
},
handleConfirmDelete() {
const { section_title } = this.activeSection;
const section_title = displaySectionTitle(
this.activeSection.value,
this.activeSectionIndex.value,
);
const newIndex = this.activeSectionIndex > 0 ? this.activeSectionIndex - 1 : 0;
this.setActiveSection(newIndex);
this.removeSection(this.activeSectionIndex);
this.$nextTick(() => {
this.$store.dispatch(
'createSnackbar',
// TODO Use `displaySectionTitle` here once #12274 is merged as that PR
// changes how we handle section indexing
this.sectionDeletedNotification$({ section_title }),
);
this.focusActiveSectionTab();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>

<div class="section-settings-content">
<div
v-if="activeSection"
class="section-settings-content"
>
<h5
class="section-settings-top-heading"
:style="{ color: $themeTokens.text }"
Expand Down Expand Up @@ -284,11 +287,14 @@
function handleConfirmDelete() {
const section_title = displaySectionTitle(activeSection.value, activeSectionIndex.value);
const newIndex = this.activeSectionIndex > 0 ? this.activeSectionIndex - 1 : 0;
removeSection(activeSectionIndex.value);
router.replace({
name: PageNames.EXAM_CREATION_ROOT,
params: {
...this.$route.params,
classId: this.$route.params.classId,
quizId: this.$route.params.quizId,
sectionIndex: newIndex,
},
});
this.$store.dispatch('createSnackbar', sectionDeletedNotification$({ section_title }));
Expand Down

0 comments on commit 3ad4d68

Please sign in to comment.