Skip to content

Commit

Permalink
Light base routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Nov 7, 2024
1 parent cfb1877 commit 755532b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const pageNameToNotificationPropsMap = [
isMultiple: false,
isWholeClass: false,
},
value: PageNames.LESSON_LEARNER_REPORT,
value: PageNames.LEARNER_LESSON_REPORT,
},
{
key: {
Expand All @@ -108,7 +108,7 @@ const pageNameToNotificationPropsMap = [
isMultiple: false,
isWholeClass: true,
},
value: PageNames.LESSON_LEARNER_REPORT,
value: PageNames.LEARNER_LESSON_REPORT,
},
{
key: {
Expand Down
40 changes: 21 additions & 19 deletions kolibri/plugins/coach/assets/src/routes/baseRoutes.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { PageNames } from '../constants';
import routes from '.';

const baseRouteNames = {
classHome: PageNames.HOME_PAGE,
lessons: PageNames.LESSONS_ROOT,
quizzes: PageNames.EXAMS_ROOT,
learners: PageNames.LEARNERS_ROOT,
groups: PageNames.GROUPS_ROOT,
export default {
classHome: {
name: PageNames.HOME_PAGE,
path: '/:classId?/home',
},
lessons: {
name: PageNames.LESSONS_ROOT,
path: '/:classId?/lessons',
},
quizzes: {
name: PageNames.EXAMS_ROOT,
path: '/:classId?/quizzes',
},
learners: {
name: PageNames.LEARNERS_ROOT,
path: '/:classId?/learners',
},
groups: {
name: PageNames.GROUPS_ROOT,
path: '/:classId?/groups',
},
};

const baseRoutes = Object.entries(baseRouteNames).reduce((curr, baseRouteName) => {
const [key, value] = baseRouteName;
const route = routes.find(({ name }) => name === value);
curr[key] = {
name: route.name,
path: route.path,
};
return curr;
}, {});

export default baseRoutes;
22 changes: 18 additions & 4 deletions kolibri/plugins/coach/assets/src/routes/examRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,30 @@ import {
generateQuestionDetailHandler,
questionRootRedirectHandler,
} from '../modules/questionDetail/handlers';
import { useRouteTerms } from './utils';
import { classIdParamRequiredGuard, useRouteTerms } from './utils';

const { CLASS, QUIZ, ALL_QUIZZES, OPTIONAL_GROUP, LEARNER, QUESTION, TRY, INTERACTION } =
useRouteTerms();
const {
CLASS,
OPTIONAL_CLASS,
QUIZ,
ALL_QUIZZES,
OPTIONAL_GROUP,
LEARNER,
QUESTION,
TRY,
INTERACTION,
} = useRouteTerms();

export default [
{
name: PageNames.EXAMS_ROOT,
path: CLASS + ALL_QUIZZES,
path: OPTIONAL_CLASS + ALL_QUIZZES,
component: ExamsRootPage,
handler(toRoute, fromRoute, next) {
if (classIdParamRequiredGuard(toRoute, PageNames.EXAMS_ROOT, next)) {
return;
}
},
meta: {
titleParts: ['quizzesLabel', 'CLASS_NAME'],
},
Expand Down
25 changes: 19 additions & 6 deletions kolibri/plugins/coach/assets/src/routes/groupsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ import GroupLessonExerciseLearnersPage from '../views/groups/reports/GroupLesson
import { showLessonSummaryPage } from '../modules/lessonSummary/handlers';
import { generateResourceHandler } from '../modules/resourceDetail/handlers';
import QuizSummaryPage from '../views/quizzes/QuizSummaryPage';
import { useRouteTerms } from './utils';
import { classIdParamRequiredGuard, useRouteTerms } from './utils';

const { CLASS, ALL_GROUPS, GROUP, LESSON, LEARNER, ALL_LEARNERS, QUESTIONS, EXERCISE, QUIZ } =
useRouteTerms();
const {
CLASS,
OPTIONAL_CLASS,
ALL_GROUPS,
GROUP,
LESSON,
LEARNER,
ALL_LEARNERS,
QUESTIONS,
EXERCISE,
QUIZ,
} = useRouteTerms();

const { showGroupsPage } = useGroups();

Expand All @@ -26,10 +36,13 @@ function defaultHandler() {
export default [
{
name: PageNames.GROUPS_ROOT,
path: CLASS + ALL_GROUPS,
path: OPTIONAL_CLASS + ALL_GROUPS,
component: GroupsRootPage,
handler(to) {
showGroupsPage(store, to.params.classId);
handler(toRoute, fromRoute, next) {
if (classIdParamRequiredGuard(toRoute, PageNames.GROUPS_ROOT, next)) {
return;
}
showGroupsPage(store, toRoute.params.classId);
},
meta: {
titleParts: ['groupsLabel', 'CLASS_NAME'],
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/coach/assets/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default [
},
{
name: ClassesPageNames.CLASS_LEARNERS_LIST_VIEWER,
path: '/:classId/learners',
path: '/:classId/learners/devices',
component: ClassLearnersListPage,
handler() {
store.dispatch('notLoading');
Expand Down
13 changes: 9 additions & 4 deletions kolibri/plugins/coach/assets/src/routes/learnersRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import LearnersRootPage from '../views/learners/LearnersRootPage';
import LearnerSummaryPage from '../views/learners/LearnerSummaryPage';
import ReportsLearnerActivityPage from '../views/learners/LearnerSummaryPage/ReportsLearnerActivityPage.vue';
import LearnerLessonPage from '../views/learners/reports/LearnerLessonPage.vue';
import { useRouteTerms } from './utils';
import { classIdParamRequiredGuard, useRouteTerms } from './utils';

const { CLASS, ALL_LEARNERS, LEARNER, LESSON } = useRouteTerms();
const { CLASS, OPTIONAL_CLASS, ALL_LEARNERS, LEARNER, LESSON } = useRouteTerms();

function defaultHandler() {
store.dispatch('notLoading');
Expand All @@ -15,9 +15,14 @@ function defaultHandler() {
export default [
{
name: PageNames.LEARNERS_ROOT,
path: CLASS + ALL_LEARNERS,
path: OPTIONAL_CLASS + ALL_LEARNERS,
component: LearnersRootPage,
handler: defaultHandler,
handler(toRoute, fromRoute, next) {
if (classIdParamRequiredGuard(toRoute, PageNames.LEARNERS_ROOT, next)) {
return;
}
defaultHandler();
},
meta: {
titleParts: ['learnersLabel', 'CLASS_NAME'],
},
Expand Down
8 changes: 0 additions & 8 deletions kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,6 @@ export default [
titleParts: ['questionsLabel', 'EXERCISE_NAME', 'LESSON_NAME', 'CLASS_NAME'],
},
},
{
path: CLASS + LESSON + EXERCISE + QUESTION,
name: PageNames.LESSON_EXERCISE_QUESTION_PAGE_ROOT,
beforeEnter: (to, from, next) => {
const { params } = to;
return questionRootRedirectHandler(params, PageNames.LESSON_EXERCISE_QUESTION_REPORT, next);
},
},
{
path: CLASS + LESSON + LEARNER + EXERCISE,
name: PageNames.LESSON_LEARNER_EXERCISE_PAGE_ROOT,
Expand Down

0 comments on commit 755532b

Please sign in to comment.