-
Notifications
You must be signed in to change notification settings - Fork 858
#13168 create composable for exam report data fetching for learn exam report viewer #13203
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
Closed
a-s-t-e-y-a
wants to merge
7
commits into
learningequality:develop
from
a-s-t-e-y-a:#13168-create-composable-for-exam-report-data-fetching-for-LearnExamReportViewer
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6f5a63
FEAT #13168: composable for exam report data fetching for LearningExa…
a-s-t-e-y-a 0866a42
Merge branch 'learningequality:develop' into #13168-create-composable…
a-s-t-e-y-a e14d58b
- Integrate the useExamReport composable to the LearnExamReportViewer
a-s-t-e-y-a b37699e
Merge branch 'learningequality:develop' into #13168-create-composable…
a-s-t-e-y-a 457ae5c
Update useExamReport.js
a-s-t-e-y-a bb237f6
Update LearnExamReportViewer.vue
a-s-t-e-y-a 2440c1c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
198 changes: 198 additions & 0 deletions
198
kolibri/plugins/learn/assets/src/composables/useExamReport.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { ref, computed, reactive, provide, inject } from 'vue'; | ||
| import { getExamReport } from 'kolibri-common/quizzes/utils'; | ||
| import router from 'kolibri/router'; | ||
| import { ClassesPageNames, PageNames } from '../constants'; | ||
| import useLearnerResources from './useLearnerResources'; | ||
|
|
||
| // Keys for provide/inject | ||
| const EXAM_REPORT_KEY = Symbol('examReport'); | ||
|
|
||
| export function provideExamReport() { | ||
| const instance = useExamReportImplementation(); | ||
| provide(EXAM_REPORT_KEY, instance); | ||
| return instance; | ||
| } | ||
|
|
||
| export function useExamReport() { | ||
| return inject(EXAM_REPORT_KEY) || useExamReportImplementation(); | ||
| } | ||
|
|
||
| function useExamReportImplementation() { | ||
| // State refs | ||
| const exam = ref(null); | ||
| const pageName = ref(''); | ||
| const pageLoading = ref(false); | ||
| const exercise = ref(null); | ||
| const exerciseContentNodes = ref([]); | ||
| const questionNumber = ref(0); | ||
| const interactionIndex = ref(0); | ||
| const tryIndex = ref(0); | ||
| const questions = ref([]); | ||
| const error = ref(null); | ||
|
|
||
| // Computed properties | ||
| const classId = computed(() => exam.value?.collection); | ||
|
|
||
| // Get exam visibility status | ||
| const { activeClassesQuizzes } = useLearnerResources(); | ||
| const isReportVisible = computed(() => { | ||
| if (!exam.value) return false; | ||
|
|
||
| const quiz = activeClassesQuizzes.value.find(q => q.id === exam.value.id) || exam.value; | ||
| return quiz.instant_report_visibility !== false || quiz.archive; | ||
| }); | ||
|
|
||
| const isLoading = computed(() => pageLoading.value); | ||
|
|
||
| // Methods that replace Vuex mutations | ||
| const setPageLoading = loading => { | ||
| pageLoading.value = loading; | ||
| }; | ||
|
|
||
| const setPageName = name => { | ||
| pageName.value = name; | ||
| }; | ||
|
|
||
| const setError = err => { | ||
| error.value = err; | ||
| }; | ||
|
|
||
| // Check if current exam report exists in state | ||
| function hasExamReport(examId, tryIdx, questionNum, interactionIdx) { | ||
| return ( | ||
| exam.value && | ||
| exam.value.id === examId && | ||
| tryIndex.value === Number(tryIdx) && | ||
| questionNumber.value === Number(questionNum) && | ||
| interactionIndex.value === Number(interactionIdx) && | ||
| exerciseContentNodes.value.length > 0 | ||
| ); | ||
| } | ||
|
|
||
| // Get exam report from current state - equivalent to getExamReportFromState in handlers.js | ||
| function getExamReportFromState(params) { | ||
| const { examId, questionNum, tryIdx, interactionIdx } = params; | ||
|
|
||
| if (!exam.value || exam.value.id !== examId) { | ||
| return null; | ||
| } | ||
|
|
||
| const exerciseNode = exerciseContentNodes.value.find( | ||
| node => node.id === questions.value[questionNum]?.exercise_id, | ||
| ); | ||
|
|
||
| if (!exerciseNode) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| exam: exam.value, | ||
| exercise: exerciseNode, | ||
| questions: questions.value, | ||
| exerciseContentNodes: exerciseContentNodes.value, | ||
| tryIndex: Number(tryIdx), | ||
| questionNumber: Number(questionNum), | ||
| interactionIndex: Number(interactionIdx), | ||
| }; | ||
| } | ||
|
|
||
| // Show exam report - | ||
| async function showExamReport(params) { | ||
| const { classId, examId, tryIndex: tryIdx, questionNumber: qNum, questionInteraction } = params; | ||
|
|
||
| setPageName(ClassesPageNames.EXAM_REPORT_VIEWER); | ||
|
|
||
| const examReportFromState = getExamReportFromState({ | ||
| examId, | ||
| questionNum: qNum || 0, | ||
| tryIdx: tryIdx || 0, | ||
| interactionIdx: questionInteraction || 0, | ||
| }); | ||
|
|
||
| if (examReportFromState) { | ||
| // Just update state with what we have | ||
| exam.value = examReportFromState.exam; | ||
| exercise.value = examReportFromState.exercise; | ||
| questions.value = examReportFromState.questions; | ||
| exerciseContentNodes.value = examReportFromState.exerciseContentNodes; | ||
| tryIndex.value = examReportFromState.tryIndex; | ||
| questionNumber.value = examReportFromState.questionNumber; | ||
| interactionIndex.value = examReportFromState.interactionIndex; | ||
|
|
||
| setError(null); | ||
| return; | ||
| } | ||
|
|
||
| setPageLoading(true); | ||
|
|
||
| try { | ||
| await fetchExamReport(examId, tryIdx, qNum, questionInteraction); | ||
| setError(null); | ||
| } catch (err) { | ||
| setError(err); | ||
| } finally { | ||
| setPageLoading(false); | ||
| } | ||
| } | ||
|
|
||
| // Fetch exam report | ||
| async function fetchExamReport(examId, tryIdx = 0, questionNum = 0, interactionIdx = 0) { | ||
| // If we already have this report loaded, don't reload | ||
| if (hasExamReport(examId, tryIdx, questionNum, interactionIdx)) { | ||
| return true; | ||
| } | ||
|
|
||
| const report = await getExamReport(examId, tryIdx, questionNum, interactionIdx); | ||
| // Update state | ||
| exam.value = report.exam; | ||
| exercise.value = report.exercise; | ||
| exerciseContentNodes.value = report.exerciseContentNodes; | ||
| questionNumber.value = Number(questionNum); | ||
| interactionIndex.value = Number(interactionIdx); | ||
| tryIndex.value = Number(tryIdx); | ||
| questions.value = report.questions; | ||
| return report; | ||
| } | ||
|
|
||
| // Handle no complete tries scenario | ||
| function handleNoCompleteTries() { | ||
| if (!classId.value) return; | ||
|
|
||
| router.replace({ | ||
| name: ClassesPageNames.CLASS_ASSIGNMENTS, | ||
| params: { classId: classId.value }, | ||
| }); | ||
| } | ||
|
|
||
| // Home page link | ||
| const homePageLink = computed(() => ({ | ||
| name: PageNames.HOME, | ||
| })); | ||
|
|
||
| return { | ||
| // State | ||
| exam, | ||
| exercise, | ||
| exerciseContentNodes, | ||
| questionNumber, | ||
| interactionIndex, | ||
| tryIndex, | ||
| questions, | ||
| classId, | ||
| isLoading, | ||
| error, | ||
| isReportVisible, | ||
| homePageLink, | ||
| showQuizReportComingSoonModal: computed(() => !isReportVisible.value && !isLoading.value), | ||
|
|
||
| // Core state management | ||
| setPageLoading, | ||
| setPageName, | ||
| setError, | ||
|
|
||
| // Methods | ||
| showExamReport, | ||
| fetchExamReport, | ||
| handleNoCompleteTries, | ||
| }; | ||
| } | ||
61 changes: 0 additions & 61 deletions
61
kolibri/plugins/learn/assets/src/modules/examReportViewer/handlers.js
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
kolibri/plugins/learn/assets/src/modules/examReportViewer/index.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never seen
Symbolused before - does it provide any additional value here than just settingEXAM_REPORT_KEY='examReport'?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbol ensures an exclusive key (examReport) that cannot be copied or replaced by other code. This prevents naming collisions, enhancing code security and maintainability.
But if this is not viable I can do this to the simple by making only "examReport"