Skip to content

Commit

Permalink
Merge branch 'stage' into MWPW-158599
Browse files Browse the repository at this point in the history
* stage:
  MWPW-158834
  console logs for ez debug
  updates
  Eslint fix
  MWPW-158122
  Add purge action command choice
  MWPW-158423

# Conflicts:
#	acrobat/blocks/verb-widget/verb-widget.js
  • Loading branch information
joaquinrivero committed Sep 24, 2024
2 parents 1044c23 + 290a911 commit 6950c1c
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 50 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/clear-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:
inputs:
cpCode:
description: 'CP Code'
description: 'CP Code, 1551836 (prod) / 1551833 (stage)'
type: string
required: true
default: '1551836'
Expand All @@ -27,6 +27,14 @@ on:
options:
- 'staging'
- 'production'
command:
description: 'Command'
type: choice
required: true
default: 'invalidate'
options:
- 'invalidate'
- 'delete'

jobs:
clear-cache:
Expand All @@ -38,7 +46,7 @@ jobs:
env:
EDGERC: ${{ secrets.EDGERC }}
with:
command: 'invalidate'
command: ${{ inputs.command }}
type: 'cpcode'
ref: ${{ inputs.cpCode }}
ref: ${{ inputs.cpCode }}
network: ${{ inputs.network }}
13 changes: 13 additions & 0 deletions acrobat/blocks/unity/unity.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import LIMITS from '../verb-widget/limits.js';

const localeMap = {
'': 'en-us',
br: 'pt-br',
Expand Down Expand Up @@ -98,12 +100,23 @@ function getUnityLibs(prodLibs = '/unitylibs') {
&& !hostname.includes('localhost')) {
return prodLibs;
}
// eslint-disable-next-line compat/compat
const branch = new URLSearchParams(window.location.search).get('unitylibs') || 'main';
if (branch.indexOf('--') > -1) return `https://${branch}.hlx.live/unitylibs`;
return `https://${branch}--unity--adobecom.hlx.live/unitylibs`;
}

export default async function init(el) {
let mobileApp;
if ((/iPad|iPhone|iPod/.test(window.browser?.ua) && !window.MSStream)
|| /android/i.test(window.browser?.ua)) {
mobileApp = true;
}

const element = el.querySelector('span');
const verb = element.classList[1].replace('icon-', '');
if (mobileApp && LIMITS[verb].mobileApp) return;

const unitylibs = getUnityLibs();
const langFromPath = window.location.pathname.split('/')[1];
const languageCode = localeMap[langFromPath] ? localeMap[langFromPath].split('-')[0] : 'en';
Expand Down
10 changes: 8 additions & 2 deletions acrobat/blocks/verb-widget/verb-widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@
margin-left: 15px;
}

.verb-mobile-cta:hover,
.verb-mobile-cta:active {
background-color: #0054b6;
color: #fff;
text-decoration: none;
}

