-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10944 from MisRob/tables-loading
Tables loading
- Loading branch information
Showing
11 changed files
with
236 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
46 changes: 46 additions & 0 deletions
46
kolibri/plugins/coach/assets/src/composables/__mocks__/useGroups.js
This file contains 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,46 @@ | ||
/** | ||
* `useGroups` composable function mock. | ||
* | ||
* If default values are sufficient for tests, | ||
* you only need call `jest.mock('<useGroups file path>')` | ||
* at the top of a test file. | ||
* | ||
* If you need to override some default values from some tests, | ||
* you can import a helper function `useGroupsMock` that accepts | ||
* an object with values to be overriden and use it together | ||
* with `mockImplementation` as follows: | ||
* | ||
* ``` | ||
* // eslint-disable-next-line import/named | ||
* import useGroups, { useGroupsMock } from '<useGroups file path>'; | ||
* | ||
* jest.mock('<useGroups file path>') | ||
* | ||
* it('test', () => { | ||
* useGroups.mockImplementation( | ||
* () => useGroupsMock({ groupsAreLoading: true }) | ||
* ); | ||
* }) | ||
* ``` | ||
* | ||
* You can reset your mock implementation back to default values | ||
* for other tests by calling the following in `beforeEach`: | ||
* | ||
* ``` | ||
* useGroups.mockImplementation(() => useGroupsMock()) | ||
* ``` | ||
*/ | ||
|
||
const MOCK_DEFAULTS = { | ||
groupsAreLoading: false, | ||
showGroupsPage: jest.fn(), | ||
}; | ||
|
||
export function useGroupsMock(overrides = {}) { | ||
return { | ||
...MOCK_DEFAULTS, | ||
...overrides, | ||
}; | ||
} | ||
|
||
export default jest.fn(() => useGroupsMock()); |
46 changes: 46 additions & 0 deletions
46
kolibri/plugins/coach/assets/src/composables/__mocks__/useLessons.js
This file contains 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,46 @@ | ||
/** | ||
* `useLessons` composable function mock. | ||
* | ||
* If default values are sufficient for tests, | ||
* you only need call `jest.mock('<useLessons file path>')` | ||
* at the top of a test file. | ||
* | ||
* If you need to override some default values from some tests, | ||
* you can import a helper function `useLessonsMock` that accepts | ||
* an object with values to be overriden and use it together | ||
* with `mockImplementation` as follows: | ||
* | ||
* ``` | ||
* // eslint-disable-next-line import/named | ||
* import useLessons, { useLessonsMock } from '<useLessons file path>'; | ||
* | ||
* jest.mock('<useLessons file path>') | ||
* | ||
* it('test', () => { | ||
* useLessons.mockImplementation( | ||
* () => useLessonsMock({ lessonsAreLoading: true }) | ||
* ); | ||
* }) | ||
* ``` | ||
* | ||
* You can reset your mock implementation back to default values | ||
* for other tests by calling the following in `beforeEach`: | ||
* | ||
* ``` | ||
* useLessons.mockImplementation(() => useLessonsMock()) | ||
* ``` | ||
*/ | ||
|
||
const MOCK_DEFAULTS = { | ||
lessonsAreLoading: false, | ||
showLessonsRootPage: jest.fn(), | ||
}; | ||
|
||
export function useLessonsMock(overrides = {}) { | ||
return { | ||
...MOCK_DEFAULTS, | ||
...overrides, | ||
}; | ||
} | ||
|
||
export default jest.fn(() => useLessonsMock()); |
This file contains 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,71 @@ | ||
import { ref } from 'kolibri.lib.vueCompositionApi'; | ||
import samePageCheckGenerator from 'kolibri.utils.samePageCheckGenerator'; | ||
import { LearnerGroupResource, FacilityUserResource } from 'kolibri.resources'; | ||
|
||
// Place outside the function to keep the state | ||
const groupsAreLoading = ref(false); | ||
|
||
export function useGroups() { | ||
function setGroupsLoading(loading) { | ||
groupsAreLoading.value = loading; | ||
} | ||
|
||
function showGroupsPage(store, classId) { | ||
// On this page, handle loading state locally | ||
// TODO: Open follow-up so that we don't need to do this | ||
store.dispatch('notLoading'); | ||
|
||
setGroupsLoading(true); | ||
|
||
const promises = [ | ||
FacilityUserResource.fetchCollection({ | ||
getParams: { member_of: classId }, | ||
force: true, | ||
}), | ||
LearnerGroupResource.fetchCollection({ | ||
getParams: { parent: classId }, | ||
force: true, | ||
}), | ||
]; | ||
const shouldResolve = samePageCheckGenerator(store); | ||
return Promise.all(promises).then( | ||
([classUsers, groupsCollection]) => { | ||
if (shouldResolve()) { | ||
const groups = groupsCollection.map(group => ({ ...group, users: [] })); | ||
const groupUsersPromises = groups.map(group => | ||
FacilityUserResource.fetchCollection({ | ||
getParams: { member_of: group.id }, | ||
force: true, | ||
}) | ||
); | ||
|
||
Promise.all(groupUsersPromises).then( | ||
groupsUsersCollection => { | ||
if (shouldResolve()) { | ||
groupsUsersCollection.forEach((groupUsers, index) => { | ||
groups[index].users = [...groupUsers]; | ||
}); | ||
store.commit('groups/SET_STATE', { | ||
classUsers: [...classUsers], | ||
groups, | ||
groupModalShown: false, | ||
}); | ||
setGroupsLoading(false); | ||
store.dispatch('clearError'); | ||
} | ||
}, | ||
error => (shouldResolve() ? store.dispatch('handleError', error) : null) | ||
); | ||
} | ||
}, | ||
error => { | ||
shouldResolve() ? store.dispatch('handleError', error) : null; | ||
} | ||
); | ||
} | ||
|
||
return { | ||
groupsAreLoading, | ||
showGroupsPage, | ||
}; | ||
} |
46 changes: 46 additions & 0 deletions
46
kolibri/plugins/coach/assets/src/composables/useLessons.js
This file contains 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,46 @@ | ||
import { ref } from 'kolibri.lib.vueCompositionApi'; | ||
import { LearnerGroupResource } from 'kolibri.resources'; | ||
import { LessonsPageNames } from '../constants/lessonsConstants'; | ||
|
||
// Place outside the function to keep the state | ||
const lessonsAreLoading = ref(false); | ||
|
||
export function useLessons() { | ||
function setLessonsLoading(loading) { | ||
lessonsAreLoading.value = loading; | ||
} | ||
|
||
// Show the Lessons Root Page, where all the Lessons are listed for a given Classroom | ||
function showLessonsRootPage(store, classId) { | ||
// on this page, don't handle loading state globally so we can do it locally | ||
store.dispatch('notLoading'); | ||
|
||
setLessonsLoading(true); | ||
store.commit('lessonsRoot/SET_STATE', { | ||
lessons: [], | ||
learnerGroups: [], | ||
}); | ||
const loadRequirements = [ | ||
// Fetch learner groups for the New Lesson Modal | ||
LearnerGroupResource.fetchCollection({ getParams: { parent: classId } }), | ||
store.dispatch('lessonsRoot/refreshClassLessons', classId), | ||
]; | ||
|
||
return Promise.all(loadRequirements).then( | ||
([learnerGroups]) => { | ||
store.commit('lessonsRoot/SET_LEARNER_GROUPS', learnerGroups); | ||
store.commit('SET_PAGE_NAME', LessonsPageNames.PLAN_LESSONS_ROOT); | ||
setLessonsLoading(false); | ||
}, | ||
error => { | ||
store.dispatch('handleApiError', error); | ||
setLessonsLoading(false); | ||
} | ||
); | ||
} | ||
|
||
return { | ||
lessonsAreLoading, | ||
showLessonsRootPage, | ||
}; | ||
} |
51 changes: 0 additions & 51 deletions
51
kolibri/plugins/coach/assets/src/modules/groups/handlers.js
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
kolibri/plugins/coach/assets/src/modules/lessonsRoot/handlers.js
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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.