Skip to content

Commit

Permalink
Merge pull request #12444 from rtibbles/one_ping_only
Browse files Browse the repository at this point in the history
Handle edge cases for resource selection in quizzes
  • Loading branch information
rtibbles authored Jul 17, 2024
2 parents 4608263 + a63b40f commit 9f86d23
Showing 1 changed file with 26 additions and 5 deletions.
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

0 comments on commit 9f86d23

Please sign in to comment.