generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 178
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
MWPW-146930 - Rollout tool plugin #3463
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d08e5d7
Initial commit for rollout plugin
sabyamon 7477120
Refactoring
sabyamon 9dd79fc
Update rollout plugin based on new requirement and locv3
sabyamon 885509b
Refactoring and adding tests
sabyamon af921e1
Adding check for non langstore urls
sabyamon 3d78323
Adding warning message
sabyamon 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 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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* Rollout Modal styling */ | ||
.modal { | ||
padding: 20px; | ||
max-width: 500px; | ||
margin: 40px auto; | ||
text-align: center; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
.modal.warning { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 15px; | ||
background-color: #fff3e0; | ||
border: 1px solid #ffb74d; | ||
border-radius: 8px; | ||
padding: 15px 20px; | ||
text-align: left; | ||
} | ||
|
||
.warning-icon { | ||
width: 24px; | ||
height: 24px; | ||
background-color: #f57c00; | ||
border-radius: 50%; | ||
position: relative; | ||
} | ||
|
||
.warning-icon:before { | ||
content: "!"; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
color: white; | ||
font-weight: bold; | ||
font-size: 16px; | ||
} | ||
|
||
.warning-text { | ||
color: #e65100; | ||
font-size: 20px; | ||
font-weight: 800; | ||
} | ||
|
||
.warning-text-sub { | ||
font-size: 14px; | ||
font-weight: 500; | ||
} | ||
|
||
.env-label { | ||
font-weight: 600; | ||
margin-bottom: 10px; | ||
color: #333; | ||
font-size: 16px; | ||
} | ||
|
||
.radio-group { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
margin: 10px 0; | ||
} | ||
|
||
.radio-group label { | ||
display: flex; | ||
align-items: center; | ||
font-size: 14px; | ||
font-weight: 500; | ||
padding: 8px 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 5px; | ||
background-color: #fff; | ||
cursor: pointer; | ||
transition: all 0.2s ease; | ||
box-shadow: 0 2px 4px rgb(0 0 0 / 5%); | ||
} | ||
|
||
.radio-group label:hover { | ||
border-color: #0078d4; | ||
background-color: #f0f8ff; | ||
box-shadow: 0 3px 6px rgb(0 0 0 / 10%); | ||
} | ||
|
||
.radio-group input[type="radio"] { | ||
margin-right: 8px; | ||
accent-color: #0078d4; | ||
width: 16px; | ||
height: 16px; | ||
} | ||
|
||
.button-group { | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 15px; | ||
} | ||
|
||
.rollout-btn { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 8px 16px; | ||
font-size: 14px; | ||
font-weight: bold; | ||
color: #fff; | ||
background: linear-gradient(135deg, #0078d4, #005a9e); | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease; | ||
box-shadow: 0 3px 6px rgb(0 0 0 / 10%); | ||
} | ||
|
||
.rollout-btn:hover { | ||
background: linear-gradient(135deg, #005a9e, #003e6b); | ||
transform: translateY(-2px); | ||
box-shadow: 0 4px 8px rgb(0 0 0 / 15%); | ||
} | ||
|
||
.rollout-btn:active { | ||
background: linear-gradient(135deg, #004080, #002a57); | ||
transform: translateY(1px); | ||
box-shadow: 0 2px 4px rgb(0 0 0 / 10%); | ||
} | ||
|
||
.rollout-btn:disabled { | ||
background-color: #ccc; | ||
color: #666; | ||
cursor: not-allowed; | ||
box-shadow: none; | ||
} | ||
|
||
.rollout-btn-text { | ||
font-size: 14px; | ||
font-weight: normal; | ||
color: inherit; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,201 @@ | ||
import { createTag } from '../../utils/utils.js'; | ||
|
||
const urlData = { | ||
urlBranch: '', | ||
urlRepo: '', | ||
urlOwner: '', | ||
urlPathRemainder: '', | ||
currentPageLang: '', | ||
referrer: '', | ||
host: '', | ||
project: '', | ||
}; | ||
|
||
/** | ||
* Extracts language code from URL path | ||
* @param {string} url - URL to parse | ||
* @returns {string|null} Language code or null if invalid | ||
*/ | ||
const getLanguageCode = (url) => { | ||
if (!url) return null; | ||
|
||
try { | ||
const pathSegments = new URL(url).pathname.split('/').filter(Boolean); | ||
if (pathSegments[0] !== 'langstore') return null; | ||
|
||
const langPattern = /^[a-z]{2,3}(-[A-Za-z]{4})?(-[A-Za-z0-9]{2,3})?$/; | ||
return langPattern.test(pathSegments[1]) ? pathSegments[1] : null; | ||
} catch (err) { | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Parses URL and sets URL data | ||
* @param {string} url - URL to parse | ||
* @param {boolean} allowEmptyPaths - Whether to allow empty paths | ||
* @returns {Object|null} URL data object or null if invalid | ||
*/ | ||
const setUrlData = (url, allowEmptyPaths = false) => { | ||
if (!url) return null; | ||
|
||
try { | ||
const urlParts = url.split('--'); | ||
if (urlParts.length !== 3) { | ||
return null; | ||
} | ||
|
||
const hlxPageIndex = urlParts[2].indexOf('.hlx.page'); | ||
const aemPageIndex = urlParts[2].indexOf('.aem.page'); | ||
const pageIndex = hlxPageIndex >= 0 ? hlxPageIndex : aemPageIndex; | ||
const pageType = hlxPageIndex >= 0 ? '.hlx.page' : '.aem.page'; | ||
|
||
const pathLengthCheck = allowEmptyPaths ? pageType.length - 1 : pageType.length; | ||
if (pageIndex < 0 || pageIndex + pathLengthCheck >= urlParts[2].length) { | ||
return null; | ||
} | ||
|
||
Object.assign(urlData, { | ||
urlBranch: urlParts[0].slice(8), // remove "https://" | ||
urlRepo: urlParts[1], | ||
urlOwner: urlParts[2].slice(0, pageIndex), | ||
urlPathRemainder: urlParts[2].slice(pageIndex + pageType.length), | ||
currentPageLang: getLanguageCode(url), | ||
}); | ||
|
||
return urlData; | ||
} catch (err) { | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Creates and configures radio button element | ||
* @param {string} value - Radio button value | ||
* @param {boolean} checked - Whether radio is checked | ||
* @returns {HTMLElement} Label containing radio button | ||
*/ | ||
const createRadioButton = (value, checked = false) => { | ||
const label = createTag('label'); | ||
const radio = createTag('input', { | ||
type: 'radio', | ||
name: 'deployTarget', | ||
value, | ||
required: true, | ||
checked, | ||
}); | ||
label.appendChild(radio); | ||
label.appendChild(document.createTextNode(value.charAt(0).toUpperCase() + value.slice(1))); | ||
return label; | ||
}; | ||
|
||
/** | ||
* Builds UI elements | ||
* @param {HTMLElement} el - Container element | ||
* @param {string} previewUrl - Preview URL | ||
*/ | ||
const buildUi = async (el, previewUrl) => { | ||
try { | ||
const modal = createTag('div', { class: 'modal' }); | ||
const radioGroup = createTag('div', { class: 'radio-group' }); | ||
const envLabel = createTag('div', { class: 'env-label' }, 'Environment'); | ||
radioGroup.appendChild(envLabel); | ||
|
||
radioGroup.appendChild(createRadioButton('stage', true)); | ||
radioGroup.appendChild(createRadioButton('prod')); | ||
|
||
const rolloutBtn = createTag('button', { class: 'rollout-btn' }); | ||
rolloutBtn.append( | ||
createTag('span', { class: 'rollout-btn-text' }, 'Rollout'), | ||
); | ||
|
||
rolloutBtn.addEventListener('click', () => { | ||
const selectedEnv = document.querySelector('input[name="deployTarget"]:checked')?.value; | ||
if (!selectedEnv) return; | ||
|
||
const locV3ConfigUrl = new URL( | ||
'tools/locui-create', | ||
`https://${urlData.urlBranch}--${urlData.urlRepo}--${urlData.urlOwner}.hlx.page`, | ||
); | ||
|
||
const params = { | ||
milolibs: 'milostudio-stage', | ||
ref: urlData.urlBranch, | ||
repo: urlData.urlRepo, | ||
owner: urlData.urlOwner, | ||
host: urlData.host, | ||
project: urlData.project, | ||
env: selectedEnv, | ||
type: 'rollout', | ||
encodedUrls: previewUrl, | ||
language: urlData.currentPageLang, | ||
}; | ||
|
||
Object.entries(params).forEach(([key, value]) => { | ||
if (value) locV3ConfigUrl.searchParams.append(key, value); | ||
}); | ||
|
||
window.open(locV3ConfigUrl, '_blank'); | ||
}); | ||
|
||
const buttonGroup = createTag('div', { class: 'button-group' }); | ||
modal.appendChild(radioGroup); | ||
buttonGroup.appendChild(rolloutBtn); | ||
modal.appendChild(buttonGroup); | ||
|
||
el.appendChild(modal); | ||
} catch (err) { | ||
el.innerHTML = '<div class="modal">Error building interface</div>'; | ||
} | ||
}; | ||
|
||
/** | ||
* Sets up the rollout interface | ||
* @param {HTMLElement} el - Container element | ||
* @param {string} previewUrl - Preview URL | ||
*/ | ||
const setup = async (el, previewUrl) => { | ||
if (!el || !previewUrl) return; | ||
|
||
const data = setUrlData(previewUrl, true); | ||
if (!data) { | ||
el.innerHTML = '<div class="modal">Invalid URL format</div>'; | ||
return; | ||
} | ||
el.innerHTML = ''; | ||
await buildUi(el, previewUrl); | ||
}; | ||
|
||
/** | ||
* Initializes the rollout tool | ||
* @param {HTMLElement} el - Container element | ||
* @param {string} search - Search params string | ||
* @returns {Promise<boolean>} Success status | ||
*/ | ||
export default async function init(el, search = window.location.search) { | ||
if (!el) return false; | ||
|
||
try { | ||
const params = new URLSearchParams(search); | ||
const referrer = params?.get('referrer')?.trim(); | ||
const host = params?.get('host')?.trim(); | ||
const project = params?.get('project')?.trim(); | ||
|
||
if (!referrer || !host || !project) { | ||
el.innerHTML = '<div class="modal">Missing required parameters</div>'; | ||
return false; | ||
} | ||
|
||
if (!referrer.includes('/langstore/')) { | ||
el.innerHTML = '<div class="modal warning"><div class="warning-icon"></div><div class="warning-text">This page is not eligible for rollout<br><span class="warning-text-sub">Only pages under /langstore/ are eligible for rollout</span></div></div>'; | ||
return false; | ||
} | ||
|
||
Object.assign(urlData, { referrer, host, project }); | ||
await setup(el, referrer); | ||
return true; | ||
} catch (err) { | ||
el.innerHTML = '<div class="modal">Initialization failed</div>'; | ||
return false; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="rollout" data-block-status="loaded" daa-lh="b1|rollout"></div> |
Oops, something went wrong.
Oops, something went wrong.
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.
Hi Sabya,
Sorry for bringing this a little late.
You may need to set this value dynamically, as milolibs value change depending on env. We wanted to keep prod and stage code separate.
Prod:
milolibs = milostudio
stage and lower env:
milolibs= milostudio-stage
CC: @nkthakur48 , @raga-adbe-gh
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.
Hi @sabyamon Could you please have a look at the comment provided by @saurabhsircar11