-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSectionBreadcrumbs.vue
108 lines (94 loc) · 2.85 KB
/
SectionBreadcrumbs.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
<AppSection width="full" alignment="left">
<AppHeading icon="location-dot">Breadcrumbs</AppHeading>
<template v-if="breadcrumbs.length">
<span
>How you got to <AppNodeBadge :node="node" /> through the Monarch
knowledge graph:</span
>
<AppFlex direction="col">
<template v-for="(breadcrumb, index) of _breadcrumbs" :key="index">
<!-- node -->
<AppNodeBadge
v-tooltip="`Go ${-breadcrumb.back} step(s) back`"
:node="breadcrumb.node"
:style="{ opacity: breadcrumb.noEntry ? 0.5 : 1 }"
@click.prevent.capture="$router.go(breadcrumb.back)"
/>
<!-- predicate -->
<AppPredicateBadge
:association="breadcrumb.association"
:vertical="true"
:reverse="
breadcrumb.association.direction ===
AssociationDirectionEnum.incoming
"
/>
</template>
<!-- ending/current node -->
<AppNodeBadge :node="node" />
</AppFlex>
<!-- clear button -->
<AppButton
v-tooltip="'Clear breadcrumb history'"
icon="xmark"
text="Clear"
design="small"
@click="clear"
/>
</template>
<template v-else>
<p class="gray">
As you navigate to new nodes from this page, the path you traveled
through the KG will be shown here. Try clicking on a node in the
hierarchy or associations sections.
</p>
</template>
</AppSection>
</template>
<script setup lang="ts">
import { computed, watch } from "vue";
import { useRoute } from "vue-router";
import { AssociationDirectionEnum, type Node } from "@/api/model";
import AppNodeBadge from "@/components/AppNodeBadge.vue";
import AppPredicateBadge from "@/components/AppPredicateBadge.vue";
import { breadcrumbs, updateBreadcrumbs } from "@/global/breadcrumbs";
interface Props {
/** current node */
node: Node;
}
defineProps<Props>();
/** route info */
const route = useRoute();
/**
* breadcrumbs, plus computed "back" prop to tell how many history steps to go
* back when clicked
*/
const _breadcrumbs = computed(() => {
let back =
-breadcrumbs.value.filter((breadcrumb) => !breadcrumb.noEntry).length - 1;
return breadcrumbs.value.map((breadcrumb) => ({
...breadcrumb,
back: breadcrumb.noEntry ? back : ++back,
}));
});
/** keep breadcrumbs global variable in sync with history.state.breadcrumbs */
watch(() => route, updateBreadcrumbs, { immediate: true, deep: true });
/** clear breadcrumbs history */
function clear() {
/**
* confirmation warning not necessary since back button should return to
* previous state
*/
window.history.pushState({}, "");
updateBreadcrumbs();
}
</script>
<style lang="scss" scoped>
.arrow {
color: $gray;
}
.gray {
color: $dark-gray;
}
</style>