Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Handle edge cases for resource selection in quizzes #12444

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,16 @@
marginTop: '2em',
marginBottom: '2em',
backgroundColor: $themePalette.grey.v_100,
position: 'sticky',
insetBlockStart: '0',
zIndex: '4',
}"
>
{{ cannotSelectSomeTopicWarning$({ count: maxSectionQuestionOptions }) }}
{{
cannotSelectSomeTopicWarning$({
count: Math.max(maxSectionQuestionOptions, workingPoolUnusedQuestions),
})
}}
</div>

<ContentCardList
Expand All @@ -125,7 +132,10 @@
:contentIsChecked="contentPresentInWorkingResourcePool"
:contentIsIndeterminate="contentPartlyPresentInWorkingResourcePool"
:contentHasCheckbox="showCheckbox"
:contentCheckboxDisabled="c => !nodeIsSelectableOrUnselectable(c)"
:contentCheckboxDisabled="
c =>
!nodeIsSelectableOrUnselectable(c) && !(c.is_leaf && workingPoolUnusedQuestions === 0)
"
:contentCardMessage="selectionMetadata"
:contentCardLink="contentLink"
:loadingMoreState="loadingMore"
Expand All @@ -143,7 +153,7 @@
:layout4="{ span: 2 }"
>
<span v-if="!selectPracticeQuiz">
<span v-if="workingPoolUnusedQuestions > maxSectionQuestionOptions">
<span v-if="tooManyQuestions">
{{
tooManyQuestions$({
count: maxSectionQuestionOptions,
Expand Down Expand Up @@ -663,7 +673,7 @@
}

const workingPoolHasChanged = computed(() => {
return workingResourcePool.value.length;
return Boolean(workingResourcePool.value.length);
});

const workingPoolUnusedQuestions = computed(() => {
Expand All @@ -672,6 +682,16 @@
}, 0);
});

const tooManyQuestions = computed(() => {
// Always allow one resource to be selected, just in case
// the exercise a user wants to use exceeds the maxSectionQuestionOptions
// with only its own unused questions.
return (
workingResourcePool.value.length !== 1 &&
workingPoolUnusedQuestions.value > maxSectionQuestionOptions.value
);
});

const disableSave = computed(() => {
if (selectPracticeQuiz.value) {
return !workingPoolHasChanged.value;
Expand All @@ -680,7 +700,7 @@
!workingPoolHasChanged.value ||
workingPoolUnusedQuestions.value < questionCount.value ||
questionCount.value < 1 ||
workingPoolUnusedQuestions.value > maxSectionQuestionOptions.value
tooManyQuestions.value
);
});

Expand Down Expand Up @@ -709,6 +729,7 @@
handleSelectAll,
toggleSelected,
workingPoolHasChanged,
tooManyQuestions,
handleConfirmClose,
handleCancelClose,
topic,
Expand Down