diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-13 12:08:41 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-13 12:08:41 +0000 |
commit | 6e91fbf77476011a7fd86ca3467aad6d7b110ff3 (patch) | |
tree | cace6db4e7ebef8b15a6a7fc8fbe8ff0d89bea90 /app/assets/javascripts/repository | |
parent | 15ae4a8da83661f2b714d804721001a53b354d28 (diff) | |
download | gitlab-ce-6e91fbf77476011a7fd86ca3467aad6d7b110ff3.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/repository')
3 files changed, 43 insertions, 53 deletions
diff --git a/app/assets/javascripts/repository/components/last_commit.vue b/app/assets/javascripts/repository/components/last_commit.vue index 3e87833f7f5..0e2bccfabdd 100644 --- a/app/assets/javascripts/repository/components/last_commit.vue +++ b/app/assets/javascripts/repository/components/last_commit.vue @@ -2,6 +2,7 @@ /* eslint-disable vue/no-v-html */ import { GlTooltipDirective, GlLink, GlButton, GlButtonGroup, GlLoadingIcon } from '@gitlab/ui'; import defaultAvatarUrl from 'images/no_avatar.png'; +import pathLastCommitQuery from 'shared_queries/repository/path_last_commit.query.graphql'; import { sprintf, s__ } from '~/locale'; import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import TimeagoTooltip from '../../vue_shared/components/time_ago_tooltip.vue'; @@ -9,7 +10,6 @@ import CiIcon from '../../vue_shared/components/ci_icon.vue'; import ClipboardButton from '../../vue_shared/components/clipboard_button.vue'; import getRefMixin from '../mixins/get_ref'; import projectPathQuery from '../queries/project_path.query.graphql'; -import pathLastCommitQuery from '../queries/path_last_commit.query.graphql'; export default { components: { diff --git a/app/assets/javascripts/repository/index.js b/app/assets/javascripts/repository/index.js index 65da8f70b40..0e4d724e949 100644 --- a/app/assets/javascripts/repository/index.js +++ b/app/assets/javascripts/repository/index.js @@ -1,4 +1,5 @@ import Vue from 'vue'; +import PathLastCommitQuery from 'shared_queries/repository/path_last_commit.query.graphql'; import { escapeFileUrl, joinPaths, webIDEUrl } from '../lib/utils/url_utility'; import createRouter from './router'; import App from './components/app.vue'; @@ -18,6 +19,10 @@ export default function setupVueRepositoryList() { const { dataset } = el; const { projectPath, projectShortPath, ref, escapedRef, fullName } = dataset; const router = createRouter(projectPath, escapedRef); + const pathRegex = /-\/tree\/[^/]+\/(.+$)/; + const matches = window.location.href.match(pathRegex); + + const currentRoutePath = matches ? matches[1] : ''; apolloProvider.clients.defaultClient.cache.writeData({ data: { @@ -29,6 +34,43 @@ export default function setupVueRepositoryList() { }, }); + const initLastCommitApp = () => + new Vue({ + el: document.getElementById('js-last-commit'), + router, + apolloProvider, + render(h) { + return h(LastCommit, { + props: { + currentPath: this.$route.params.path, + }, + }); + }, + }); + + if (window.gl.startup_graphql_calls) { + const query = window.gl.startup_graphql_calls.find( + call => call.operationName === 'pathLastCommit', + ); + query.fetchCall + .then(res => res.json()) + .then(res => { + apolloProvider.clients.defaultClient.writeQuery({ + query: PathLastCommitQuery, + data: res.data, + variables: { + projectPath, + ref, + path: currentRoutePath, + }, + }); + }) + .catch(() => {}) + .finally(() => initLastCommitApp()); + } else { + initLastCommitApp(); + } + router.afterEach(({ params: { path } }) => { setTitle(path, ref, fullName); }); @@ -77,20 +119,6 @@ export default function setupVueRepositoryList() { }); } - // eslint-disable-next-line no-new - new Vue({ - el: document.getElementById('js-last-commit'), - router, - apolloProvider, - render(h) { - return h(LastCommit, { - props: { - currentPath: this.$route.params.path, - }, - }); - }, - }); - const treeHistoryLinkEl = document.getElementById('js-tree-history-link'); const { historyLink } = treeHistoryLinkEl.dataset; diff --git a/app/assets/javascripts/repository/queries/path_last_commit.query.graphql b/app/assets/javascripts/repository/queries/path_last_commit.query.graphql deleted file mode 100644 index 51f3f790a5d..00000000000 --- a/app/assets/javascripts/repository/queries/path_last_commit.query.graphql +++ /dev/null @@ -1,38 +0,0 @@ -query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) { - project(fullPath: $projectPath) { - repository { - tree(path: $path, ref: $ref) { - lastCommit { - sha - title - titleHtml - descriptionHtml - message - webPath - authoredDate - authorName - authorGravatar - author { - name - avatarUrl - webPath - } - signatureHtml - pipelines(ref: $ref, first: 1) { - edges { - node { - detailedStatus { - detailsPath - icon - tooltip - text - group - } - } - } - } - } - } - } - } -} |