Skip to content

Commit

Permalink
Merge pull request #12723 from LianaHarris360/attempt-log-undefined
Browse files Browse the repository at this point in the history
Prevent access to undefined AttemptLogs while looking at reports
  • Loading branch information
rtibbles authored Oct 24, 2024
2 parents 51ee25c + 6b19bea commit 068f25b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kolibri/core/assets/src/exams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function annotateSections(sections, questions = []) {
if (!sections) {
return [
{
title: '',
section_title: '',
questions: questions,
startQuestionNumber: 0,
endQuestionNumber: questions.length - 1,
Expand Down
6 changes: 5 additions & 1 deletion kolibri/core/assets/src/views/AttemptLogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:is="displayTag"
class="item"
>
{{ coreString('questionNumberLabel', { questionNumber: attemptLog.questionNumber }) }}
{{ coreString('questionNumberLabel', { questionNumber: questionNumber }) }}
</component>
<template v-if="!isSurvey">
<AttemptIconDiff
Expand Down Expand Up @@ -92,6 +92,10 @@
type: Boolean,
required: true,
},
questionNumber: {
type: Number,
required: true,
},
},
computed: {
showDiff() {
Expand Down
25 changes: 22 additions & 3 deletions kolibri/core/assets/src/views/AttemptLogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
<AttemptLogItem
class="attempt-selected"
:isSurvey="isSurvey"
:attemptLog="attemptLogs[selectedQuestionNumber]"
:attemptLog="selectedAttemptLog"
:questionNumber="selectedQuestionNumber + 1"
displayTag="span"
/>
</template>
<template #option="{ index }">
<AttemptLogItem
v-if="attemptLogsForCurrentSection[index]"
class="attempt-option"
:isSurvey="isSurvey"
:attemptLog="attemptLogs[sections[currentSectionIndex].startQuestionNumber + index]"
:attemptLog="attemptLogsForCurrentSection[index]"
:questionNumber="index + 1"
displayTag="span"
/>
</template>
Expand Down Expand Up @@ -131,8 +134,10 @@
"
>
<AttemptLogItem
v-if="attemptLogsForCurrentSection[qIndex]"
:isSurvey="isSurvey"
:attemptLog="attemptLogs[section.startQuestionNumber + qIndex]"
:attemptLog="attemptLogsForCurrentSection[qIndex]"
:questionNumber="qIndex + 1"
displayTag="p"
/>
</a>
Expand Down Expand Up @@ -193,10 +198,17 @@
return sections.value[currentSectionIndex.value];
});
// Computed property for attempt logs of the current section
const attemptLogsForCurrentSection = computed(() => {
const start = currentSection.value.startQuestionNumber;
return props.attemptLogs.slice(start, start + currentSection.value.questions.length);
});
const questionSelectOptions = computed(() => {
return currentSection.value.questions.map((question, index) => ({
value: index,
label: questionNumberLabel$({ questionNumber: index + 1 }),
disabled: !attemptLogsForCurrentSection.value[index],
}));
});
Expand All @@ -212,6 +224,11 @@
];
});
// Computed property for the selected attempt log
const selectedAttemptLog = computed(() => {
return props.attemptLogs[selectedQuestionNumber.value];
});
function handleQuestionChange(index) {
emit('select', index + currentSection.value.startQuestionNumber);
expandCurrentSectionIfNeeded();
Expand Down Expand Up @@ -239,6 +256,8 @@
sectionSelectOptions,
selectedQuestion,
questionSelectOptions,
attemptLogsForCurrentSection,
selectedAttemptLog,
};
},
props: {
Expand Down

0 comments on commit 068f25b

Please sign in to comment.