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

[UXE-6389] Fix: disable browser back in the edge app config page #2180

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
9 changes: 9 additions & 0 deletions src/helpers/browser-back-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const disabledBackButton = () => {
window.location.hash = 'no-back-button'

window.location.hash = 'Again-No-back-button'

window.onhashchange = function () {
window.location.hash = 'no-back-button'
}
}
4 changes: 3 additions & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import FILTERS_RULES from './real-time-filters-rules'
import { openGraphQlPlayground } from './open-graphql-playground.js'
import { eventsPlaygroundOpener } from './events-playground-opener'
import { setRedirectRoute, getRedirectRoute } from './login-redirect-manager'
import { disabledBackButton } from './browser-back-button'

export {
InviteSession,
Expand Down Expand Up @@ -81,5 +82,6 @@ export {
openGraphQlPlayground,
eventsPlaygroundOpener,
setRedirectRoute,
getRedirectRoute
getRedirectRoute,
disabledBackButton
}
7 changes: 6 additions & 1 deletion src/templates/dialog-unsaved-block/index.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script setup>
import { computed, ref, watch, inject } from 'vue'
import { computed, ref, watch, inject, onMounted } from 'vue'
import PrimeDialog from 'primevue/dialog'
import PrimeButton from 'primevue/button'
import { onBeforeRouteLeave, useRouter } from 'vue-router'
import { disabledBackButton } from '@/helpers'

defineOptions({ name: 'dialog-unsaved-block' })
const emit = defineEmits(['update:visible'])
Expand Down Expand Up @@ -114,6 +115,10 @@
watch(formDrawerHasUpdated, () => {
openDialogUnsaved(true)
})

onMounted(() => {
disabledBackButton()
})
</script>

<template>
Expand Down
28 changes: 28 additions & 0 deletions src/tests/helpers/browser-back-button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { afterAll, describe, expect, it, vi } from 'vitest'
import { disabledBackButton } from '@/helpers/browser-back-button'

vi.stubGlobal('window', {
location: {
hash: ''
},
onhashchange: null
})

describe('disabledBackButton', () => {
afterAll(() => {
vi.unstubAllGlobals()
})
it('should update window.location.hash to "Again-No-back-button"', () => {
disabledBackButton()
expect(window.location.hash).toBe('Again-No-back-button')
})

it('should reset window.location.hash to "no-back-button" on hash change', () => {
disabledBackButton()

window.location.hash = 'some-other-hash'
window.onhashchange()

expect(window.location.hash).toBe('no-back-button')
})
})
Loading