diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-11 09:11:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-11 09:11:25 +0300 |
commit | fd92c8afee165b1da0f0d2386fdf4382bf6d7ab2 (patch) | |
tree | d4d7cc642a6de36c59adf6375afabdfdc0630fe0 /app/assets | |
parent | 676396cd60c28640534bc56a1183fbf9d179ec47 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets')
4 files changed, 28 insertions, 8 deletions
diff --git a/app/assets/javascripts/pages/projects/find_file/ref_switcher/index.js b/app/assets/javascripts/pages/projects/find_file/ref_switcher/index.js index 9a3bb25de70..ffd4ef9efbb 100644 --- a/app/assets/javascripts/pages/projects/find_file/ref_switcher/index.js +++ b/app/assets/javascripts/pages/projects/find_file/ref_switcher/index.js @@ -2,7 +2,7 @@ import Vue from 'vue'; import { s__ } from '~/locale'; import Translate from '~/vue_shared/translate'; import RefSelector from '~/ref/components/ref_selector.vue'; -import { visitUrl } from '~/lib/utils/url_utility'; +import { joinPaths, visitUrl } from '~/lib/utils/url_utility'; import { generateRefDestinationPath } from './ref_switcher_utils'; Vue.use(Translate); @@ -13,7 +13,7 @@ export default () => { const el = document.getElementById('js-blob-ref-switcher'); if (!el) return false; - const { projectId, ref, namespace } = el.dataset; + const { projectId, ref, refType, namespace } = el.dataset; return new Vue({ el, @@ -21,7 +21,8 @@ export default () => { return createElement(RefSelector, { props: { projectId, - value: ref, + value: refType ? joinPaths('refs', refType, ref) : ref, + useSymbolicRefNames: Boolean(refType), translations: { dropdownHeader: REF_SWITCH_HEADER, searchPlaceholder: REF_SWITCH_HEADER, diff --git a/app/assets/javascripts/pages/projects/find_file/ref_switcher/ref_switcher_utils.js b/app/assets/javascripts/pages/projects/find_file/ref_switcher/ref_switcher_utils.js index 5fecd024f1a..21a30f1c54b 100644 --- a/app/assets/javascripts/pages/projects/find_file/ref_switcher/ref_switcher_utils.js +++ b/app/assets/javascripts/pages/projects/find_file/ref_switcher/ref_switcher_utils.js @@ -10,19 +10,32 @@ export function generateRefDestinationPath(selectedRef, namespace) { return window.location.href; } + let refType = null; const { pathname } = window.location; const encodedHash = '%23'; const [projectRootPath] = pathname.split(namespace); + let actualRef = selectedRef; + + const matches = selectedRef.match(/^refs\/(heads|tags)\/(.+)/); + if (matches) { + [, refType, actualRef] = matches; + } const destinationPath = joinPaths( projectRootPath, namespace, - encodeURI(selectedRef).replace(/#/g, encodedHash), + encodeURI(actualRef).replace(/#/g, encodedHash), ); const newURL = new URL(window.location); newURL.pathname = destinationPath; + if (refType) { + newURL.searchParams.set('ref_type', refType.toLowerCase()); + } else { + newURL.searchParams.delete('ref_type'); + } + return newURL.href; } diff --git a/app/assets/javascripts/pages/projects/find_file/show/index.js b/app/assets/javascripts/pages/projects/find_file/show/index.js index e207df2434b..22c21430e8b 100644 --- a/app/assets/javascripts/pages/projects/find_file/show/index.js +++ b/app/assets/javascripts/pages/projects/find_file/show/index.js @@ -6,8 +6,9 @@ import InitBlobRefSwitcher from '../ref_switcher'; InitBlobRefSwitcher(); const findElement = document.querySelector('.js-file-finder'); const projectFindFile = new ProjectFindFile($('.file-finder-holder'), { - url: findElement.dataset.fileFindUrl, treeUrl: findElement.dataset.findTreeUrl, blobUrlTemplate: findElement.dataset.blobUrlTemplate, + refType: findElement.dataset.refType, }); +projectFindFile.load(findElement.dataset.fileFindUrl); new ShortcutsFindFile(projectFindFile); // eslint-disable-line no-new diff --git a/app/assets/javascripts/projects/project_find_file.js b/app/assets/javascripts/projects/project_find_file.js index a8b884a68a0..711a8278e07 100644 --- a/app/assets/javascripts/projects/project_find_file.js +++ b/app/assets/javascripts/projects/project_find_file.js @@ -50,8 +50,6 @@ export default class ProjectFindFile { this.initEvent(); // focus text input box this.inputElement.focus(); - // load file list - this.load(this.options.url); } initEvent() { @@ -110,7 +108,14 @@ export default class ProjectFindFile { if (searchText) { matches = fuzzaldrinPlus.match(filePath, searchText); } - const blobItemUrl = joinPaths(this.options.blobUrlTemplate, escapeFileUrl(filePath)); + + let blobItemUrl = joinPaths(this.options.blobUrlTemplate, escapeFileUrl(filePath)); + + if (this.options.refType) { + const blobUrlObject = new URL(blobItemUrl, window.location.origin); + blobUrlObject.searchParams.append('ref_type', this.options.refType); + blobItemUrl = blobUrlObject.toString(); + } const html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl); results.push(this.element.find('.tree-table > tbody').append(html)); } |