diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-21 18:14:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-21 18:14:09 +0300 |
commit | e87220d9c1a7878a4cb2bb86554c5951371e340b (patch) | |
tree | fa8d81c8463cf97362f441f81dfef890df34ebbd /app/assets/javascripts/blame | |
parent | c0a3d287c0d613cc439a31683d06dd70f3411f8c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blame')
-rw-r--r-- | app/assets/javascripts/blame/blame_redirect.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/assets/javascripts/blame/blame_redirect.js b/app/assets/javascripts/blame/blame_redirect.js new file mode 100644 index 00000000000..155e2a3a2cd --- /dev/null +++ b/app/assets/javascripts/blame/blame_redirect.js @@ -0,0 +1,23 @@ +import { setUrlParams } from '~/lib/utils/url_utility'; +import { createAlert } from '~/flash'; +import { __ } from '~/locale'; + +export default function redirectToCorrectBlamePage() { + const { hash } = window.location; + const linesPerPage = parseInt(document.querySelector('.js-per-page').dataset.perPage, 10); + const params = new URLSearchParams(window.location.search); + const currentPage = parseInt(params.get('page'), 10); + const isPaginationDisabled = params.get('no_pagination'); + if (hash && linesPerPage && !isPaginationDisabled) { + const lineNumber = parseInt(hash.split('#L')[1], 10); + const pageToRedirect = Math.ceil(lineNumber / linesPerPage); + const isRedirectNeeded = + (pageToRedirect > 1 && pageToRedirect !== currentPage) || pageToRedirect < currentPage; + if (isRedirectNeeded) { + createAlert({ + message: __('Please wait a few moments while we load the file history for this line.'), + }); + window.location.href = setUrlParams({ page: pageToRedirect }); + } + } +} |