Skip to content

Commit

Permalink
Merge pull request #821 from adobecom/2439
Browse files Browse the repository at this point in the history
DC MILO Release 0.2439
  • Loading branch information
Blainegunn authored Sep 24, 2024
2 parents 1951099 + 290a911 commit e847e23
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 95 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
166 changes: 84 additions & 82 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,32 @@

import LIMITS from './limits.js';
import { setLibs, getEnv, isOldBrowser } from '../../scripts/utils.js';
import { setLibs, isOldBrowser } from '../../scripts/utils.js';
import verbAnalytics from '../../scripts/alloy/verb-widget.js';

const miloLibs = setLibs('/libs');
const { createTag } = await import(`${miloLibs}/utils/utils.js`);

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

const verbRedirMap = {
createpdf: 'createpdf',
'crop-pages': 'crop',
'delete-pages': 'deletepages',
'extract-pages': 'extract',
'combine-pdf': 'combine',
'protect-pdf': 'protect',
'add-comment': 'addcomment',
'pdf-to-image': 'pdftoimage',
'reorder-pages': 'reorderpages',
sendforsignature: 'sendforsignature',
'rotate-pages': 'rotatepages',
fillsign: 'fillsign',
'split-pdf': 'split',
'insert-pdf': 'insert',
'compress-pdf': 'compress',
'png-to-pdf': 'jpgtopdf',
'number-pages': 'number',
'ocr-pdf': 'ocr',
'chat-pdf': 'chat',
'chat-pdf-student': 'study',
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);

// // 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 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) => {
// eslint-disable-next-line chai-friendly/no-unused-expressions
shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging');
};

function redDir(verb) {
const hostname = window?.location?.hostname;
const ENV = getEnv();
const VERB = verb;
let newLocation;
if (hostname !== 'www.adobe.com' && hostname !== 'sign.ing' && hostname !== 'edit.ing') {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}-${ENV}`;
} else {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}` || fallBack;
}
window.location.href = newLocation;
}

export default async function init(element) {
if (isOldBrowser()) {
window.location.href = EOLBrowserPage;
Expand Down Expand Up @@ -117,9 +58,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 @@ -139,14 +83,22 @@ 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);

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

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

button.addEventListener('cancel', () => {
Expand All @@ -168,18 +120,68 @@ 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();
}
});

window.addEventListener('IMS:Ready', async () => {
if (window.adobeIMS.isSignedInUser()) {
redDir(VERB);
// 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.
Loading

0 comments on commit e847e23

Please sign in to comment.