summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/explorer/components/registry_breadcrumb.vue
blob: 666d8b042da4beebf03b39840a374caa6156794e (plain)
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
<script>
import { initial, first, last } from 'lodash';
import { GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';

export default {
  directives: { SafeHtml },
  props: {
    crumbs: {
      type: Array,
      required: true,
    },
  },
  computed: {
    rootRoute() {
      return this.$router.options.routes.find(r => r.meta.root);
    },
    isRootRoute() {
      return this.$route.name === this.rootRoute.name;
    },
    rootCrumbs() {
      return initial(this.crumbs);
    },
    divider() {
      const { classList, tagName, innerHTML } = first(this.crumbs).querySelector('svg');
      return { classList: [...classList], tagName, innerHTML };
    },
    lastCrumb() {
      const { children } = last(this.crumbs);
      const { tagName, className } = first(children);
      return {
        tagName,
        className,
        text: this.$route.meta.nameGenerator(this.$store.state),
        path: { to: this.$route.name },
      };
    },
  },
};
</script>

<template>
  <ul>
    <li
      v-for="(crumb, index) in rootCrumbs"
      :key="index"
      v-safe-html="crumb.innerHTML"
      :class="crumb.className"
    ></li>
    <li v-if="!isRootRoute">
      <router-link ref="rootRouteLink" :to="rootRoute.path">
        {{ rootRoute.meta.nameGenerator($store.state) }}
      </router-link>
      <component :is="divider.tagName" v-safe-html="divider.innerHTML" :class="divider.classList" />
    </li>
    <li>
      <component :is="lastCrumb.tagName" ref="lastCrumb" :class="lastCrumb.className">
        <router-link ref="childRouteLink" :to="lastCrumb.path">{{ lastCrumb.text }}</router-link>
      </component>
    </li>
  </ul>
</template>