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

Implement manual questions selection workflow #13091

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@
<div class="save-button-wrapper">
<KButton
primary
:text="
settings.selectPracticeQuiz
? selectQuiz$()
: addNumberOfQuestions$({ count: Math.max(1, settings.questionCount) })
"
:text="saveButtonLabel"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such a nice small cleanup 😅

:disabled="disableSave"
@click="saveSelectedResource"
/>
Expand Down Expand Up @@ -186,6 +182,10 @@

const { selectPracticeQuiz } = route.value.query;

const getDefaultQuestionCount = maxQuestions => {
return Math.min(10, maxQuestions);
};

const settings = ref({
maxQuestions: null,
questionCount: null,
Expand All @@ -199,12 +199,24 @@
newSettings.maxQuestions = MAX_QUESTIONS_PER_QUIZ_SECTION - activeQuestions.value.length;
if (newSettings.questionCount === null) {
// initialize questionCount if it hasn't been set yet
newSettings.questionCount = Math.min(10, newSettings.maxQuestions);
newSettings.questionCount = getDefaultQuestionCount(newSettings.maxQuestions);
}
settings.value = newSettings;
},
{ immediate: true },
);

watch(settings, (newSettings, oldSettings) => {
// If isChoosingManually was toggled
if (newSettings.isChoosingManually !== oldSettings.isChoosingManually) {
if (newSettings.isChoosingManually) {
newSettings.questionCount = newSettings.maxQuestions;
} else {
newSettings.questionCount = getDefaultQuestionCount(newSettings.maxQuestions);
}
}
});

const {
questionsUnusedInSection$,
tooManyQuestions$,
Expand Down Expand Up @@ -369,13 +381,24 @@
return workingResourcePool.value.length > settings.value.questionCount;
});

const saveButtonLabel = computed(() => {
if (selectPracticeQuiz) {
return selectQuiz$();
}
if (settings.value.isChoosingManually) {
return addNumberOfQuestions$({ count: workingQuestions.value.length });
}
return addNumberOfQuestions$({ count: settings.value.questionCount });
});

const disableSave = computed(() => {
if (selectPracticeQuiz) {
return !workingPoolHasChanged.value;
}
return (
!workingPoolHasChanged.value ||
workingPoolQuestionsCount.value < settings.value.questionCount ||
(!settings.value.isChoosingManually &&
workingPoolQuestionsCount.value < settings.value.questionCount) ||
settings.value.questionCount < 1 ||
tooManyQuestions.value ||
settings.value.questionCount.value > settings.value.maxQuestions
Expand Down Expand Up @@ -463,6 +486,7 @@
setWorkingResourcePool,
settings,
disableSave,
saveButtonLabel,
closeConfirmationMessage$,
closeConfirmationTitle$,
tooManyQuestions$,
Expand All @@ -472,8 +496,6 @@
addQuestionsToSectionFromResources,
workingResourcePool,
workingQuestions,
selectQuiz$,
addNumberOfQuestions$,
numberOfSelectedResources$,
numberOfSelectedQuestions$,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
:min="1"
:invalid="questionCount > maxQuestions"
:invalidText="maxNumberOfQuestions$({ count: maxQuestions })"
:disabled="!questionCountIsEditable"
:showInvalidText="true"
class="question-textbox"
/>
Expand All @@ -28,14 +29,14 @@
<KIconButton
icon="minus"
aria-hidden="true"
:disabled="questionCount === 1"
:disabled="questionCount === 1 || !questionCountIsEditable"
@click="questionCount -= 1"
/>
<span :style="{ color: $themeTokens.fineLine }"> | </span>
<KIconButton
icon="plus"
aria-hidden="true"
:disabled="questionCount >= maxQuestions"
:disabled="questionCount >= maxQuestions || !questionCountIsEditable"
@click="questionCount += 1"
/>
</div>
Expand Down Expand Up @@ -131,10 +132,13 @@
props.setContinueAction(null);
});

const questionCountIsEditable = computed(() => !props.settings.isChoosingManually);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is non-blocking, but I'm having a little difficulty wrapping my head around what the question count being editable means here. Why would not choosing manually impact the user's ability to adjust the number of questions? It probably makes sense, and I know that there are only so many variable name possibilities. I'm just a but stuck trying to reason through the relationship here


return {
// eslint-disable-next-line vue/no-unused-properties
prevRoute,
questionCount,
questionCountIsEditable,
maxQuestions: computed(() => props.settings.maxQuestions),
maxNumberOfQuestions$,
numberOfQuestionsLabel$,
Expand Down
Loading