@media screen and (min-width: 768px) {
.verb-container {
align-items: center;
Expand All @@ -246,11 +253,10 @@
}

.verb-mobile-cta {
/* display: none; */
background: #1473e6;
border-radius: 8px;
padding: 11px 27px;
color: white;
color: #fff;
white-space: nowrap;
font-weight: 700;
display: flex;
Expand Down
137 changes: 94 additions & 43 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,24 @@ const { createTag } = await import(`${miloLibs}/utils/utils.js`);

const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html';

// const handleError = (err, errTxt, str, strTwo) => {
// err.classList.add('verb-error');
// err.classList.remove('hide');
// errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`;

// setTimeout(() => {
// err.classList.remove('verb-error');
// err.classList.add('hide');
// }, 5000);

// // Add LANA Logs and AA
// };

// This function is no longer needed, I'll remove after we get error event from Unity team.
// handleError() is will need to be uncommented out too.

// const sendToUnity = async (file, verb, err, errTxt) => {
// // Error Check: File Empty
// if (file.size < 1) {
// verbAnalytics('error:step01:empty-file', verb);
// handleError(err, errTxt, 'verb-widget-error-empty');
// }

// // Error Check: Supported File Type
// if (LIMITS[verb].acceptedFiles.indexOf(file.type) < 0) {
// verbAnalytics('error:step01:unsupported-file-type', verb);
// handleError(err, errTxt, 'verb-widget-error-unsupported');
// return;
// }

// // Error Check: File Too Large
// if (file.size > LIMITS[verb].maxFileSize) {
// verbAnalytics('error:step01:file-too-large', verb);
// handleError(err, errTxt, 'verb-widget-error-large', LIMITS[verb].maxFileSizeFriendly);
// }
// };
const setUser = () => {
localStorage.setItem('unity.user', 'true');
};

const handleError = (err, errTxt, str, strTwo) => {
err.classList.add('verb-error');
err.classList.remove('hide');
errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`;

setTimeout(() => {
err.classList.remove('verb-error');
err.classList.add('hide');
}, 5000);
};

const setDraggingClass = (widget, shouldToggle) => {
widget.classList.toggle('dragging', shouldToggle);
// eslint-disable-next-line chai-friendly/no-unused-expressions
shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging');
};

function prefetchNextPage(verb) {
Expand Down Expand Up @@ -99,9 +78,12 @@ export default async function init(element) {
const widgetButton = createTag('label', { for: 'file-upload', class: 'verb-cta' }, window.mph['verb-widget-cta']);
const widgetMobileButton = createTag('a', { class: 'verb-mobile-cta', href: mobileLink }, window.mph['verb-widget-cta-mobile']);
const button = createTag('input', { type: 'file', id: 'file-upload', class: 'hide' });
const widgetImage = createTag('img', { class: 'verb-image', src: children[1].querySelector('img')?.src });
const widgetImage = createTag('img', { class: 'verb-image', src: `/acrobat/img/verb-widget/${VERB}.png` });
// Since we're using placeholders we need a solution for the hyperlinks
const legal = createTag('p', { class: 'verb-legal' }, window.mph['verb-widget-legal']);
const legal = createTag('p', { class: 'verb-legal' }, `${window.mph['verb-widget-legal']} `);
const terms = createTag('a', { class: 'verb-legal-url', target: '_blank', href: 'https://www.adobe.com/legal/terms.html' }, window.mph.tou);
const and = createTag('span', { class: 'verb-legal-url' }, ` ${window.mph.and} `);
const privacy = createTag('a', { class: 'verb-legal-url', target: '_blank', href: 'https://www.adobe.com/privacy/policy.html' }, `${window.mph.pp}.`);
const iconSecurity = createTag('div', { class: 'security-icon' });
const footer = createTag('div', { class: 'verb-footer' });

Expand All @@ -121,16 +103,24 @@ export default async function init(element) {
} else {
widgetLeft.append(widgetHeader, widgetHeading, widgetCopy, errorState, widgetButton, button);
}

legal.append(terms, and, privacy);

footer.append(iconSecurity, legal);

element.append(widget, footer);

// Analytics
verbAnalytics('landing:shown', VERB);

window.prefetchInitiated = false;

widgetMobileButton.addEventListener('click', () => {
verbAnalytics('goto-app:clicked', VERB);
});

button.addEventListener('click', () => {
verbAnalytics('dropzone:choose-file-clicked', VERB);
verbAnalytics('filepicker:shown', VERB);
initiatePrefetch(VERB);
});

Expand Down Expand Up @@ -159,12 +149,73 @@ export default async function init(element) {
});

window.addEventListener('unity:track-analytics', (e) => {
if (e.detail.event === 'change') {
if (e.detail?.event === 'change') {
verbAnalytics('choose-file:open', VERB);
setUser();
}
if (e.detail.event === 'drop') {
verbAnalytics('files-dropped', VERB);
// maybe new event name files-dropped?
if (e.detail?.event === 'drop') {
verbAnalytics('files-dropped', VERB, e.detail?.data);
setDraggingClass(widget, false);
setUser();
}
if (e.detail?.event === 'choose-file-clicked') {
verbAnalytics('dropzone:choose-file-clicked', VERB, e.detail?.data);
setUser();
}

if (e.detail?.event === 'uploading') {
verbAnalytics('job:uploading', VERB, e.detail?.data);
setUser();
}

if (e.detail?.event === 'uploaded') {
verbAnalytics('job:uploaded', VERB, e.detail?.data);
setUser();
}
});

// Errors, Analytics & Logging
window.addEventListener('unity:show-error-toast', (e) => {
console.log(`⛔️ Error Code - ${e.detail?.code}`);

if (e.detail?.code === 'only_accept_one_file') {
handleError(errorState, errorStateText, 'verb-widget-error-multi');
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'unsupported_type') {
handleError(errorState, errorStateText, 'verb-widget-error-unsupported');
verbAnalytics('error:unsupported_type', VERB);
}

if (e.detail?.code === 'empty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-empty');
verbAnalytics('error:empty_file', VERB);
}

// Code may be wrong. should be 'file_too_large'
if (e.detail?.code === 'file_too_largempty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-large', LIMITS[VERB].maxFileSizeFriendly);
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'max_page_count') {
handleError(errorState, errorStateText, 'verb-widget-error-max', LIMITS[VERB].maxNumFiles);
verbAnalytics('error:max_page_count', VERB);
}

// acrobat:verb-fillsign:error:page_count_missing_from_metadata_api
// acrobat:verb-fillsign:error:403
// acrobat:verb-fillsign:error
// LANA for 403
});
}

// const ce = (
// new CustomEvent(
// 'unity:show-error-toast',
// { detail: { code: 'only_accept_one_file', message: 'Error message' } },
// )
// );
// dispatchEvent(ce)
Binary file added acrobat/img/verb-widget/fillsign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 76 additions & 2 deletions acrobat/scripts/alloy/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
const params = new Proxy(
// eslint-disable-next-line compat/compat
new URLSearchParams(window.location.search),
{ get: (searchParams, prop) => searchParams.get(prop) },
);

let appReferrer = params.x_api_client_id || params['x-product'] || '';
if (params.x_api_client_location || params['x-product-location']) {
appReferrer = `${appReferrer}:${params.x_api_client_location || params['x-product-location']}`;
}
let trackingId = params.trackingid || '';
if (params.mv) {
trackingId = `${trackingId}:${params.mv}`;
}
if (params.mv2) {
trackingId = `${trackingId}:${params.mv2}`;
}
const appTags = [];
if (params.workflow) {
appTags.push(params.workflow);
}
if (params.dropzone2) {
appTags.push('dropzone2');
}

export default function init(eventName, verb) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName}`);
const event = {
documentUnloading: true,
data: {
Expand All @@ -12,8 +38,56 @@ export default function init(eventName, verb) {
},
_adobe_corpnew: {
digitalData: {
dcweb: { event: { pagename: `acrobat:verb-${verb}:${eventName}` } },
dcweb2: { event: { pagename: `acrobat:verb-${verb}:${eventName}` } },
dcweb: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size: '2-5MB',
count: 1,
extension: 'docx',
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: 'DO WE NEED THIS?',
is_authenticated: false,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
},
dcweb2: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size: '2-5MB',
count: 1,
extension: 'docx',
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: 'DO WE NEED THIS?',
is_authenticated: false,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
},
},
},
},
Expand Down

0 comments on commit 6950c1c

Please sign in to comment.