Skip to content

Commit

Permalink
Use sub routes to manage tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Sep 30, 2024
1 parent a535618 commit 4ce565d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
4 changes: 4 additions & 0 deletions kolibri/plugins/coach/assets/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const PageNames = {
QUIZ_SECTION_ORDER: 'QUIZ_SECTION_ORDER',
BOOK_MARKED_RESOURCES: 'BOOK_MARKED_RESOURCES',

/** Quiz summary page */
QUIZ_LEARNERS_REPORT_TAB: 'QUIZ_LEARNERS_REPORT_TAB',
QUIZ_DIFFICULT_QUESTIONS_REPORT_TAB: 'QUIZ_DIFFICULT_QUESTIONS_REPORT_TAB',

EXAM_REPORT: 'EXAM_REPORT',
EXAM_REPORT_DETAIL: 'EXAM_REPORT_DETAIL',
EXAM_REPORT_DETAIL_ROOT: 'EXAM_REPORT_DETAIL_ROOT',
Expand Down
29 changes: 28 additions & 1 deletion kolibri/plugins/coach/assets/src/routes/planExamRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import CoachExamsPage from '../views/plan/CoachExamsPage';
import QuizSummaryPage from '../views/plan/QuizSummaryPage';
import SectionOrder from '../views/plan/CreateExamPage/SectionOrder';
import { generateQuestionListHandler } from '../modules/questionList/handlers';
import ReportsLearnersTable from '../views/reports/ReportsLearnersTable.vue';
import ReportsDifficultQuestionsTable from '../views/reports/ReportsDifficultQuestionsTable.vue';
import { QuizzesTabs } from '../constants/tabsConstants';

export default [
{
Expand Down Expand Up @@ -54,11 +57,35 @@ export default [
},
{
name: QuizSummaryPage.name,
path: '/:classId/plan/quizzes/:quizId/:tabId?',
path: '/:classId/plan/quizzes/:quizId',
component: QuizSummaryPage,
handler: generateQuestionListHandler(['quizId']),
meta: {
titleParts: ['QUIZ_NAME', 'quizzesLabel', 'CLASS_NAME'],
},
children: [
{
name: PageNames.QUIZ_LEARNERS_REPORT_TAB,
path: QuizzesTabs.REPORT,
component: ReportsLearnersTable,
},
{
name: PageNames.QUIZ_DIFFICULT_QUESTIONS_REPORT_TAB,
path: QuizzesTabs.DIFFICULT_QUESTIONS,
component: ReportsDifficultQuestionsTable,
},
{
path: '*',
redirect: {
name: PageNames.QUIZ_LEARNERS_REPORT_TAB,
},
},
{
path: '',
redirect: {
name: PageNames.QUIZ_LEARNERS_REPORT_TAB,
},
},
],
},
];
5 changes: 4 additions & 1 deletion kolibri/plugins/coach/assets/src/views/CoachAppBarPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
</div>
</AppBarPage>

<router-view />
<!--
Not sure the implications of removing this router-view, but because of this the table
was being rendered twice
-->
</NotificationsRoot>

</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,11 @@
:tabsId="QUIZZES_TABS_ID"
:activeTabId="activeTabId"
>
<template #[QuizzesTabs.REPORT]>
<ReportsLearnersTable
ref="table"
:entries="learnersTable"
:questionCount="exam.question_count"
/>
</template>
<template #[QuizzesTabs.DIFFICULT_QUESTIONS]>
<ReportsDifficultQuestionsTable
ref="table"
:entries="difficultQuestionsTable"
:isMissingResource="exam.missing_resource"
/>
</template>
<router-view
ref="table"
:entries="entries"
:questionCount="exam.question_count"
/>
</KTabsPanel>
</KPageContainer>
</KGridItem>
Expand Down Expand Up @@ -101,8 +92,6 @@
import CoachAppBarPage from '../../CoachAppBarPage';
import { coachStringsMixin } from '../../common/commonCoachStrings';
import ReportsControls from '../../reports/ReportsControls';
import ReportsLearnersTable from '../../reports/ReportsLearnersTable';
import ReportsDifficultQuestionsTable from '../../reports/ReportsDifficultQuestionsTable';
import QuizOptionsDropdownMenu from './QuizOptionsDropdownMenu';
import ManageExamModals from './ManageExamModals';
import {
Expand All @@ -118,9 +107,7 @@
CoachAppBarPage,
ReportsControls,
ManageExamModals,
ReportsLearnersTable,
QuizOptionsDropdownMenu,
ReportsDifficultQuestionsTable,
},
mixins: [commonCoach, coachStringsMixin, commonCoreStrings],
setup() {
Expand Down Expand Up @@ -152,7 +139,6 @@
loading: true,
currentAction: '',
QUIZZES_TABS_ID,
QuizzesTabs,
};
},
computed: {
Expand All @@ -166,7 +152,7 @@
return this.$route.params.quizId;
},
activeTabId() {
const { tabId } = this.$route.params;
const tabId = this.$route.path.split('/').pop();
if (Object.values(QuizzesTabs).includes(tabId)) {
return tabId;
}
Expand Down Expand Up @@ -194,6 +180,7 @@
{
id: QuizzesTabs.REPORT,
label: this.coachString('reportLabel'),
to: this.classRoute('QUIZ_LEARNERS_REPORT_TAB', { quizId: this.quizId }),
},
];
Expand All @@ -202,15 +189,18 @@
tabsList.push({
id: QuizzesTabs.DIFFICULT_QUESTIONS,
label: this.coachString('difficultQuestionsLabel'),
to: this.classRoute('QUIZ_DIFFICULT_QUESTIONS_REPORT_TAB', { quizId: this.quizId }),
});
}
tabsList.forEach(tab => {
tab.to = this.classRoute('QuizSummaryPage', { quizId: this.quizId, tabId: tab.id });
});
return tabsList;
},
entries() {
if (this.activeTabId === QuizzesTabs.REPORT) {
return this.learnersTable;
}
return this.difficultQuestionsTable;
},
learnersTable() {
const learners = this.recipients.map(learnerId => this.learnerMap[learnerId]);
const sorted = sortBy(learners, ['name']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<td>
<span v-if="$isPrint">{{ tableRow.title }}</span>
<KRouterLink
v-if="!isMissingResource"
v-if="!exam.missing_resource"
:text="tableRow.title"
:to="questionLink(tableRow.item)"
icon="question"
Expand Down Expand Up @@ -70,10 +70,6 @@
type: Array,
default: () => [],
},
isMissingResource: {
type: Boolean,
default: false,
},
},
computed: {
exam() {
Expand Down

0 comments on commit 4ce565d

Please sign in to comment.