-
Notifications
You must be signed in to change notification settings - Fork 164
Updated Auto-Redirect Flow for Segments #1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba100da
CR-29590
olegt-codefresh ac333f4
After review fix
olegt-codefresh 73b83c4
swap commandbarSegment values for correct configuration
olegt-codefresh 90032c1
CR-29589
olegt-codefresh f85350c
docs: Exclude gitops collection pages from Sitemap.xml
olegt-codefresh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ defaults: | |
type: gitops | ||
values: | ||
layout: gitops | ||
sitemap: false | ||
toc: true | ||
wide: true | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,157 @@ | ||
const enterpriseDocumentationCookie = "cfdoctype=enterprise"; | ||
const ARGOHUB_MAIN_PATH = `/${SITE_GITOPS_COLLECTION}/`; | ||
const enterpriseDocTypeLockKey = "enterpriseDocTypeLock"; | ||
const GITOPS_DOC_COOKIE = 'cfdoctype=gitops' | ||
const IS_GITOPS_DOC_COOKIE_SET = document.cookie.includes(GITOPS_DOC_COOKIE) | ||
|
||
function checkIfEnterpriseDocumentationCookieSet() { | ||
return document.cookie.includes(enterpriseDocumentationCookie); | ||
} | ||
handleRedirect() | ||
|
||
async function getArgoHubRedirectURL(currentPath) { | ||
currentPath = currentPath.replace(SITE_BASE_URL, ""); | ||
currentPath = currentPath.replace(SITE_BASE_URL, '') | ||
|
||
const redirectMap = await fetchRedirectMap(); | ||
const redirectMap = await fetchRedirectMap() | ||
|
||
const newPath = redirectMap[currentPath]; | ||
if (!newPath) return null; | ||
const newPath = redirectMap[currentPath] | ||
if (!newPath) return null | ||
|
||
const newURL = | ||
newPath === ARGOHUB_MAIN_PATH | ||
newPath === `/${SITE_GITOPS_COLLECTION}/` | ||
? `${location.href}${SITE_GITOPS_COLLECTION}` | ||
: location.href.replace(currentPath, newPath); | ||
: location.href.replace(currentPath, newPath) | ||
|
||
return newURL; | ||
return newURL | ||
} | ||
|
||
async function handleRedirect() { | ||
if (shouldSkipRedirect()) return; | ||
if (SITE_IS_GITOPS_COLLECTION || !IS_GITOPS_DOC_COOKIE_SET) return | ||
|
||
const argoHubRedirectURL = await getArgoHubRedirectURL(location.pathname); | ||
if (!argoHubRedirectURL) return; | ||
const argoHubRedirectURL = await getArgoHubRedirectURL(location.pathname) | ||
if (!argoHubRedirectURL) return | ||
|
||
location.href = argoHubRedirectURL; | ||
location.href = argoHubRedirectURL | ||
} | ||
|
||
async function fetchRedirectMap() { | ||
const response = await fetch( | ||
`${SITE_BASE_URL}/assets/js/src/argohub-redirect-mapping.json` | ||
); | ||
const response = await fetch(`${SITE_BASE_URL}/assets/js/src/argohub-redirect-mapping.json`) | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch the collections redirect map."); | ||
throw new Error('Failed to fetch the collections redirect map.') | ||
} | ||
return response.json() | ||
} | ||
|
||
function setGitOpsDocumentationCookie() { | ||
const maxAge = 2592000 | ||
configureGitOpsDocumentationCookie(maxAge) | ||
} | ||
|
||
function removeGitOpsDocumentationCookie() { | ||
configureGitOpsDocumentationCookie(0) | ||
} | ||
|
||
function configureGitOpsDocumentationCookie(maxAge) { | ||
let cookie = `${GITOPS_DOC_COOKIE}; Max-Age=${maxAge}; Path=/; SameSite=Strict` | ||
|
||
if (location.protocol === 'https:') { | ||
cookie += '; Secure' | ||
} | ||
|
||
if (location.hostname.endsWith('.codefresh.io')) { | ||
cookie += '; Domain=.codefresh.io' | ||
} | ||
|
||
document.cookie = cookie | ||
} | ||
|
||
function toggleSegmentDropdown() { | ||
const select = document.querySelector('.custom-select') | ||
select.classList.toggle('open') | ||
} | ||
|
||
function handleDropdownKeydown(event) { | ||
const select = document.querySelector('.custom-select') | ||
const options = select.querySelectorAll('.option') | ||
const isOpen = select.classList.contains('open') | ||
|
||
switch (event.key) { | ||
case 'Enter': | ||
case ' ': | ||
event.preventDefault() | ||
toggleSegmentDropdown() | ||
break | ||
case 'ArrowDown': | ||
event.preventDefault() | ||
if (!isOpen) toggleSegmentDropdown() | ||
options[0].focus() | ||
break | ||
case 'Escape': | ||
if (isOpen) toggleSegmentDropdown() | ||
break | ||
} | ||
return response.json(); | ||
} | ||
|
||
function isEnterpriseLockPresent() { | ||
const enterpriseDocTypeLock = localStorage.getItem(enterpriseDocTypeLockKey); | ||
return !!enterpriseDocTypeLock; | ||
function handleOptionKeydown(event, option, selectedValue) { | ||
const select = document.querySelector('.custom-select') | ||
const options = select.querySelectorAll('.option') | ||
const currentIndex = Array.from(options).indexOf(option) | ||
|
||
switch (event.key) { | ||
case 'Enter': | ||
case ' ': | ||
event.preventDefault() | ||
selectSegmentOption(option, selectedValue) | ||
break | ||
case 'ArrowDown': | ||
event.preventDefault() | ||
if (currentIndex < options.length - 1) { | ||
options[currentIndex + 1].focus() | ||
} | ||
break | ||
case 'ArrowUp': | ||
event.preventDefault() | ||
if (currentIndex > 0) { | ||
options[currentIndex - 1].focus() | ||
} | ||
break | ||
case 'Escape': | ||
select.classList.remove('open') | ||
select.querySelector('.select-display').focus() | ||
break | ||
} | ||
} | ||
|
||
function shouldSkipRedirect() { | ||
return true; // Redirect temporarily disabled. Will be re-enabled with a new cookie-based mechanism. | ||
// return ( | ||
// isEnterpriseLockPresent() || | ||
// SITE_IS_GITOPS_COLLECTION || | ||
// checkIfEnterpriseDocumentationCookieSet() | ||
// ); | ||
async function selectSegmentOption(option, selectedValue) { | ||
const selectDisplay = document.querySelector('.select-display') | ||
|
||
selectDisplay.textContent = option.textContent | ||
|
||
const redirectMap = await fetchRedirectMap() | ||
|
||
const pathname = window.location.pathname | ||
const currentPath = pathname.replace(SITE_BASE_URL, '') | ||
|
||
if (selectedValue === 'enterprise') { | ||
removeGitOpsDocumentationCookie() | ||
|
||
const enterprisePath = Object.keys(redirectMap).find((key) => redirectMap[key] === currentPath) | ||
|
||
if (enterprisePath) { | ||
window.location.href = `${SITE_BASE_URL}${enterprisePath}` | ||
} else { | ||
window.location.href = `${SITE_BASE_URL}/` | ||
} | ||
} else if (selectedValue === 'gitops') { | ||
setGitOpsDocumentationCookie() | ||
|
||
const gitOpsPath = redirectMap[currentPath] | ||
|
||
if (gitOpsPath) { | ||
window.location.href = `${SITE_BASE_URL}${gitOpsPath}` | ||
} else { | ||
window.location.href = `${SITE_BASE_URL}/${SITE_GITOPS_COLLECTION}/` | ||
} | ||
} | ||
} | ||
|
||
handleRedirect(); | ||
document.addEventListener('click', (e) => { | ||
const select = document.querySelector('.custom-select') | ||
if (!select.contains(e.target)) { | ||
select.classList.remove('open') | ||
} | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if gitops cookie is removed, but user is trying to reach gitops page, we will not redirect him to enterprise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this stage, we will maintain a one-way redirect and extend it if necessary.