diff options
Diffstat (limited to 'app/assets/javascripts/lib/utils/url_utility.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/url_utility.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js index bca0e45d98d..1c22d21a313 100644 --- a/app/assets/javascripts/lib/utils/url_utility.js +++ b/app/assets/javascripts/lib/utils/url_utility.js @@ -1,3 +1,5 @@ +export const DASH_SCOPE = '-'; + const PATH_SEPARATOR = '/'; const PATH_SEPARATOR_LEADING_REGEX = new RegExp(`^${PATH_SEPARATOR}+`); const PATH_SEPARATOR_ENDING_REGEX = new RegExp(`${PATH_SEPARATOR}+$`); @@ -588,3 +590,30 @@ export function isSameOriginUrl(url) { return false; } } + +/** + * Returns a URL to WebIDE considering the current user's position in + * repository's tree. If not MR `iid` has been passed, the URL is fetched + * from the global `gl.webIDEPath`. + * + * @param sourceProjectFullPath Source project's full path. Used in MRs + * @param targetProjectFullPath Target project's full path. Used in MRs + * @param iid MR iid + * @returns {string} + */ + +export function constructWebIDEPath({ + sourceProjectFullPath, + targetProjectFullPath = '', + iid, +} = {}) { + if (!iid || !sourceProjectFullPath) { + return window.gl?.webIDEPath; + } + return mergeUrlParams( + { + target_project: sourceProjectFullPath !== targetProjectFullPath ? targetProjectFullPath : '', + }, + webIDEUrl(`/${sourceProjectFullPath}/merge_requests/${iid}`), + ); +} |