Skip to content

Commit ecf9a28

Browse files
committed
handle refresh in nav guard, not onMounted, avoid whole setup() function this way
1 parent 25a4219 commit ecf9a28

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

kolibri/plugins/facility/assets/src/views/users/sidePanels/AssignCoachesSidePanel.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
<script>
101101
102-
import { onMounted, ref, computed } from 'vue';
102+
import { ref, computed } from 'vue';
103103
import { useRoute } from 'vue-router/composables';
104104
import SidePanelModal from 'kolibri-common/components/SidePanelModal';
105105
import KIcon from 'kolibri-design-system/lib/KIcon';
@@ -111,6 +111,7 @@
111111
import FacilityUserResource from 'kolibri-common/apiResources/FacilityUserResource';
112112
import flatMap from 'lodash/flatMap';
113113
import CloseConfirmationGuard from '../common/CloseConfirmationGuard.vue';
114+
import { PageNames } from '../../../constants.js';
114115
import { getRootRouteName, overrideRoute } from '../../../utils';
115116
import SelectableList from '../../common/SelectableList.vue';
116117
import { _userState } from '../../../modules/mappers';
@@ -141,13 +142,6 @@
141142
},
142143
});
143144
144-
onMounted(() => {
145-
// Answering the question "what happens when we refresh?"
146-
if (props.selectedUsers.size === 0) {
147-
goBack();
148-
}
149-
});
150-
151145
const {
152146
coachesAssignedNotice$,
153147
assignCoachUndoneNotice$,
@@ -325,6 +319,19 @@
325319
default: () => {},
326320
},
327321
},
322+
beforeRouteEnter(to, from, next) {
323+
// We can't land here without having navigated to here from the users root page - we can't
324+
// have selected any users if we load into this page, so go to the users table.
325+
if (from.name === null) {
326+
next(
327+
// Override to to keep params like facility_id in place
328+
overrideRoute(to, {
329+
name: PageNames.USER_MGMT_PAGE,
330+
}),
331+
);
332+
}
333+
next();
334+
},
328335
beforeRouteLeave(to, from, next) {
329336
this.$refs.closeConfirmationGuardRef?.beforeRouteLeave(to, from, next);
330337
},

kolibri/plugins/facility/assets/src/views/users/sidePanels/EnrollLearnersSidePanel.vue

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<script>
104104
105105
import { useRoute } from 'vue-router/composables';
106-
import { onMounted, getCurrentInstance, ref, computed } from 'vue';
106+
import { getCurrentInstance, ref, computed } from 'vue';
107107
import SidePanelModal from 'kolibri-common/components/SidePanelModal';
108108
import commonCoreStrings from 'kolibri/uiText/commonCoreStrings';
109109
import { useGoBack } from 'kolibri-common/composables/usePreviousRoute';
@@ -112,6 +112,7 @@
112112
import groupBy from 'lodash/groupBy';
113113
import SelectableList from '../../common/SelectableList.vue';
114114
import useActionWithUndo from '../../../composables/useActionWithUndo';
115+
import { PageNames } from '../../../constants.js';
115116
import { getRootRouteName, overrideRoute } from '../../../utils';
116117
import CloseConfirmationGuard from '../common/CloseConfirmationGuard.vue';
117118
@@ -134,13 +135,6 @@
134135
},
135136
});
136137
137-
onMounted(() => {
138-
// Answering the question "what happens when we refresh?"
139-
if (props.selectedUsers.size === 0) {
140-
goBack();
141-
}
142-
});
143-
144138
const loading = ref(false);
145139
const showErrorWarning = ref(false);
146140
const selectedOptions = ref([]);
@@ -302,6 +296,19 @@
302296
default: () => {},
303297
},
304298
},
299+
beforeRouteEnter(to, from, next) {
300+
// We can't land here without having navigated to here from the users root page - we can't
301+
// have selected any users if we load into this page, so go to the users table.
302+
if (from.name === null) {
303+
next(
304+
// Override to to keep params like facility_id in place
305+
overrideRoute(to, {
306+
name: PageNames.USER_MGMT_PAGE,
307+
}),
308+
);
309+
}
310+
next();
311+
},
305312
beforeRouteLeave(to, from, next) {
306313
this.$refs.closeConfirmationGuardRef?.beforeRouteLeave(to, from, next);
307314
},

kolibri/plugins/facility/assets/src/views/users/sidePanels/RemoveFromClassSidePanel.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
import { UserKinds } from 'kolibri/constants';
113113
import groupBy from 'lodash/groupBy';
114114
import { useGoBack } from 'kolibri-common/composables/usePreviousRoute';
115+
import { PageNames } from '../../../constants.js';
115116
import SelectableList from '../../common/SelectableList.vue';
116117
import { getRootRouteName, overrideRoute } from '../../../utils';
117118
import useActionWithUndo from '../../../composables/useActionWithUndo';
@@ -305,10 +306,6 @@
305306
});
306307
307308
onMounted(() => {
308-
// Answering the question "what happens when we refresh?"
309-
if (props.selectedUsers.size === 0) {
310-
goBack();
311-
}
312309
setClassUsers();
313310
});
314311
@@ -359,6 +356,19 @@
359356
default: () => {},
360357
},
361358
},
359+
beforeRouteEnter(to, from, next) {
360+
// We can't land here without having navigated to here from the users root page - we can't
361+
// have selected any users if we load into this page, so go to the users table.
362+
if (from.name === null) {
363+
next(
364+
// Override to to keep params like facility_id in place
365+
overrideRoute(to, {
366+
name: PageNames.USER_MGMT_PAGE,
367+
}),
368+
);
369+
}
370+
next();
371+
},
362372
beforeRouteLeave(to, from, next) {
363373
this.$refs.closeConfirmationGuardRef?.beforeRouteLeave(to, from, next);
364374
},

0 commit comments

Comments
 (0)