Skip to content

Commit 068f25b

Browse files
authored
Merge pull request #12723 from LianaHarris360/attempt-log-undefined
Prevent access to undefined AttemptLogs while looking at reports
2 parents 51ee25c + 6b19bea commit 068f25b

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

kolibri/core/assets/src/exams/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function annotateSections(sections, questions = []) {
263263
if (!sections) {
264264
return [
265265
{
266-
title: '',
266+
section_title: '',
267267
questions: questions,
268268
startQuestionNumber: 0,
269269
endQuestionNumber: questions.length - 1,

kolibri/core/assets/src/views/AttemptLogItem.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:is="displayTag"
66
class="item"
77
>
8-
{{ coreString('questionNumberLabel', { questionNumber: attemptLog.questionNumber }) }}
8+
{{ coreString('questionNumberLabel', { questionNumber: questionNumber }) }}
99
</component>
1010
<template v-if="!isSurvey">
1111
<AttemptIconDiff
@@ -92,6 +92,10 @@
9292
type: Boolean,
9393
required: true,
9494
},
95+
questionNumber: {
96+
type: Number,
97+
required: true,
98+
},
9599
},
96100
computed: {
97101
showDiff() {

kolibri/core/assets/src/views/AttemptLogList.vue

+22-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@
3838
<AttemptLogItem
3939
class="attempt-selected"
4040
:isSurvey="isSurvey"
41-
:attemptLog="attemptLogs[selectedQuestionNumber]"
41+
:attemptLog="selectedAttemptLog"
42+
:questionNumber="selectedQuestionNumber + 1"
4243
displayTag="span"
4344
/>
4445
</template>
4546
<template #option="{ index }">
4647
<AttemptLogItem
48+
v-if="attemptLogsForCurrentSection[index]"
4749
class="attempt-option"
4850
:isSurvey="isSurvey"
49-
:attemptLog="attemptLogs[sections[currentSectionIndex].startQuestionNumber + index]"
51+
:attemptLog="attemptLogsForCurrentSection[index]"
52+
:questionNumber="index + 1"
5053
displayTag="span"
5154
/>
5255
</template>
@@ -131,8 +134,10 @@
131134
"
132135
>
133136
<AttemptLogItem
137+
v-if="attemptLogsForCurrentSection[qIndex]"
134138
:isSurvey="isSurvey"
135-
:attemptLog="attemptLogs[section.startQuestionNumber + qIndex]"
139+
:attemptLog="attemptLogsForCurrentSection[qIndex]"
140+
:questionNumber="qIndex + 1"
136141
displayTag="p"
137142
/>
138143
</a>
@@ -193,10 +198,17 @@
193198
return sections.value[currentSectionIndex.value];
194199
});
195200
201+
// Computed property for attempt logs of the current section
202+
const attemptLogsForCurrentSection = computed(() => {
203+
const start = currentSection.value.startQuestionNumber;
204+
return props.attemptLogs.slice(start, start + currentSection.value.questions.length);
205+
});
206+
196207
const questionSelectOptions = computed(() => {
197208
return currentSection.value.questions.map((question, index) => ({
198209
value: index,
199210
label: questionNumberLabel$({ questionNumber: index + 1 }),
211+
disabled: !attemptLogsForCurrentSection.value[index],
200212
}));
201213
});
202214
@@ -212,6 +224,11 @@
212224
];
213225
});
214226
227+
// Computed property for the selected attempt log
228+
const selectedAttemptLog = computed(() => {
229+
return props.attemptLogs[selectedQuestionNumber.value];
230+
});
231+
215232
function handleQuestionChange(index) {
216233
emit('select', index + currentSection.value.startQuestionNumber);
217234
expandCurrentSectionIfNeeded();
@@ -239,6 +256,8 @@
239256
sectionSelectOptions,
240257
selectedQuestion,
241258
questionSelectOptions,
259+
attemptLogsForCurrentSection,
260+
selectedAttemptLog,
242261
};
243262
},
244263
props: {

0 commit comments

Comments
 (0)