Skip to content

Commit 949e586

Browse files
authored
Merge pull request cylc#1794 from MetRonnie/router
Fix router issues
2 parents 08878fb + 8f98567 commit 949e586

30 files changed

+135
-291
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"@lumino/default-theme": "2.1.5",
3030
"@lumino/widgets": "2.3.2",
3131
"@mdi/js": "7.4.47",
32-
"@unhead/vue": "1.9.9",
3332
"@vueuse/core": "10.9.0",
3433
"apexcharts": "3.41.0",
3534
"axios": "1.7.2",

renovate.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
"matchPackageNames": ["sass"],
5656
"schedule": ["on the 25th day of the month"]
5757
},
58-
{
59-
"matchPackageNames": ["@unhead/vue"],
60-
"automerge": true,
61-
"schedule": ["on the 3rd day of the month"]
62-
},
6358
{
6459
"matchPackageNames": ["@vueuse/core"],
6560
"automerge": true,

src/components/cylc/commandMenu/Menu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export default {
254254
// Navigate to the corresponding workflow then open the log view
255255
// (no nav occurs if already on the correct workflow page)
256256
this.$router.push({
257-
name: 'workspace',
257+
name: 'Workspace',
258258
params: {
259259
workflowName: this.node.tokens.workflow
260260
}

src/components/cylc/workspace/Toolbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
131131
<v-spacer class="mx-0" />
132132

133133
<v-btn
134-
v-if="$route.name === 'workspace'"
134+
v-if="$route.name === 'Workspace'"
135135
class="add-view"
136136
color="primary"
137137
data-cy="add-view-btn"

src/layouts/Default.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2929
class="overflow-auto"
3030
:style="coreViewStyle"
3131
>
32-
<v-fade-transition mode="out-in">
33-
<slot/>
34-
</v-fade-transition>
32+
<slot/>
3533
</div>
3634
</v-main>
3735
</div>
@@ -42,6 +40,7 @@ import { computed } from 'vue'
4240
import { useRoute } from 'vue-router'
4341
import { mapState } from 'vuex'
4442
import { store } from '@/store/index'
43+
import { allViews } from '@/views/views'
4544
import { Alert as AlertModel } from '@/model/Alert.model'
4645
import Alert from '@/components/core/Alert.vue'
4746
import Drawer from '@/components/cylc/Drawer.vue'
@@ -57,17 +56,15 @@ export default {
5756
const route = useRoute()
5857
/**
5958
* Views that display workflows. For these views, we do not
60-
* want to display the default Toolbar—the Workflow view
59+
* want to display the default Toolbar—the Workspace view
6160
* has its own Toolbar that communicates with the Workflow
6261
* component (e.g. the Workflow Toolbar owns a button that
6362
* triggers the action to add a new Tree or Table View, so the events
6463
* are passed down from the parent Workflow View).
6564
*/
6665
const workflowViews = [
67-
'workspace',
68-
'tree',
69-
'table',
70-
'graph',
66+
...allViews.keys(),
67+
'Workspace',
7168
]
7269
const { showNavBtn } = useNavBtn()
7370

src/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import { i18n } from '@/i18n/index'
3030
import router from '@/router/index'
3131
import { store } from '@/store/index'
3232
import { createVuetify } from 'vuetify'
33-
import { createHead, VueHeadMixin } from '@unhead/vue'
3433

34+
import 'nprogress/css/nprogress.css'
3535
import '@/styles/index.scss'
3636

3737
if (location.search) {
@@ -50,13 +50,10 @@ if (location.search) {
5050
// Normal app start
5151
const app = createApp(App)
5252

53-
app.mixin(VueHeadMixin)
54-
5553
app.use(store)
5654
app.use(router)
5755
app.use(createVuetify(vuetifyOptions))
5856
app.use(i18n)
59-
app.use(createHead())
6057
app.use(ServicesPlugin)
6158
app.use(CommandMenuPlugin)
6259

src/mixins/graphql.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { mapState } from 'vuex'
2-
3-
/**
1+
/*
42
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
53
*
64
* This program is free software: you can redistribute it and/or modify
@@ -17,15 +15,18 @@ import { mapState } from 'vuex'
1715
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1816
*/
1917

18+
import { mapState } from 'vuex'
19+
2020
/**
2121
* A mixin that contains data used for a GraphQL subscription, such as the
2222
* query variables.
2323
*
24-
* To be used in Views that are bound to VueRouter routes that contain the
24+
* To be used in Views that are bound to Vue-Router routes that contain the
2525
* :workflowName param.
2626
*/
2727
export default {
2828
props: {
29+
/** This is set by vue-router */
2930
workflowName: {
3031
type: String,
3132
required: true

src/router/index.js

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,41 @@
2323
* https://router.vuejs.org/en/
2424
*/
2525

26-
// Lib imports
2726
import { createRouter, createWebHashHistory } from 'vue-router'
2827
import NProgress from 'nprogress'
29-
import { store } from '@/store/index'
30-
31-
import 'nprogress/css/nprogress.css'
28+
import { i18n } from '@/i18n'
3229

33-
// Routes
34-
import paths from './paths'
30+
import paths from '@/router/paths'
31+
import { store } from '@/store/index'
3532
import { Alert } from '@/model/Alert.model'
3633

34+
const defaultPageTitle = i18n.global.t('App.name')
35+
3736
NProgress.configure({ showSpinner: false })
3837

39-
function route (path) {
40-
const copy = Object.assign({}, path)
41-
const view = copy.view
42-
return Object.assign(copy, {
43-
name: path.name || view,
44-
component: (resolve) => import(
45-
`@/views/${view}.vue`
46-
).then(resolve)
47-
})
38+
function getRoute (path) {
39+
return {
40+
...path,
41+
name: path.name || path.view,
42+
component: () => import(`@/views/${path.view}.vue`)
43+
}
44+
}
45+
46+
/**
47+
* Return the page title for a particular route.
48+
* @param {import('vue-router').RouteLocation} route
49+
*/
50+
export function getPageTitle ({ meta, params }) {
51+
const extra = meta.getTitle?.(params) || meta.title
52+
return extra
53+
? `${defaultPageTitle} | ${extra}`
54+
: defaultPageTitle
4855
}
4956

5057
// Create a new router
5158
const router = createRouter({
5259
history: createWebHashHistory(),
53-
routes: paths.map(path => route(path)),
54-
// .concat([{ path: '*', redirect: '/dashboard' }]),
60+
routes: paths.map(getRoute),
5561
scrollBehavior (to, from, savedPosition) {
5662
if (savedPosition) {
5763
return savedPosition
@@ -66,34 +72,40 @@ const router = createRouter({
6672
router.beforeEach(async (to, from) => {
6773
NProgress.start()
6874
if (!store.state.user.user) {
69-
try {
70-
const user = await router.app.config.globalProperties.$userService.getUserProfile()
71-
store.commit('user/SET_USER', user)
72-
} catch (err) {
73-
store.dispatch('setAlert', new Alert(err, 'error'))
74-
}
75+
const user = await router.app.config.globalProperties.$userService.getUserProfile()
76+
// TODO: catch error getting user profile and redirect to static error page
77+
store.commit('user/SET_USER', user)
7578
}
76-
if (!store.state.user.user.permissions.includes('read') && to.name !== 'noAuth') {
77-
return { name: 'noAuth' }
79+
if (!store.state.user.user.permissions?.includes('read')) {
80+
if (to.name !== 'NoAuth') { // Avoid infinite redirect?
81+
return { name: 'NoAuth' }
82+
}
83+
} else if (to.name === 'NoAuth') {
84+
// If authorized, redirect no-auth page to home page
85+
return { path: '/' }
7886
}
7987

80-
if (to.name) {
81-
let title = to.name
82-
let workflowName = null
83-
if (to.meta.toolbar) {
84-
// When a workflow is being displayed, we set the title to a
85-
// different value.
86-
title = to.params.workflowName
87-
workflowName = to.params.workflowName
88-
}
89-
store.commit('app/setTitle', title)
90-
store.commit('workflows/SET_WORKFLOW_NAME', workflowName)
91-
store.dispatch('setAlert', null)
88+
// Set page title:
89+
document.title = getPageTitle(to)
90+
91+
// Set toolbar title:
92+
let title = to.name
93+
if (to.meta.toolbar) {
94+
// When a workflow is being displayed, we set the title to a
95+
// different value.
96+
title = to.params.workflowName
9297
}
98+
store.commit('app/setTitle', title)
99+
store.dispatch('setAlert', null)
93100
})
94101

95102
router.afterEach(() => {
96103
NProgress.done()
97104
})
98105

106+
router.onError((err, to, from) => {
107+
store.dispatch('setAlert', new Alert(err, 'error'))
108+
NProgress.done()
109+
})
110+
99111
export default router

0 commit comments

Comments
 (0)