Skip to content

Commit

Permalink
Clean PageNames object and fix navigation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Nov 7, 2024
1 parent 755532b commit cd788dc
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 85 deletions.
10 changes: 5 additions & 5 deletions kolibri/plugins/coach/assets/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CoachToolsModule extends KolibriApp {
PageNames.QUIZ_SELECT_PRACTICE_QUIZ,
PageNames.QUIZ_SELECT_RESOURCES,
PageNames.QUIZ_SECTION_ORDER,
PageNames.BOOK_MARKED_RESOURCES,
PageNames.QUIZ_BOOK_MARKED_RESOURCES,
PageNames.QUIZ_LEARNER_REPORT,
];
// If we're navigating to the same page for a quiz summary page, don't set loading
Expand Down Expand Up @@ -100,12 +100,12 @@ class CoachToolsModule extends KolibriApp {
PageNames.LESSON_CREATION_ROOT,
PageNames.LESSON_SUMMARY,
PageNames.LESSON_EDIT_DETAILS,
PageNames.SELECTION_ROOT,
PageNames.SELECTION,
PageNames.SELECTION_SEARCH,
PageNames.LESSON_RESOURCE_SELECTION_ROOT,
PageNames.LESSON_RESOURCE_SELECTION,
PageNames.LESSON_RESOURCE_SELECTION_SEARCH,
PageNames.LESSON_SELECTION_BOOKMARKS,
PageNames.LESSON_SELECTION_BOOKMARKS_MAIN,
PageNames.SELECTION_CONTENT_PREVIEW,
PageNames.LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW,
PageNames.RESOURCE_CONTENT_PREVIEW,
PageNames.GROUP_SUMMARY,
PageNames.GROUP_ENROLL,
Expand Down
65 changes: 25 additions & 40 deletions kolibri/plugins/coach/assets/src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,66 @@
export const PageNames = {
/** Class Summary */
HOME_PAGE: 'HomePage', // make sure this matches the Coach 'Home' page name
REPORTS_PAGE: 'REPORTS_PAGE',
COACH_CLASS_LIST_PAGE: 'COACH_CLASS_LIST_PAGE',
NEW_COACH_PAGES: 'NEW_COACH_PAGES',
EXAMS_ROOT: 'EXAMS_ROOT',
EXAM_CREATION_ROOT: 'EXAM_CREATION_ROOT',
EXAM_SUMMARY: 'EXAM_SUMMARY',

/** Newly added routes */
/** Exams and quizzes */
EXAMS_ROOT: 'EXAMS_ROOT',
EXAM_SUMMARY: 'EXAM_SUMMARY',
QUIZ_PREVIEW: 'QUIZ_PREVIEW',
QUIZ_LEARNER_PAGE_ROOT: 'QUIZ_LEARNER_PAGE_ROOT',
QUIZ_LEARNER_REPORT: 'QUIZ_LEARNER_REPORT',
QUIZ_SECTION_EDITOR: 'QUIZ_SECTION_EDITOR',
QUIZ_REPLACE_QUESTIONS: 'QUIZ_REPLACE_QUESTIONS',
QUIZ_SELECT_RESOURCES: 'QUIZ_SELECT_RESOURCES',
QUIZ_SELECT_PRACTICE_QUIZ: 'QUIZ_SELECT_PRACTICE_QUIZ',
QUIZ_SECTION_ORDER: 'QUIZ_SECTION_ORDER',
QUIZ_LEARNER_REPORT: 'QUIZ_LEARNER_REPORT',
QUIZ_PREVIEW: 'QUIZ_PREVIEW',
QUIZ_QUESTION_PAGE_ROOT: 'QUIZ_QUESTION_PAGE_ROOT',
QUIZ_QUESTION_REPORT: 'QUIZ_QUESTION_REPORT',
BOOK_MARKED_RESOURCES: 'BOOK_MARKED_RESOURCES',

EXAM_REPORT: 'EXAM_REPORT',
EXAM_REPORT_DETAIL: 'EXAM_REPORT_DETAIL',
EXAM_REPORT_DETAIL_ROOT: 'EXAM_REPORT_DETAIL_ROOT',
LESSON_EXERCISE_LEARNER_PAGE_ROOT: 'LESSON_EXERCISE_LEARNER_PAGE_ROOT',
LESSON_EXERCISE_LEARNER_REPORT: 'LESSON_EXERCISE_LEARNER_REPORT',
REPORTS_GROUP_REPORT_LESSON_EXERCISE_LEARNER_PAGE_ROOT:
'REPORTS_GROUP_REPORT_LESSON_EXERCISE_LEARNER_PAGE_ROOT',
LESSON_LEARNER_EXERCISE_PAGE_ROOT: 'LESSON_LEARNER_EXERCISE_PAGE_ROOT',
LESSON_LEARNER_EXERCISE_REPORT: 'LESSON_LEARNER_EXERCISE_REPORT',
REPORTS_GROUP_LEARNER_REPORT_QUIZ_PAGE_ROOT: 'REPORTS_GROUP_LEARNER_REPORT_QUIZ_PAGE_ROOT',
QUIZ_LEARNER_PAGE_ROOT: 'QUIZ_LEARNER_PAGE_ROOT',
REPORTS_LEARNER_REPORT_QUIZ_PAGE_ROOT: 'REPORTS_LEARNER_REPORT_QUIZ_PAGE_ROOT',
REPORTS_QUIZ_LEARNER_PAGE_ROOT: 'REPORTS_QUIZ_LEARNER_PAGE_ROOT',
LESSON_EXERCISE_QUESTION_PAGE_ROOT: 'LESSON_EXERCISE_QUESTION_PAGE_ROOT',
REPORTS_GROUP_REPORT_QUIZ_QUESTION_PAGE_ROOT: 'REPORTS_GROUP_REPORT_QUIZ_QUESTION_PAGE_ROOT',
QUIZ_BOOK_MARKED_RESOURCES: 'QUIZ_BOOK_MARKED_RESOURCES',

/* Lessons */
LESSONS_ROOT: 'LESSONS_ROOT',
LESSONS_ROOT_BETTER: 'LESSONS_ROOT_BETTER',
LESSON_SUMMARY: 'LESSON_SUMMARY',
LESSON_CREATION_ROOT: 'LESSON_CREATION_ROOT',
LESSON_CREATION_ROOT_BETTER: 'LESSON_CREATION_ROOT_BETTER',
LESSON_SUMMARY: 'LESSON_SUMMARY',
RESOURCE_USER_REPORT: 'RESOURCE_USER_REPORT',
RESOURCE_USER_REPORT_ROOT: 'RESOURCE_USER_REPORT_ROOT',
RESOURCE_CONTENT_PREVIEW: 'RESOURCE_CONTENT_PREVIEW', // exclusively a route name
SELECTION_ROOT: 'SELECTION_ROOT',
SELECTION: 'SELECTION',
SELECTION_SEARCH: 'SELECTION_SEARCH',
SELECTION_CONTENT_PREVIEW: 'SELECTION_CONTENT_PREVIEW', // exclusively a route name
CONTENT_PREVIEW: 'CONTENT_PREVIEW',
LESSON_RESOURCE_SELECTION_ROOT: 'LESSON_RESOURCE_SELECTION_ROOT',
LESSON_RESOURCE_SELECTION: 'LESSON_RESOURCE_SELECTION',
LESSON_RESOURCE_SELECTION_SEARCH: 'LESSON_RESOURCE_SELECTION_SEARCH',
LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW: 'LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW', // exclusively a route name
LESSON_CONTENT_PREVIEW: 'LESSON_CONTENT_PREVIEW',
LESSON_SELECTION_BOOKMARKS: 'LESSON_SELECTION_BOOKMARKS',
LESSON_SELECTION_BOOKMARKS_MAIN: 'LESSON_SELECTION_BOOKMARKS_MAIN',
LESSON_EDIT_DETAILS: 'LESSON_EDIT_DETAILS',
LESSON_SELECT_RESOURCES: 'LESSON_SELECT_RESOURCES',
LESSON_PREVIEW_SELECTED_RESOURCES: 'LESSON_PREVIEW_SELECTED_RESOURCES',
LESSON_PREVIEW_RESOURCE: 'LESSON_PREVIEW_RESOURCE',
LESSON_RESOURCE_LEARNERS_REPORT: 'LESSON_RESOURCE_LEARNERS_REPORT',
LESSON_LEARNER_REPORT: 'LESSON_LEARNER_REPORT',
LESSON_RESOURCE_LEARNERS_REPORT: 'LESSON_RESOURCE_LEARNERS_REPORT',
LESSON_EXERCISE_LEARNER_PAGE_ROOT: 'LESSON_EXERCISE_LEARNER_PAGE_ROOT',
LESSON_EXERCISE_LEARNERS_REPORT: 'LESSON_EXERCISE_LEARNERS_REPORT',
LESSON_EXERCISE_LEARNER_REPORT: 'LESSON_EXERCISE_LEARNER_REPORT',
LESSON_EXERCISE_QUESTIONS_REPORT: 'LESSON_EXERCISE_QUESTIONS_REPORT',
LESSON_EXERCISE_QUESTION_PAGE_ROOT: 'LESSON_EXERCISE_QUESTION_PAGE_ROOT',
LESSON_EXERCISE_QUESTION_REPORT: 'LESSON_EXERCISE_QUESTION_REPORT',
LESSON_LEARNER_EXERCISE_PAGE_ROOT: 'LESSON_LEARNER_EXERCISE_PAGE_ROOT',
LESSON_LEARNER_EXERCISE_REPORT: 'LESSON_LEARNER_EXERCISE_REPORT',

LESSONS_ROOT: 'LESSONS_ROOT',
LESSONS_ROOT_BETTER: 'LESSONS_ROOT_BETTER',

/* Learners */
LEARNERS_ROOT: 'LEARNERS_ROOT',
LEARNER_SUMMARY: 'LEARNER_SUMMARY',
LEARNER_LESSON_REPORT: 'LEARNER_LESSON_REPORT',

/** Groups */
GROUPS_ROOT: 'GROUPS_ROOT',
GROUP_SUMMARY: 'GROUP_SUMMARY',
GROUP_ENROLL: 'GROUP_ENROLL',
GROUP_EXAM_SUMMARY: 'GROUP_EXAM_SUMMARY',
GROUP_LESSON_SUMMARY: 'GROUP_LESSON_SUMMARY',
GROUP_LESSON_LEARNER: 'GROUP_LESSON_LEARNER',
GROUP_LESSON_EXERCISE_QUESTIONS_REPORT: 'GROUP_LESSON_EXERCISE_QUESTIONS_REPORT',
GROUP_LESSON_EXERCISE_LEARNER_REPORT: 'GROUP_LESSON_EXERCISE_LEARNER_REPORT',
GROUP_EXAM_SUMMARY: 'GROUP_EXAM_SUMMARY',
};

export const GroupModals = {
Expand All @@ -91,9 +78,7 @@ export const ViewMoreButtonStates = {
};

export const pageNameToModuleMap = {
[PageNames.EXAM_REPORT_DETAIL]: 'examReportDetail',
[PageNames.LESSONS_ROOT]: 'lessonsRoot',
[PageNames.RESOURCE_USER_REPORT]: 'exerciseDetail',
// Omitting modules for resource selection, exam creation, and preview to prevent
// default module state resetting behavior.
};
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ async function showResourceSelectionPage(store, params) {
store.commit('lessonSummary/resources/SET_SEARCH_RESULTS', params.searchResults);
}
store.commit('SET_PAGE_NAME', pageName);
if (pageName === PageNames.SELECTION_SEARCH) {
if (pageName === PageNames.LESSON_RESOURCE_SELECTION_SEARCH) {
store.commit('SET_TOOLBAR_ROUTE', {
name: PageNames.SELECTION_ROOT,
name: PageNames.LESSON_RESOURCE_SELECTION_ROOT,
});
} else {
store.commit('SET_TOOLBAR_ROUTE', {
Expand Down Expand Up @@ -107,7 +107,7 @@ export function showLessonResourceSelectionRootPage(store, params) {
classId: params.classId,
lessonId: params.lessonId,
contentList: channelContentList,
pageName: PageNames.SELECTION_ROOT,
pageName: PageNames.LESSON_RESOURCE_SELECTION_ROOT,
descendantCounts,
});
},
Expand All @@ -130,7 +130,7 @@ export function showLessonResourceSelectionTopicPage(store, params) {
classId: params.classId,
lessonId: params.lessonId,
contentList: childNodes,
pageName: PageNames.SELECTION,
pageName: PageNames.LESSON_RESOURCE_SELECTION,
descendantCounts,
ancestors: [...topicNode.ancestors, topicNode],
});
Expand All @@ -150,7 +150,7 @@ export function showLessonResourceBookmarks(store, params) {
classId: params.classId,
lessonId: params.lessonId,
bookmarksList: childNodes,
pageName: PageNames.SELECTION,
pageName: PageNames.LESSON_RESOURCE_SELECTION,
ancestors: [...topicNode.ancestors, topicNode],
});
});
Expand Down Expand Up @@ -222,15 +222,15 @@ export async function showLessonSelectionContentPreview(store, params, query = {
const { searchTerm, ...otherQueryParams } = query;
if (searchTerm) {
store.commit('SET_TOOLBAR_ROUTE', {
name: PageNames.SELECTION_SEARCH,
name: PageNames.LESSON_RESOURCE_SELECTION_SEARCH,
params: {
searchTerm,
},
query: otherQueryParams,
});
} else {
store.commit('SET_TOOLBAR_ROUTE', {
name: PageNames.SELECTION,
name: PageNames.LESSON_RESOURCE_SELECTION,
params: {
topicId: contentNode.parent,
},
Expand Down Expand Up @@ -273,7 +273,7 @@ function _prepLessonContentPreview(store, classId, lessonId, contentId) {
});
}

store.commit('SET_PAGE_NAME', PageNames.CONTENT_PREVIEW);
store.commit('SET_PAGE_NAME', PageNames.LESSON_CONTENT_PREVIEW);
return contentNode;
},
error => {
Expand All @@ -298,7 +298,7 @@ export function showLessonResourceSearchPage(store, params, query = {}) {
lessonId: params.lessonId,
contentList: results.results,
searchResults: results,
pageName: PageNames.SELECTION_SEARCH,
pageName: PageNames.LESSON_RESOURCE_SELECTION_SEARCH,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/coach/assets/src/modules/pluginModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default {
// If going from Lesson Summary to something other than Resource Selection, reset
if (
fromRoute.name === PageNames.LESSON_SUMMARY &&
![PageNames.SELECTION_ROOT, PageNames.LESSON_SUMMARY].includes(toRoute.name)
![PageNames.LESSON_RESOURCE_SELECTION_ROOT, PageNames.LESSON_SUMMARY].includes(toRoute.name)
) {
return store.dispatch('lessonSummary/resetLessonSummaryState');
}
Expand Down
12 changes: 6 additions & 6 deletions kolibri/plugins/coach/assets/src/routes/lessonsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ export default [
component: LessonEditDetailsPage,
},
{
name: PageNames.SELECTION_ROOT,
name: PageNames.LESSON_RESOURCE_SELECTION_ROOT,
path: CLASS + LESSON + SELECTION,
component: LessonResourceSelectionPage,
handler(toRoute) {
showLessonResourceSelectionRootPage(store, toRoute.params);
},
},
{
name: PageNames.SELECTION,
name: PageNames.LESSON_RESOURCE_SELECTION,
path: CLASS + LESSON + SELECTION + TOPIC,
component: LessonResourceSelectionPage,
handler(toRoute, fromRoute) {
Expand All @@ -174,7 +174,7 @@ export default [
// called whether or not a change is made, because we don't track changes
// enough steps back.
let preHandlerPromise;
if (fromRoute.name === PageNames.SELECTION_CONTENT_PREVIEW) {
if (fromRoute.name === PageNames.LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW) {
preHandlerPromise = store.dispatch('lessonSummary/saveLessonResources', {
lessonId: toRoute.params.lessonId,
resources: store.state.lessonSummary.workingResources,
Expand All @@ -188,7 +188,7 @@ export default [
},
},
{
name: PageNames.SELECTION_SEARCH,
name: PageNames.LESSON_RESOURCE_SELECTION_SEARCH,
path: CLASS + LESSON + SELECTION + SEARCH,
component: LessonResourceSelectionPage,
handler(toRoute) {
Expand All @@ -201,7 +201,7 @@ export default [
component: LessonResourceSelectionPage,
handler(toRoute, fromRoute) {
let preHandlerPromise;
if (fromRoute.name === PageNames.SELECTION_CONTENT_PREVIEW) {
if (fromRoute.name === PageNames.LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW) {
preHandlerPromise = store.dispatch('lessonSummary/saveLessonResources', {
lessonId: toRoute.params.lessonId,
resources: store.state.lessonSummary.workingResources,
Expand All @@ -223,7 +223,7 @@ export default [
},
},
{
name: PageNames.SELECTION_CONTENT_PREVIEW,
name: PageNames.LESSON_RESOURCE_SELECTION_CONTENT_PREVIEW,
path: CLASS + LESSON + SELECTION + PREVIEW,
component: LessonSelectionContentPreviewPage,
handler(toRoute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<KPageContainer>
<p>
<BackLink
:to="$router.getRoute(PageNames.GROUPS_ROOT)"
:to="classRoute(PageNames.GROUPS_ROOT)"
:text="$tr('back')"
/>
</p>
Expand Down Expand Up @@ -182,7 +182,7 @@
handleSuccessDeleteGroup() {
this.showSnackbarNotification('groupDeleted');
this.displayModal(false);
this.$router.push(this.$router.getRoute(PageNames.GROUPS_ROOT));
this.$router.push(this.classRoute(PageNames.GROUPS_ROOT));
},
handleOptionSelect(value) {
switch (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
methods: {
link(learnerId) {
return this.classRoute(PageNames.REPORTS_GROUP_REPORT_LESSON_EXERCISE_LEARNER_PAGE_ROOT, {
return this.classRoute(PageNames.LESSON_EXERCISE_LEARNER_PAGE_ROOT, {
learnerId,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const router = new VueRouter({
routes: [
{ name: PageNames.LESSON_SUMMARY, path: '/summary' },
{ name: 'SELECT_RESOURCES', path: '/' },
{ name: 'SELECTION_ROOT', path: '/select' },
{ name: 'LESSON_RESOURCE_SELECTION_ROOT', path: '/select' },
{ name: 'SELECTION', path: '/select/:topicId' },
{ name: 'SELECTION_SEARCH', path: '/search/:searchTerm' },
{ name: 'LESSON_SUMMARY', path: '/reportslessonreportpage' },
Expand Down Expand Up @@ -87,11 +87,11 @@ describe('LessonResourceSelectionPage', () => {
},
});

// If there is no last_id in query params, link to SELECTION_ROOT
// If there is no last_id in query params, link to LESSON_RESOURCE_SELECTION_ROOT
const noLastIdQuery = { ...filterValues };
await router.replace({ query: noLastIdQuery });
expect(button.props().to).toEqual({
name: 'SELECTION_ROOT',
name: 'LESSON_RESOURCE_SELECTION_ROOT',
params: {},
query: {
...filterValues,
Expand All @@ -115,7 +115,7 @@ describe('LessonResourceSelectionPage', () => {
it('the breadcrumbs are visible and have the correct links', () => {
const breadcrumbs = wrapper.findComponent({ name: 'ResourceSelectionBreadcrumbs' });
expect(breadcrumbs.exists()).toBe(true);
expect(breadcrumbs.props().channelsLink.name).toEqual('SELECTION_ROOT');
expect(breadcrumbs.props().channelsLink.name).toEqual('LESSON_RESOURCE_SELECTION_ROOT');
});

it('the bottom bar has the correct label and link if coming from reports page', async () => {
Expand Down
Loading

0 comments on commit cd788dc

Please sign in to comment.