Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prevent access to undefined AttemptLogs while looking at reports #12723

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions kolibri/core/assets/src/views/AttemptLogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@
<AttemptLogItem
class="attempt-selected"
:isSurvey="isSurvey"
:attemptLog="attemptLogs[selectedQuestionNumber]"
:attemptLog="selectedAttemptLog"
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]"
displayTag="span"
/>
</template>
Expand All @@ -62,7 +63,7 @@
v-for="(section, index) in sections"
:id="`section-questions-${index}`"
:key="`section-questions-${index}`"
:title="displaySectionTitle(section, index)"
:title="displaySectionTitle(section, index) || ''"
@focus="expand(index)"
>
<template
Expand Down Expand Up @@ -131,8 +132,9 @@
"
>
<AttemptLogItem
v-if="attemptLogsForCurrentSection[qIndex]"
:isSurvey="isSurvey"
:attemptLog="attemptLogs[section.startQuestionNumber + qIndex]"
:attemptLog="attemptLogsForCurrentSection[qIndex]"
displayTag="p"
/>
</a>
Expand Down Expand Up @@ -193,11 +195,24 @@
return sections.value[currentSectionIndex.value];
});

// Computed property for attempt logs of the current section
const attemptLogsForCurrentSection = computed(() => {
const start = currentSection.value.startQuestionNumber;
return currentSection.value.questions.map((_, index) => {
return props.attemptLogs[start + index];
});
});

const questionSelectOptions = computed(() => {
return currentSection.value.questions.map((question, index) => ({
value: index,
label: questionNumberLabel$({ questionNumber: index + 1 }),
}));
return currentSection.value.questions.reduce((options, question, index) => {
if (attemptLogsForCurrentSection.value[index]) {
options.push({
value: index,
label: questionNumberLabel$({ questionNumber: index + 1 }),
});
}
return options;
}, []);
});

// The KSelect-shaped object for the current section
Expand All @@ -212,6 +227,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 +259,8 @@
sectionSelectOptions,
selectedQuestion,
questionSelectOptions,
attemptLogsForCurrentSection,
selectedAttemptLog,
};
},
props: {
Expand Down