Skip to content

Commit

Permalink
Merge pull request #12216 from AlexVelezLl/allow-delete-all-questions
Browse files Browse the repository at this point in the history
Allow delete all questions
  • Loading branch information
rtibbles authored May 28, 2024
2 parents 7181cfa + 506f461 commit 5c4aac7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 35 deletions.
67 changes: 35 additions & 32 deletions kolibri/plugins/coach/assets/src/composables/useQuizCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,36 @@ export default function useQuizCreation() {
resource_pool
);
} else {
// In this case, we already had resources in the section, so we need to handle the
// case where a resource has been removed so that we remove & replace the questions
const removedResourceQuestionIds = originalResourcePool.reduce(
(questionIds, originalResource) => {
if (!resource_pool.map(r => r.id).includes(originalResource.id)) {
// If the resource_pool doesn't have the originalResource, we're removing it
questionIds = [...questionIds, ...originalResource.unique_question_ids];
if (question_count === 0) {
updates.questions = [];
} else {
// In this case, we already had resources in the section, so we need to handle the
// case where a resource has been removed so that we remove & replace the questions
const removedResourceQuestionIds = originalResourcePool.reduce(
(questionIds, originalResource) => {
if (!resource_pool.map(r => r.id).includes(originalResource.id)) {
// If the resource_pool doesn't have the originalResource, we're removing it
questionIds = [...questionIds, ...originalResource.unique_question_ids];
return questionIds;
}
return questionIds;
}
return questionIds;
},
[]
);
if (removedResourceQuestionIds.length === 0) {
// If no resources were removed, we don't need to update the questions
return;
},
[]
);
if (removedResourceQuestionIds.length === 0) {
// If no resources were removed, we don't need to update the questions
return;
}
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 Expand Up @@ -445,20 +449,18 @@ export default function useQuizCreation() {
);
});

const allSectionsEmpty = computed(() => {
return get(allSections).every(section => section.questions.length === 0);
});

/**
*/
function deleteActiveSelectedQuestions() {
const { section_id, questions: section_questions } = get(activeSection);
const selectedIds = get(selectedActiveQuestions);
let questions = section_questions.filter(q => !selectedIds.includes(q.id));
let question_count = questions.length;
if (question_count === 0) {
// They've deleted all of the questions. We don't allow `question_count` to be 0,
// so we'll randomly select 1 question for the section -- pass `true` to reseed the shuffle.
questions = selectRandomQuestionsFromResources(1, get(activeResourcePool), selectedIds);
question_count = 1;
}
const questions = section_questions.filter(q => !selectedIds.includes(q.id));
const question_count = questions.length;
updateSection({
section_id,
questions,
Expand Down Expand Up @@ -545,6 +547,7 @@ export default function useQuizCreation() {
replacementQuestionPool,
selectAllIsIndeterminate,
selectAllLabel,
allSectionsEmpty,
allQuestionsSelected,
noQuestionsSelected,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@
<CreateQuizSection v-if="quizInitialized" />

<BottomAppBar>
<span
v-if="allSectionsEmpty"
class="message"
>
{{ allSectionsEmptyWarning$() }}
</span>
<KButtonGroup>
<KButton
:text="coreString('saveAction')"
primary
:disabled="allSectionsEmpty"
@click="() => saveQuizAndRedirect()"
/>
</KButtonGroup>
Expand All @@ -45,6 +52,7 @@
import pickBy from 'lodash/pickBy';
import BottomAppBar from 'kolibri.coreVue.components.BottomAppBar';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import { enhancedQuizManagementStrings } from 'kolibri-common/strings/enhancedQuizManagementStrings';
import { PageNames } from '../../../constants';
import commonCoach from '../../common';
import CoachImmersivePage from '../../CoachImmersivePage';
Expand All @@ -60,10 +68,20 @@
},
mixins: [commonCoreStrings, commonCoach],
setup() {
const { saveQuiz, initializeQuiz } = useQuizCreation();
const { saveQuiz, initializeQuiz, allSectionsEmpty } = useQuizCreation();
const showError = ref(false);
const quizInitialized = ref(false);
return { showError, saveQuiz, initializeQuiz, quizInitialized };
const { allSectionsEmptyWarning$ } = enhancedQuizManagementStrings;
return {
showError,
saveQuiz,
initializeQuiz,
quizInitialized,
allSectionsEmpty,
allSectionsEmptyWarning$,
};
},
provide() {
return {
Expand Down Expand Up @@ -126,4 +144,10 @@
</script>


<style lang="scss" scoped></style>
<style lang="scss" scoped>
.message {
margin-right: 8px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,7 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag
updateResources: {
message: 'Update resources',
},
allSectionsEmptyWarning: {
message: "You don't have any questions in the quiz",
},
});

0 comments on commit 5c4aac7

Please sign in to comment.