Skip to content

Commit a5cbc20

Browse files
add routePush function since vue-router is not available in Tour.vue
The component is mounted in `runTour` and somehow doesn't have access to the router when mounted.
1 parent bfc1eb8 commit a5cbc20

3 files changed

Lines changed: 40 additions & 22 deletions

File tree

client/src/components/Tour/Tour.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const PLAY_DELAY = 3000;
1818
const props = defineProps<{
1919
steps: { title: string; content: string; onNext?: () => Promise<void>; onBefore?: () => Promise<void> }[];
2020
requirements: string[];
21+
/** A way to use the vue-router which won't be available in this component locally (because we mount it in `runTour`). */
22+
routePush?: (path: string) => void;
2123
}>();
2224
2325
const currentIndex = ref(-1);
@@ -69,13 +71,29 @@ const modalContents = computed<{
6971
title: "Requires Login",
7072
message: "You must log in to Galaxy to use this tour.",
7173
variant: "info",
74+
okText: props.routePush ? "Login or Register" : undefined,
75+
ok: async () => {
76+
if (props.routePush) {
77+
props.routePush("/login/start");
78+
}
79+
},
7280
};
7381
}
7482
if (props.requirements.indexOf("admin") >= 0 && !isAdminUser(currentUser.value)) {
7583
return {
7684
title: "Requires Admin",
7785
message: "You must be an admin to use this tour.",
7886
variant: "info",
87+
okText: props.routePush ? "Exit Tour" : undefined,
88+
ok: async () => {
89+
if (props.routePush) {
90+
if (isAnonymousUser(currentUser.value)) {
91+
props.routePush("/login/start");
92+
} else {
93+
props.routePush("/");
94+
}
95+
}
96+
},
7997
};
8098
}
8199
// TODO: better estimate for whether the history is new.
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
<template>
2-
<CenterFrame src="/welcome" />
3-
</template>
4-
5-
<script>
6-
import CenterFrame from "entry/analysis/modules/CenterFrame";
1+
<script setup lang="ts">
2+
import { useRouter } from "vue-router/composables";
73
84
import { runTour } from "./runTour";
95
10-
export default {
11-
components: {
12-
CenterFrame,
13-
},
14-
props: {
15-
tourId: {
16-
type: String,
17-
required: true,
18-
},
19-
},
20-
mounted() {
21-
runTour(this.tourId);
22-
},
23-
};
6+
import CenterFrame from "@/entry/analysis/modules/CenterFrame.vue";
7+
8+
const props = defineProps<{
9+
tourId: string;
10+
}>();
11+
12+
const router = useRouter();
13+
14+
function routePush(path: string) {
15+
router.push(path);
16+
}
17+
18+
runTour(props.tourId, null, routePush);
2419
</script>
20+
21+
<template>
22+
<CenterFrame src="/welcome" />
23+
</template>

client/src/components/Tour/runTour.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ function mountTour(props) {
8787
* Runs a Tour by identifier or from provided data.
8888
* @param {String} Unique Tour identifier (for api request)
8989
* @param {Object} Tour data
90+
* @param {Function} routePush function to handle route changes
9091
* @returns mounted instance
9192
*/
92-
export async function runTour(tourId, tourData = null) {
93+
export async function runTour(tourId, tourData = null, routePush = undefined) {
9394
if (!tourData) {
9495
tourData = await getTourData(tourId);
9596
}
@@ -124,5 +125,5 @@ export async function runTour(tourId, tourData = null) {
124125
});
125126
});
126127
const requirements = tourData.requirements || [];
127-
return mountTour({ steps, requirements });
128+
return mountTour({ steps, requirements, routePush });
128129
}

0 commit comments

Comments
 (0)