summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/components/breadcrumbs.vue
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-06-10 08:56:25 +0100
committerSean McGivern <sean@gitlab.com>2019-06-10 08:56:25 +0100
commit51713627f61b5897c0697f7574d8c3d7c3e93c41 (patch)
tree21cf681e4c976bd2012af21ba749f952624de9b5 /app/assets/javascripts/repository/components/breadcrumbs.vue
parent6a4aa3f9be8b31e5d76750d40f15f5fef2c792af (diff)
parente3072811475dcd563911a78fce85263b693d3fd6 (diff)
downloadgitlab-ce-51713627f61b5897c0697f7574d8c3d7c3e93c41.tar.gz
Merge remote-tracking branch 'origin/master' into patch-56
Diffstat (limited to 'app/assets/javascripts/repository/components/breadcrumbs.vue')
-rw-r--r--app/assets/javascripts/repository/components/breadcrumbs.vue61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/assets/javascripts/repository/components/breadcrumbs.vue b/app/assets/javascripts/repository/components/breadcrumbs.vue
new file mode 100644
index 00000000000..6eca015036f
--- /dev/null
+++ b/app/assets/javascripts/repository/components/breadcrumbs.vue
@@ -0,0 +1,61 @@
+<script>
+import getRefMixin from '../mixins/get_ref';
+import getProjectShortPath from '../queries/getProjectShortPath.graphql';
+
+export default {
+ apollo: {
+ projectShortPath: {
+ query: getProjectShortPath,
+ },
+ },
+ mixins: [getRefMixin],
+ props: {
+ currentPath: {
+ type: String,
+ required: false,
+ default: '/',
+ },
+ },
+ data() {
+ return {
+ projectShortPath: '',
+ };
+ },
+ computed: {
+ pathLinks() {
+ return this.currentPath
+ .split('/')
+ .filter(p => p !== '')
+ .reduce(
+ (acc, name, i) => {
+ const path = `${i > 0 ? acc[i].path : ''}/${name}`;
+
+ return acc.concat({
+ name,
+ path,
+ to: `/tree/${this.ref}${path}`,
+ });
+ },
+ [{ name: this.projectShortPath, path: '/', to: `/tree/${this.ref}` }],
+ );
+ },
+ },
+ methods: {
+ isLast(i) {
+ return i === this.pathLinks.length - 1;
+ },
+ },
+};
+</script>
+
+<template>
+ <nav :aria-label="__('Files breadcrumb')">
+ <ol class="breadcrumb repo-breadcrumb">
+ <li v-for="(link, i) in pathLinks" :key="i" class="breadcrumb-item">
+ <router-link :to="link.to" :aria-current="isLast(i) ? 'page' : null">
+ {{ link.name }}
+ </router-link>
+ </li>
+ </ol>
+ </nav>
+</template>