Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix router issues #1794

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@lumino/default-theme": "2.1.5",
"@lumino/widgets": "2.3.2",
"@mdi/js": "7.4.47",
"@unhead/vue": "1.9.9",
"@vueuse/core": "10.9.0",
"apexcharts": "3.41.0",
"axios": "1.7.2",
Expand Down
5 changes: 0 additions & 5 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
"matchPackageNames": ["sass"],
"schedule": ["on the 25th day of the month"]
},
{
"matchPackageNames": ["@unhead/vue"],
"automerge": true,
"schedule": ["on the 3rd day of the month"]
},
{
"matchPackageNames": ["@vueuse/core"],
"automerge": true,
Expand Down
2 changes: 1 addition & 1 deletion src/components/cylc/commandMenu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default {
// Navigate to the corresponding workflow then open the log view
// (no nav occurs if already on the correct workflow page)
this.$router.push({
name: 'workspace',
name: 'Workspace',
params: {
workflowName: this.node.tokens.workflow
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/cylc/workspace/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<v-spacer class="mx-0" />

<v-btn
v-if="$route.name === 'workspace'"
v-if="$route.name === 'Workspace'"
class="add-view"
color="primary"
data-cy="add-view-btn"
Expand Down
13 changes: 5 additions & 8 deletions src/layouts/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class="overflow-auto"
:style="coreViewStyle"
>
<v-fade-transition mode="out-in">
<slot/>
</v-fade-transition>
<slot/>
</div>
</v-main>
</div>
Expand All @@ -42,6 +40,7 @@ import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { mapState } from 'vuex'
import { store } from '@/store/index'
import { allViews } from '@/views/views'
import { Alert as AlertModel } from '@/model/Alert.model'
import Alert from '@/components/core/Alert.vue'
import Drawer from '@/components/cylc/Drawer.vue'
Expand All @@ -57,17 +56,15 @@ export default {
const route = useRoute()
/**
* Views that display workflows. For these views, we do not
* want to display the default Toolbar—the Workflow view
* want to display the default Toolbar—the Workspace view
* has its own Toolbar that communicates with the Workflow
* component (e.g. the Workflow Toolbar owns a button that
* triggers the action to add a new Tree or Table View, so the events
* are passed down from the parent Workflow View).
*/
const workflowViews = [
'workspace',
'tree',
'table',
'graph',
...allViews.keys(),
'Workspace',
]
const { showNavBtn } = useNavBtn()

Expand Down
5 changes: 1 addition & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { i18n } from '@/i18n/index'
import router from '@/router/index'
import { store } from '@/store/index'
import { createVuetify } from 'vuetify'
import { createHead, VueHeadMixin } from '@unhead/vue'

import 'nprogress/css/nprogress.css'
import '@/styles/index.scss'

if (location.search) {
Expand All @@ -50,13 +50,10 @@ if (location.search) {
// Normal app start
const app = createApp(App)

app.mixin(VueHeadMixin)

app.use(store)
app.use(router)
app.use(createVuetify(vuetifyOptions))
app.use(i18n)
app.use(createHead())
app.use(ServicesPlugin)
app.use(CommandMenuPlugin)

Expand Down
9 changes: 5 additions & 4 deletions src/mixins/graphql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { mapState } from 'vuex'

/**
/*
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -17,15 +15,18 @@ import { mapState } from 'vuex'
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { mapState } from 'vuex'

/**
* A mixin that contains data used for a GraphQL subscription, such as the
* query variables.
*
* To be used in Views that are bound to VueRouter routes that contain the
* To be used in Views that are bound to Vue-Router routes that contain the
* :workflowName param.
*/
export default {
props: {
/** This is set by vue-router */
workflowName: {
type: String,
required: true
Expand Down
86 changes: 49 additions & 37 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,41 @@
* https://router.vuejs.org/en/
*/

// Lib imports
import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'
import { store } from '@/store/index'

import 'nprogress/css/nprogress.css'
import { i18n } from '@/i18n'

// Routes
import paths from './paths'
import paths from '@/router/paths'
import { store } from '@/store/index'
import { Alert } from '@/model/Alert.model'

const defaultPageTitle = i18n.global.t('App.name')

NProgress.configure({ showSpinner: false })

function route (path) {
const copy = Object.assign({}, path)
const view = copy.view
return Object.assign(copy, {
name: path.name || view,
component: (resolve) => import(
`@/views/${view}.vue`
).then(resolve)
})
function getRoute (path) {
return {
...path,
name: path.name || path.view,
component: () => import(`@/views/${path.view}.vue`)
}
}

/**
* Return the page title for a particular route.
* @param {import('vue-router').RouteLocation} route
*/
export function getPageTitle ({ meta, params }) {
const extra = meta.getTitle?.(params) || meta.title
return extra
? `${defaultPageTitle} | ${extra}`
: defaultPageTitle
}

// Create a new router
const router = createRouter({
history: createWebHashHistory(),
routes: paths.map(path => route(path)),
// .concat([{ path: '*', redirect: '/dashboard' }]),
routes: paths.map(getRoute),
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
Expand All @@ -66,34 +72,40 @@
router.beforeEach(async (to, from) => {
NProgress.start()
if (!store.state.user.user) {
try {
const user = await router.app.config.globalProperties.$userService.getUserProfile()
store.commit('user/SET_USER', user)
} catch (err) {
store.dispatch('setAlert', new Alert(err, 'error'))
}
const user = await router.app.config.globalProperties.$userService.getUserProfile()
// TODO: catch error getting user profile and redirect to static error page
store.commit('user/SET_USER', user)
}
if (!store.state.user.user.permissions.includes('read') && to.name !== 'noAuth') {
return { name: 'noAuth' }
if (!store.state.user.user.permissions?.includes('read')) {
if (to.name !== 'NoAuth') { // Avoid infinite redirect?
return { name: 'NoAuth' }
}
} else if (to.name === 'NoAuth') {
// If authorized, redirect no-auth page to home page
return { path: '/' }

Check warning on line 85 in src/router/index.js

View check run for this annotation

Codecov / codecov/patch

src/router/index.js#L85

Added line #L85 was not covered by tests
}

if (to.name) {
let title = to.name
let workflowName = null
if (to.meta.toolbar) {
// When a workflow is being displayed, we set the title to a
// different value.
title = to.params.workflowName
workflowName = to.params.workflowName
}
store.commit('app/setTitle', title)
store.commit('workflows/SET_WORKFLOW_NAME', workflowName)
store.dispatch('setAlert', null)
// Set page title:
document.title = getPageTitle(to)

// Set toolbar title:
let title = to.name
if (to.meta.toolbar) {
// When a workflow is being displayed, we set the title to a
// different value.
title = to.params.workflowName
}
store.commit('app/setTitle', title)
store.dispatch('setAlert', null)
})

router.afterEach(() => {
NProgress.done()
})

router.onError((err, to, from) => {
store.dispatch('setAlert', new Alert(err, 'error'))
NProgress.done()

Check warning on line 108 in src/router/index.js

View check run for this annotation

Codecov / codecov/patch

src/router/index.js#L107-L108

Added lines #L107 - L108 were not covered by tests
})

export default router
Loading