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

EQM: Notify not enough resources to replace questions #12219

Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 10 additions & 12 deletions kolibri/plugins/coach/assets/src/composables/useQuizCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,17 @@ export default function useQuizCreation() {
},
[]
);
if (removedResourceQuestionIds.length === 0) {
// If no resources were removed, we don't need to update the questions
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

This return here has making the whole function to return, and the updates werent applied when we had resource_pool updates.

if (removedResourceQuestionIds.length !== 0) {
const questionsToKeep = originalQuestions.filter(
q => !removedResourceQuestionIds.includes(q.id)
);
const numReplacementsNeeded =
(question_count || originalQuestionCount) - questionsToKeep.length;
updates.questions = [
...questionsToKeep,
...selectRandomQuestionsFromResources(numReplacementsNeeded, resource_pool),
];
}
const questionsToKeep = originalQuestions.filter(
q => !removedResourceQuestionIds.includes(q.id)
);
const numReplacementsNeeded =
(question_count || originalQuestionCount) - questionsToKeep.length;
updates.questions = [
...questionsToKeep,
...selectRandomQuestionsFromResources(numReplacementsNeeded, resource_pool),
];
}
}
} else if (question_count !== originalQuestionCount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template>

<KModal
:title="notEnoughReplacementsTitle$()"
:submitText="addResourcesAction$()"
>
<p>
{{
notEnoughReplacementsMessage$({
selected: selectedQuestions.length,
available: availableResources.length,
})
}}
</p>
<p v-if="availableResources.length">
{{
addMoreResourcesWithNonEmptyPool$({
available: availableResources.length,
})
}}
</p>
<p v-else>
{{ addMoreResourcesWithEmptyPool$() }}
</p>
<template #actions>
<KButtonGroup>
<KButton
@click="() => $emit('close')"
>
{{ goBackAction$() }}
</KButton>
<KButton
primary
@click="() => $emit('addResources')"
>
{{ addResourcesAction$() }}
</KButton>
</KButtonGroup>
</template>
</KModal>

</template>


<script>

import { enhancedQuizManagementStrings } from 'kolibri-common/strings/enhancedQuizManagementStrings';

export default {
name: 'NotEnoughResourcesModal',
setup() {
const {
goBackAction$,
addResourcesAction$,
notEnoughReplacementsTitle$,
notEnoughReplacementsMessage$,
addMoreResourcesWithEmptyPool$,
addMoreResourcesWithNonEmptyPool$,
} = enhancedQuizManagementStrings;
return {
goBackAction$,
addResourcesAction$,
notEnoughReplacementsTitle$,
notEnoughReplacementsMessage$,
addMoreResourcesWithEmptyPool$,
addMoreResourcesWithNonEmptyPool$,
};
},
props: {
selectedQuestions: {
type: Array,
required: true,
},
availableResources: {
type: Array,
required: true,
},
},
};

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
</KGridItem>
</KGrid>
</div>
<NotEnoughResourcesModal
v-if="showNoEnoughResources"
:selectedQuestions="selectedActiveQuestions"
:availableResources="replacementQuestionPool"
@close="showNoEnoughResources = false"
Copy link
Member

Choose a reason for hiding this comment

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

This should also "go back" in the router and close the side panel.

@addResources="redirectToSelectResources"
/>
<KModal
v-if="showReplacementConfirmation"
:submitText="coreString('confirmAction')"
Expand Down Expand Up @@ -160,10 +167,12 @@
import { PageNames } from '../../../constants/index';
import AccordionItem from './AccordionItem';
import AccordionContainer from './AccordionContainer';
import NotEnoughResourcesModal from './NotEnoughResourcesModal';

export default {
name: 'ReplaceQuestions',
components: {
NotEnoughResourcesModal,
AccordionContainer,
AccordionItem,
},
Expand Down Expand Up @@ -202,6 +211,10 @@

const showCloseConfirmation = ref(false);
const showReplacementConfirmation = ref(false);
const showNoEnoughResources = ref(false);

showNoEnoughResources.value =
replacementQuestionPool.value.length < selectedActiveQuestions.value.length;

function handleConfirmClose() {
replacements.value = [];
Expand Down Expand Up @@ -262,6 +275,7 @@
selectAllIsChecked,
replaceSelectedQuestions,
activeResourceMap,
showNoEnoughResources,
showCloseConfirmation,
showReplacementConfirmation,
confirmReplacement,
Expand Down Expand Up @@ -338,6 +352,14 @@
next();
}
},
methods: {
redirectToSelectResources() {
const route = this.$router.getRoute(PageNames.QUIZ_SELECT_RESOURCES, {
section_id: this.activeSection.section_id,
});
this.$router.replace(route);
},
},
};

</script>
Expand Down
27 changes: 27 additions & 0 deletions packages/kolibri-common/strings/enhancedQuizManagementStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,31 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag
allSectionsEmptyWarning: {
message: "You don't have any questions in the quiz",
},
notEnoughReplacementsTitle: {
message: 'Not enough replacements available',
context:
'Title of modal when a user tries to replace more questions than are available in the pool',
},
notEnoughReplacementsMessage: {
message:
"You've selected { selected, number } { selected, plural, one { question } other { questions } } to replace, but {available, plural, =0 { don't have questions } one { only have 1 question } other { only have { available } questions } } available to replace them with.",
context:
'Message of modal when a user tries to replace more questions than are available in the pool',
},
addMoreResourcesWithEmptyPool: {
message: 'Please more resources to this section.',
context: 'Message of modal when a user tries to replace questions but the pool is empty',
},
addMoreResourcesWithNonEmptyPool: {
message:
'Please add more resources to this section, or go back and only select up to { available, number } { available, plural, one { question } other { questions } } to be replaced.',
context:
'Message of modal when a user tries to replace more questions than are available in the pool',
},
addResourcesAction: {
message: 'Add resources',
},
goBackAction: {
message: 'Go back',
},
});