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 project switch on create cluster page #2047

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'vue-router'

import { useAppStore } from '@/store/app'
import { useAuthzStore } from '@/store/authz'

import { useLogger } from '@/composables/useLogger'

Expand All @@ -26,6 +27,7 @@ const zeroPoint = { left: 0, top: 0 }
export function createRouter () {
const logger = useLogger()
const appStore = useAppStore()
const authzStore = useAuthzStore()

const router = createVueRouter({
history: createWebHistory(import.meta.env.BASE_URL),
Expand All @@ -52,6 +54,10 @@ export function createRouter () {
} else {
logger.info('Navigation failure: %s', failure)
}

// Reset namespace if navigation failed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules should be updated only after successful navigation. To me this looks like a hack. I will try to find a better solution soon.

const namespace = from.params.namespace ?? from.query.namespace
authzStore.fetchRules(namespace)
}
})

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/views/GNewShoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ export default {

return next()
},
async beforeRouteUpdate (to, from, next) {
if (!this.isShootCreated && this.isShootDirty && !await this.confirmNavigation()) {
return next(false)
}

return next()
},
setup () {
const {
shootNamespace,
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/views/GNewShootEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import {
useRouter,
onBeforeRouteLeave,
onBeforeRouteUpdate,
} from 'vue-router'

import { useAppStore } from '@/store/app'
Expand Down Expand Up @@ -72,7 +73,6 @@ const appStore = useAppStore()

const {
shootNamespace,
isShootDirty,
shootManifest,
setShootManifest,
} = useShootContext()
Expand All @@ -84,6 +84,7 @@ const useProvide = (key, value) => {
const {
getEditorValue,
focusEditor,
clean,
} = useProvide(injectionKey, useShootEditor(shootManifest))

function confirmEditorNavigation () {
Expand Down Expand Up @@ -134,7 +135,16 @@ onBeforeRouteLeave(async (to, from, next) => {
if (isShootCreated.value) {
return next()
}
if (isShootDirty.value) {
if (!clean.value) {
if (!await confirmEditorNavigation()) {
focusEditor()
return next(false)
}
}
return next()
})
onBeforeRouteUpdate(async (to, from, next) => {
if (!clean.value) {
if (!await confirmEditorNavigation()) {
focusEditor()
return next(false)
Expand Down