From a8ea3cd3444034985417b19d15fb455ad9e8ddfc Mon Sep 17 00:00:00 2001 From: Raghav Sharma <118168183+sharmrj@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:29:27 +0530 Subject: [PATCH] MWPW-154013 PEP prompt redirection is broken in stage after the PEP dismissal PR merge (#2547) * Added a way to mock entitlements in non prod environments for testing purposes * Added a pulsing animation after dismissing the PEP modal * Added the ability to debug pep in prod; added skipPepEntitlements option * fixed url for loading the pep dismissal animation * Another url fix for the pep dismissal animation css file * slowed down the default animation * Added the tooltip * re-enabled tracking dismissed prompts * added tooltip that uses data attributes; cleaned up ring animation slightly * styled the tooltip in accordance with the new figma spec sheet * Changed the color of the tooltip * Pick up pep dismissal action config from section metadata; fixed lowercase url issue * Updated unit tests * updated an incomplete pep test * Fixed dismissal actions firing when redirecting * Removed a comment * added tests for running dismissal actions * Tooltip and animation are now cleared if the app switcher is clicked * added a missing semicolon * small refactor of remove animation/tooltip on click logic * A bit of cleanup * removed some unnecessary code * Fixed a bug introduced by one of the previous fixes * fixed a classname * Formatting of an html string * replaced all usage of right in absolute positioning with left * Added CONFIG default values to dismissal action function parameter lists * renamed a variable * Removed an unused variable * Grouped together common css rules in tooltip.css * Combined dismissal css with the general webapp-prompt css * Removed an unused import * Added a unit test * Removed some unneeded newlines * Moved the tooltip down slightly * Added a missing curly brace * added a missing semicolon on line 92 of libs/features/webapp-prompt/webapp-prompt.js Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * made the dismissal config its own entity * added some variables to the focus animation css * removed a redundant style * cleaned up the padding css for the tooltip * minor refactoring * Changed the tooltip fontfamily to use the milo styles variable defined in root * Removed an unnecessary css rule * Replaced tabs with spaces in webapp-prompt.css * Fixed the PEP unit tests * clock cleanup in tests * fixed an issue with the redirect * small change * Fixed eslint error by making a method static * Fixed failing tests * Fixed an issue where the redirect wasn't happening * Added a newline to get Franklin to pick up the new css * Removing the newline added previously * Fixing the tests --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- libs/features/webapp-prompt/webapp-prompt.css | 115 ++++++++++++++++++ libs/features/webapp-prompt/webapp-prompt.js | 99 +++++++++++++-- .../webapp-prompt/mocks/pep-prompt-content.js | 27 +++- test/features/webapp-prompt/test-utilities.js | 13 +- .../webapp-prompt/webapp-prompt.test.js | 113 ++++++++++++----- 5 files changed, 322 insertions(+), 45 deletions(-) diff --git a/libs/features/webapp-prompt/webapp-prompt.css b/libs/features/webapp-prompt/webapp-prompt.css index 1fbc0baae8..cd421f6f8a 100644 --- a/libs/features/webapp-prompt/webapp-prompt.css +++ b/libs/features/webapp-prompt/webapp-prompt.css @@ -188,3 +188,118 @@ } } } + +/* DISMISSAL TOOLTIP */ + +[data-pep-dismissal-tooltip]::after { + content: attr(data-pep-dismissal-tooltip); + display: inline-flex; + z-index: 3; + height: fit-content; + width: 8.875rem; + top: 125%; + left: -300%; + word-break: break-word; + border-radius: 7px; + + padding-inline: 0.5625rem; + padding-block: 0.25rem 0.3125rem; + + font-family: var(--body-font-family); + font-size: 0.75rem; + line-height: 0.9375rem; + color: white; +} + +[data-pep-dismissal-tooltip]::before { + content: ''; + z-index: 2; + width: 0.44rem; + height: 0.44rem; + border-radius: 0.05rem; + left: calc(50% - 0.22rem); + top: 115%; + + transform: rotate(45deg); +} + +[data-pep-dismissal-tooltip]::before, +[data-pep-dismissal-tooltip]::after { + background-color: #3B63FB; + position: absolute; + pointer-events: none; + transition: opacity 0.5s; +} + +@media (min-width: 1520px) { + [data-pep-dismissal-tooltip]::after { + left: calc(50% - 5rem); + } +} + +/* DISMISSAL ANIMATION */ + +.coach-indicator { + --coach-indicator-ring-default-color: rgba(56,146,243); + --coach-indicator-ring-diameter: 1.25rem; + --coach-indicator-ring-border-size: 2px; + --coach-indicator-ring-inline-size: var(--coach-indicator-ring-diameter); + --coach-indicator-ring-block-size: var(--coach-indicator-ring-diameter); + --coach-indicator-first-ring-delay-fraction: 0; + --coach-indicator-second-ring-delay-fraction: 0.33; + --coach-indicator-third-ring-delay-fraction: 0.66; + --animation-duration: 3000ms; +} + +@keyframes pulse { + 0% { + transform: scale(0.8); + opacity: 0; + } + + 50% { + transform: scale(1.5); + opacity: 1; + } + + 100% { + transform: scale(2); + opacity: 0; + } +} + +.coach-indicator .coach-indicator-ring { + display: block; + position: absolute; + top: 14%; + left: 13%; + + border-style: solid; + border-width: var(--coach-indicator-ring-border-size); + border-color: var(--coach-indicator-ring-default-color); + + inline-size: var(--coach-indicator-ring-inline-size); + block-size: var(--coach-indicator-ring-block-size); + animation: pulse var(--animation-duration) linear; + animation-fill-mode: both; + + border-radius: 5px; +} + +.coach-indicator .coach-indicator-ring:nth-child(1) { + animation-delay: calc(var(--animation-duration)*var(--coach-indicator-first-ring-delay-fraction)); +} + +.coach-indicator .coach-indicator-ring:nth-child(2) { + animation-delay: calc(var(--animation-duration)*var(--coach-indicator-second-ring-delay-fraction)); +} + +.coach-indicator .coach-indicator-ring:nth-child(3) { + animation-delay: calc(var(--animation-duration)*var(--coach-indicator-third-ring-delay-fraction)); +} + +@media (prefers-reduced-motion: reduce) { + .coach-indicator .coach-indicator-ring { + animation: none; + } +} diff --git a/libs/features/webapp-prompt/webapp-prompt.js b/libs/features/webapp-prompt/webapp-prompt.js index 418d2ad68d..ea9bc072d0 100644 --- a/libs/features/webapp-prompt/webapp-prompt.js +++ b/libs/features/webapp-prompt/webapp-prompt.js @@ -8,13 +8,21 @@ import { import { getConfig, decorateSVG } from '../../utils/utils.js'; import { replaceKey, replaceText } from '../placeholders.js'; +export const DISMISSAL_CONFIG = { + animationCount: 2, + animationDuration: 2500, + tooltipMessage: 'Use the App Switcher to quickly find apps.', + tooltipDuration: 5000, +}; + const CONFIG = { selectors: { prompt: '.appPrompt' }, delay: 7000, loaderColor: '#EB1000', + ...DISMISSAL_CONFIG, }; -const getElemText = (elem) => elem?.textContent?.trim().toLowerCase(); +const getElemText = (elem) => elem?.textContent?.trim(); const getMetadata = (el) => [...el.childNodes].reduce((acc, row) => { if (row.children?.length === 2) { @@ -35,6 +43,54 @@ const getIcon = (content) => { return icons.company; }; +const showTooltip = ( + element, + message = CONFIG.tooltipMessage, + time = CONFIG.tooltipDuration, +) => { + element.setAttribute('data-pep-dismissal-tooltip', message); + const cleanup = () => element.removeAttribute('data-pep-dismissal-tooltip'); + const timeoutID = setTimeout(cleanup, time); + element.addEventListener('click', () => { + cleanup(); + clearTimeout(timeoutID); + }, { once: true }); +}; + +const playFocusAnimation = ( + element, + iterationCount = CONFIG.animationCount, + animationDuration = CONFIG.animationDuration, +) => { + element.classList.add('coach-indicator'); + element.style.setProperty('--animation-duration', `${animationDuration}ms`); + const rings = []; + const createRing = () => toFragment` +