-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(routing): define default previous views for go-back-button
- Loading branch information
1 parent
4d6ec14
commit b73b021
Showing
5 changed files
with
71 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
src/components/specific/app/go-back-button/GoBackButton.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<BIMDataButton | ||
data-test="btn-back" | ||
class="go-back-button" | ||
ghost | ||
radius | ||
@click="goBack" | ||
> | ||
<BIMDataIcon class="go-back-button__icon" name="arrow" size="xxs" /> | ||
<span>{{ $t("GoBackButton.text") }}</span> | ||
</BIMDataButton> | ||
</template> | ||
|
||
<script> | ||
import { useRoute, useRouter } from "vue-router"; | ||
import { routeNames } from "@/router"; | ||
// Components | ||
import BIMDataButton from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataButton.js"; | ||
import BIMDataIcon from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataIcon.js"; | ||
const HAS_PREVIOUS_STORAGE_KEY = "has-previous"; | ||
const DEFAULT_PREVIOUS_VIEWS = { | ||
[routeNames.userSpaces]: routeNames.dashboard, | ||
[routeNames.userProjects]: routeNames.dashboard, | ||
[routeNames.spaceBoard]: routeNames.dashboard, | ||
[routeNames.projectBoard]: routeNames.spaceBoard, | ||
[routeNames.modelViewer]: routeNames.projectBoard, | ||
[routeNames.projectGroups]: routeNames.projectBoard, | ||
[routeNames.groupBoard]: routeNames.projectGroups | ||
}; | ||
export default { | ||
components: { | ||
BIMDataButton, | ||
BIMDataIcon | ||
}, | ||
setup() { | ||
const router = useRouter(); | ||
const route = useRoute(); | ||
const goBack = () => { | ||
const hasPrevious = sessionStorage.getItem(HAS_PREVIOUS_STORAGE_KEY); | ||
if (hasPrevious) { | ||
router.back(); | ||
} else { | ||
sessionStorage.setItem(HAS_PREVIOUS_STORAGE_KEY, "yes"); | ||
router.push({ | ||
name: DEFAULT_PREVIOUS_VIEWS[route.name], | ||
params: route.params | ||
}); | ||
} | ||
}; | ||
return { | ||
goBack | ||
}; | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss" src="./GoBackButton.scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters