diff options
Diffstat (limited to 'app/assets/javascripts/repository/index.js')
-rw-r--r-- | app/assets/javascripts/repository/index.js | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/app/assets/javascripts/repository/index.js b/app/assets/javascripts/repository/index.js index 7f72524b6fe..a62b2d96c54 100644 --- a/app/assets/javascripts/repository/index.js +++ b/app/assets/javascripts/repository/index.js @@ -1,16 +1,17 @@ import Vue from 'vue'; -import { escapeFileUrl, joinPaths, webIDEUrl } from '../lib/utils/url_utility'; +import PathLastCommitQuery from 'shared_queries/repository/path_last_commit.query.graphql'; +import { escapeFileUrl } from '../lib/utils/url_utility'; import createRouter from './router'; import App from './components/app.vue'; import Breadcrumbs from './components/breadcrumbs.vue'; import LastCommit from './components/last_commit.vue'; import TreeActionLink from './components/tree_action_link.vue'; -import WebIdeLink from '~/vue_shared/components/web_ide_link.vue'; +import initWebIdeLink from '~/pages/projects/shared/web_ide_link'; import DirectoryDownloadLinks from './components/directory_download_links.vue'; import apolloProvider from './graphql'; import { setTitle } from './utils/title'; import { updateFormAction } from './utils/dom'; -import { convertObjectPropsToCamelCase, parseBoolean } from '../lib/utils/common_utils'; +import { parseBoolean } from '../lib/utils/common_utils'; import { __ } from '../locale'; export default function setupVueRepositoryList() { @@ -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; @@ -110,29 +138,7 @@ export default function setupVueRepositoryList() { }, }); - const webIdeLinkEl = document.getElementById('js-tree-web-ide-link'); - - if (webIdeLinkEl) { - const { ideBasePath, ...options } = convertObjectPropsToCamelCase( - JSON.parse(webIdeLinkEl.dataset.options), - ); - - // eslint-disable-next-line no-new - new Vue({ - el: webIdeLinkEl, - router, - render(h) { - return h(WebIdeLink, { - props: { - webIdeUrl: webIDEUrl( - joinPaths('/', ideBasePath, 'edit', ref, '-', this.$route.params.path || '', '/'), - ), - ...options, - }, - }); - }, - }); - } + initWebIdeLink({ el: document.getElementById('js-tree-web-ide-link'), router }); const directoryDownloadLinks = document.getElementById('js-directory-downloads'); |