Skip to content

Commit

Permalink
fix(routing): define default previous views for go-back-button
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jul 7, 2021
1 parent 4d6ec14 commit b73b021
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 43 deletions.
27 changes: 0 additions & 27 deletions src/components/generic/go-back-button/GoBackButton.vue

This file was deleted.

23 changes: 8 additions & 15 deletions src/components/specific/app/app-breadcrumb/AppBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
import { useRoute } from "vue-router";
import { routeNames } from "@/router";
// Components
import GoBackButton from "@/components/generic/go-back-button/GoBackButton";
import GoBackButton from "@/components/specific/app/go-back-button/GoBackButton";
import BreadcrumbGroupSelector from "./breadcrumb-group-selector/BreadcrumbGroupSelector";
import BreadcrumbProjectSelector from "./breadcrumb-project-selector/BreadcrumbProjectSelector";
import BreadcrumbSpaceSelector from "./breadcrumb-space-selector/BreadcrumbSpaceSelector";
const BREADCRUMB_COMPONENTS = {
[routeNames.spaceBoard]: "BreadcrumbSpaceSelector",
[routeNames.projectBoard]: "BreadcrumbProjectSelector",
[routeNames.groupBoard]: "BreadcrumbGroupSelector"
};
export default {
components: {
GoBackButton,
Expand All @@ -27,21 +33,8 @@ export default {
setup() {
const route = useRoute();
let breadcrumb;
switch (route.name) {
case routeNames.spaceBoard:
breadcrumb = "BreadcrumbSpaceSelector";
break;
case routeNames.projectBoard:
breadcrumb = "BreadcrumbProjectSelector";
break;
case routeNames.groupBoard:
breadcrumb = "BreadcrumbGroupSelector";
break;
}
return {
breadcrumb
breadcrumb: BREADCRUMB_COMPONENTS[route.name]
};
}
};
Expand Down
62 changes: 62 additions & 0 deletions src/components/specific/app/go-back-button/GoBackButton.vue
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>
2 changes: 1 addition & 1 deletion src/views/model-viewer/ModelViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useAuth } from "@/state/auth";
import { useSpaces } from "@/state/spaces";
// Components
import AppSlotContent from "@/components/generic/app-slot-content/AppSlotContent";
import GoBackButton from "@/components/generic/go-back-button/GoBackButton";
import GoBackButton from "@/components/specific/app/go-back-button/GoBackButton";
const availablePlugins = {
bimobject: "https://unpkg.com/@bimdata/bimobject-viewer-plugin@1.0.0",
Expand Down

0 comments on commit b73b021

Please sign in to comment.