-
Notifications
You must be signed in to change notification settings - Fork 175
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-135821 introduce mep custom action & use it for card collection #2152
Conversation
- and inaugurating first custom action for replacing cards in collection
@@ -51,6 +51,10 @@ const DATA_TYPE = { | |||
TEXT: 'text', | |||
}; | |||
|
|||
export const MERCH_CARD_COLLECTION_SELECTOR = 'in-card-collection'; |
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.
I think this constant should not be here, personalization.js should not know about blocks needing delayed MEP based personalization.
@@ -51,6 +51,10 @@ const DATA_TYPE = { | |||
TEXT: 'text', | |||
}; | |||
|
|||
export const MERCH_CARD_COLLECTION_SELECTOR = 'in-card-collection'; | |||
|
|||
const CUSTOM_SELECTORS = [MERCH_CARD_COLLECTION_SELECTOR]; |
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.
this too.
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.
this is the smallest footprint to have to get "custom" actions defined so mep knows it just needs to register them as such.
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 selectors had a pattern or prefix, we wouldn't need to add custom selectors in this file.
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.
I think @yesil is right. The more I think about it, the more I think we should do a prefix and maybe the block name. Something like:
in-block:blockname
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 we did that, you wouldn't need the constant. You just extract the 2nd part of the string and in your block you just use your own block name.
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.
sure :) or custom:whatever but yes in that case in-block:merch-card-collection sounds right indeed :)
@@ -289,6 +293,14 @@ function getSection(rootEl, idx) { | |||
: rootEl.querySelector(`:scope > div:nth-child(${idx})`); | |||
} | |||
|
|||
function registerCustomAction(cmd) { |
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.
should we differentiate normal MEP rules from these ones?
if we expose all the MEP rules and have a flag when they are successfully executed at page load, then blocks such as merch-card-collection
can go over the rules without that flag and find matching rules and execute them.
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.
they are, all normal processing is stopped if identified action is custom, and then put in config.mep.custom
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.
actually I meant, do we need to differentiate, sorry for the language.
@@ -161,7 +161,23 @@ describe('Merch Cards', async () => { | |||
|
|||
it('should override cards when asked to', async () => { | |||
const el = document.getElementById('multipleFilters'); | |||
el.dataset.overrides = '/override-photoshop,/override-express'; | |||
setConfig({ |
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.
I suggest putting MEP rules in own config object.
it can be a module scoped config and be exposed from personalization.js
.
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.
this is what we do, in config.mep.custom
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.
I see 👍
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.
In my opinion, personalization.js should not know about blocks needing to perform MEP during block initialisation.
Otherwise, the current code looks concise and simple.
@@ -289,6 +293,14 @@ function getSection(rootEl, idx) { | |||
: rootEl.querySelector(`:scope > div:nth-child(${idx})`); | |||
} | |||
|
|||
function registerCustomAction(cmd) { |
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.
actually I meant, do we need to differentiate, sorry for the language.
@@ -161,7 +161,23 @@ describe('Merch Cards', async () => { | |||
|
|||
it('should override cards when asked to', async () => { | |||
const el = document.getElementById('multipleFilters'); | |||
el.dataset.overrides = '/override-photoshop,/override-express'; | |||
setConfig({ |
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.
I see 👍
setConfig({ | ||
...conf, | ||
mep: { | ||
custom: { |
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.
suggestion: deferred
or lazy
instead of custom
?
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.
To me it's less talkative than custom. custom means in that context that it will not be handled by perso, which implies it's lazy/deferred, but also that something else should take care of it :)
@@ -51,6 +51,10 @@ const DATA_TYPE = { | |||
TEXT: 'text', | |||
}; | |||
|
|||
export const MERCH_CARD_COLLECTION_SELECTOR = 'in-card-collection'; | |||
|
|||
const CUSTOM_SELECTORS = [MERCH_CARD_COLLECTION_SELECTOR]; |
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 selectors had a pattern or prefix, we wouldn't need to add custom selectors in this file.
i suggested "custom-" prefix for actions :) but @vgoodric was preferring custom selectors :) |
This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR. |
@@ -291,8 +292,7 @@ export default async function init(el) { | |||
} | |||
|
|||
const cardsRoot = await cardsRootPromise; | |||
const overrides = el.dataset[OVERRIDE_PATHS]; | |||
const overridePromises = overrides?.split(',').map(fetchOverrideCard); | |||
const overridePromises = mep?.custom?.[MERCH_CARD_COLLECTION_SELECTOR]?.map(fetchOverrideCard); |
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.
look in personalization.js for the handleFragmentCommand function. In particular, this line:
if (config.mep.preview) a.dataset.manifestId = manifestPath;
This is what makes the highlight feature possible. I recommend doing this as well so people can see what has been changed.
thanks for the great suggestion about prefixes @yesil @vivgoodrich, just updated |
Can you also update your sample manifests? So I can see it all in action? |
just did @vivgoodrich , will now tackle your 2nd suggestion |
|
do we have a task to cover it with nala tests? |
This PR is currently in the |
* stage: MWPW-146999: kodiak CVE 25883 (adobecom#2183) MWPW-144549 CTA alignment for Text, Icon, and Media Blocks (adobecom#2098) MWPW-146494-keep gnav sticky when branch banner is displayed (adobecom#2175) MWPW-135821 introduce mep custom action & use it for card collection (adobecom#2152) MWPW-146129 [Original: adobecom#2123] App Launcher overlaps the menu in Unav in the devices (adobecom#2184) Revert "MWPW-146129 App Launcher overlaps the menu in Unav in the devices" (adobecom#2182) MWPW-146129 App Launcher overlaps the menu in Unav in the devices (adobecom#2123) MWPW-139842 [Revert] Fill button style (adobecom#2181) Mwpw 142003: Mini Compare Chart card fixes (adobecom#2093) MWPW-146756] Add support for RTL in aside notifications, horizontal cards"" (adobecom#2178) Revert "[MWPW-146756] Add support for RTL in aside notifications, horizontal cards" (adobecom#2177) [MWPW-146756] Add support for RTL in aside notifications, horizontal cards (adobecom#2167) Revert "MWPW-142590 - [Share] enhancement - ability to edit text above icons" (adobecom#2172)
…dobecom#2152) * MWPW-135821 introduce custom action - and inaugurating first custom action for replacing cards in collection * MWPW-135821 use prefix in selector * MWPW-135821 adding preview data --------- Co-authored-by: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com>
Resolves: MWPW-135821
with following manifest added to the page
before & after personalisation (see photoshop card)
Test URLs:
Before: https://main--milo--adobecom.hlx.page/?martech=off
After: https://mwpw-135821--milo--npeltier.hlx.page/?martech=off
Before: https://main--cc--adobecom.hlx.page/drafts/npeltier/promocard-test?milolibs=mwpw-135821--milo--npeltier
After: https://main--cc--adobecom.hlx.page/drafts/npeltier/promocard-test?milolibs=mwpw-135821--milo--npeltier&mep=%2Fdrafts%2Fnpeltier%2Fpromo-test.json--target-challenger+name