Skip to content

Commit

Permalink
Revert "MWPW-154980 - Milo advanced page publishing" (#2883)
Browse files Browse the repository at this point in the history
Revert "MWPW-154980 - Milo advanced page publishing (#2846)"

This reverts commit 8fd5925.
  • Loading branch information
rgclayton committed Sep 16, 2024
1 parent cb05c67 commit 840e037
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 183 deletions.
17 changes: 6 additions & 11 deletions libs/blocks/bulk-publish-v2/components/bulk-publisher.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './job-process.js';
import { LitElement, html } from '../../../deps/lit-all.min.js';
import { getSheet } from '../../../../tools/utils/utils.js';
import { authenticate, getPublishable, startJob } from '../services.js';
import { authenticate, startJob } from '../services.js';
import { getConfig } from '../../../utils/utils.js';
import {
delay,
Expand Down Expand Up @@ -95,8 +95,7 @@ class BulkPublish2 extends LitElement {
this.validateUrls();
}

setJobErrors(jobErrors, authErrors) {
const errors = [...jobErrors, ...authErrors];
setJobErrors(errors) {
const urls = [];
errors.forEach((error) => {
const matched = this.urls.filter((url) => {
Expand Down Expand Up @@ -324,8 +323,7 @@ class BulkPublish2 extends LitElement {
class="panel-title"
@click=${handleToggle}>
<span class="title">
${this.jobs.length ? html`<strong>${this.jobs.length}</strong>` : ''}
Job Result${this.jobs.length > 1 ? 's' : ''}
Job Results
</span>
<div class="jobs-tools${showList}">
<div
Expand Down Expand Up @@ -382,17 +380,16 @@ class BulkPublish2 extends LitElement {
async submit() {
if (!this.isDisabled()) {
this.processing = 'started';
const { authorized, unauthorized } = await getPublishable(this);
const job = await startJob({
urls: authorized,
urls: this.urls,
process: this.process.toLowerCase(),
useBulk: this.user.permissions[this.process]?.useBulk ?? false,
});
const { complete, error } = processJobResult(job);
this.jobs = [...this.jobs, ...complete];
this.processing = complete.length ? 'job' : false;
if (error.length || unauthorized.length) {
this.setJobErrors(error, unauthorized);
if (error.length) {
this.setJobErrors(error);
} else {
if (this.mode === 'full') this.openJobs = true;
this.reset();
Expand All @@ -410,7 +407,6 @@ class BulkPublish2 extends LitElement {

renderPromptLoader() {
setTimeout(() => {
/* c8 ignore next 4 */
const loader = this.renderRoot.querySelector('.load-indicator');
const message = this.renderRoot.querySelector('.message');
loader?.classList.add('hide');
Expand All @@ -431,7 +427,6 @@ class BulkPublish2 extends LitElement {
const canUse = Object.values(this.user.permissions).filter((perms) => perms.canUse);
if (canUse.length) return html``;
message = 'Current user is not authorized to use Bulk Publishing Tool';
/* c8 ignore next 3 */
} else {
message = 'Please sign in to AEM sidekick to continue';
}
Expand Down
25 changes: 0 additions & 25 deletions libs/blocks/bulk-publish-v2/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import userCanPublishPage from '../../tools/utils/publish.js';
import {
PROCESS_TYPES,
getErrorText,
Expand Down Expand Up @@ -247,32 +246,8 @@ const updateRetry = async ({ queue, urls, process }) => {
return newQueue;
};

// publish authentication service
const getPublishable = async ({ urls, process, user }) => {
let publishable = { authorized: [], unauthorized: [] };
if (!isLive(process)) {
publishable.authorized = urls;
} else {
const { permissions, profile } = user;
const live = { permissions: ['read'] };
if (permissions?.publish?.canUse) {
live.permissions.push('write');
}
publishable = await urls.reduce(async (init, url) => {
const result = await init;
const detail = { webPath: new URL(url).pathname, live, profile };
const { canPublish, message } = await userCanPublishPage(detail);
if (canPublish) result.authorized.push(url);
else result.unauthorized.push({ href: url, message });
return result;
}, Promise.resolve(publishable));
}
return publishable;
};

export {
authenticate,
getPublishable,
pollJobStatus,
startJob,
updateRetry,
Expand Down
32 changes: 0 additions & 32 deletions libs/tools/utils/publish.js

This file was deleted.

61 changes: 9 additions & 52 deletions libs/utils/sidekick-decorate.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
import userCanPublishPage from '../tools/utils/publish.js';

const PUBLISH_BTN = '.publish.plugin button';
const BACKUP_PROFILE = '.profile-email';
const CONFIRM_MESSAGE = 'Are you sure? This will publish to production.';

export default function stylePublish(sk) {
const setupPublishBtn = async (page, btn) => {
const { canPublish, message } = await userCanPublishPage(page, false);
btn.setAttribute('disabled', !canPublish);
const messageText = btn.querySelector('span');
const text = canPublish ? CONFIRM_MESSAGE : message;
if (messageText) {
messageText.innerText = text;
} else {
btn.insertAdjacentHTML('beforeend', `<span>${text}</span>`);
}
};

const style = new CSSStyleSheet();
style.replaceSync(`
:host {
Expand All @@ -28,21 +10,19 @@ export default function stylePublish(sk) {
order: 100;
}
.publish.plugin button {
position: relative;
}
.publish.plugin button:not([disabled=true]) {
background: var(--bg-color);
border-color: #b46157;
color: var(--text-color);
position: relative;
}
.publish.plugin button:not([disabled=true]):hover {
.publish.plugin button:hover {
background-color: var(--hlx-sk-button-hover-bg);
border-color: unset;
color: var(--hlx-sk-button-hover-color);
}
.publish.plugin button > span {
display: none;
background: #666;
background: var(--bg-color);
border-radius: 4px;
line-height: 1.2rem;
padding: 8px 12px;
Expand All @@ -53,9 +33,6 @@ export default function stylePublish(sk) {
width: 150px;
white-space: pre-wrap;
}
.publish.plugin button:not([disabled=true]) > span {
background: var(--bg-color);
}
.publish.plugin button:hover > span {
display: block;
color: var(--text-color);
Expand All @@ -64,39 +41,19 @@ export default function stylePublish(sk) {
content: '';
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid #666;
border-bottom: 6px solid var(--bg-color);
position: absolute;
text-align: center;
top: -6px;
left: 50%;
transform: translateX(-50%);
}
.publish.plugin button:not([disabled=true]) > span:before {
border-bottom: 6px solid var(--bg-color);
}
`);

sk.shadowRoot.adoptedStyleSheets = [style];

sk.addEventListener('statusfetched', async (event) => {
const page = event?.detail?.data;
const btn = event?.target?.shadowRoot?.querySelector(PUBLISH_BTN);
if (page && btn) {
setupPublishBtn(page, btn);
}
});

setTimeout(async () => {
const btn = sk.shadowRoot.querySelector(PUBLISH_BTN);
btn?.setAttribute('disabled', true);
const message = btn?.querySelector('span');
if (btn && !message) {
const page = {
webPath: window.location.pathname,
// added for edge case where the statusfetched event isnt fired on refresh
profile: { email: sk.shadowRoot.querySelector(BACKUP_PROFILE)?.innerText },
};
setupPublishBtn(page, btn);
}
setTimeout(() => {
const btn = sk.shadowRoot.querySelector('.publish.plugin button');
btn?.insertAdjacentHTML('beforeend', `
<span>Are you sure? This will publish to production.</span>
`);
}, 500);
}
33 changes: 12 additions & 21 deletions test/blocks/bulk-publish-v2/bulk-publish-v2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@ describe('Bulk Publish Tool', () => {
await mouseEvent(rootEl.querySelector('.fix-btn'));
});

it('can trigger cannot publish config', async () => {
await clock.runAllAsync();
await setProcess(rootEl, 'publish');
await setTextArea(rootEl, 'https://error--milo--adobecom.hlx.page/not/a/valid/path');
await mouseEvent(rootEl.querySelector('#RunProcess'));
const errors = rootEl.querySelector('.errors');
expect(errors.querySelector('strong').innerText).to.equal('Publishing disabled until the test is over');
await mouseEvent(rootEl.querySelector('.fix-btn'));
});

it('can validate milo urls and enable form', async () => {
await clock.runAllAsync();
await setProcess(rootEl, 'publish');
Expand All @@ -142,17 +132,6 @@ describe('Bulk Publish Tool', () => {
await mouseEvent(rootEl.querySelector('.switch.half'));
});

it('can toggle job timing flyout', async () => {
await clock.runAllAsync();
const doneJobProcess = rootEl.querySelector('job-process');
const jobInfo = doneJobProcess?.shadowRoot.querySelector('job-info');
const timerDetail = jobInfo?.shadowRoot.querySelector('.timer');
await mouseEvent(timerDetail);
await clock.runAllAsync();
await mouseEvent(timerDetail);
expect(timerDetail.classList.contains('show-times')).to.be.false;
});

it('can submit valid bulk preview job', async () => {
await clock.runAllAsync();
await setProcess(rootEl, 'preview');
Expand Down Expand Up @@ -195,6 +174,17 @@ describe('Bulk Publish Tool', () => {
expect(rootEl.querySelectorAll('job-process')).to.have.lengthOf(4);
});

it('can toggle job timing flyout', async () => {
await clock.runAllAsync();
const doneJobProcess = rootEl.querySelector('job-process');
const jobInfo = doneJobProcess?.shadowRoot.querySelector('job-info');
const timerDetail = jobInfo?.shadowRoot.querySelector('.timer');
await mouseEvent(timerDetail);
await clock.runAllAsync();
await mouseEvent(timerDetail);
expect(timerDetail.classList.contains('show-times')).to.be.false;
});

it('can toggle view mode', async () => {
await mouseEvent(rootEl.querySelector('.switch.full'));
await clock.runAllAsync();
Expand Down Expand Up @@ -228,6 +218,7 @@ describe('Bulk Publish Tool', () => {
it('can clear bulk jobs', async () => {
await clock.runAllAsync();
await mouseEvent(rootEl.querySelector('.clear-jobs'));
await clock.runAllAsync();
expect(rootEl.querySelectorAll('job-process')).to.have.lengthOf(0);
});
});
2 changes: 1 addition & 1 deletion test/blocks/bulk-publish-v2/mocks/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MockAuth extends HTMLElement {
bubbles: true,
detail: {
data: {
profile: { name: 'Unit Test', email: '[email protected]' },
profile: { name: 'Unit Test' },
preview: { permissions },
live: { permissions },
},
Expand Down
3 changes: 1 addition & 2 deletions test/blocks/bulk-publish-v2/mocks/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const requests = {
delstatus: 'https://admin.hlx.page/job/adobecom/milo/main/preview-remove/job-2024-01-24t23-16-20-377z/details',
retry: 'https://admin.hlx.page/preview/adobecom/milo/main/tools/bulk-publish-v2-test',
index: 'https://admin.hlx.page/index/adobecom/milo/main/tools/bulk-publish-v2-test',
permissions: '/.milo/publish-permissions-config.json',
};

const getMocks = async () => {
Expand All @@ -26,7 +25,7 @@ const getMocks = async () => {
export async function mockFetch() {
const mocks = await getMocks();
stub(window, 'fetch').callsFake((...args) => {
const headers = args[1]?.body ?? null;
const headers = args[1].body ?? null;
const body = headers ? JSON.parse(headers) : false;
const [resource] = args;
const response = mocks.find((mock) => (body.delete ? mock.request === 'delete' : mock.url === resource));
Expand Down
26 changes: 0 additions & 26 deletions test/blocks/bulk-publish-v2/mocks/response/permissions.json

This file was deleted.

14 changes: 1 addition & 13 deletions tools/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const IMS_CLIENT_ID = 'milo_ims';
const IMS_PROD_URL = 'https://auth.services.adobe.com/imslib/imslib.min.js';
const STYLE_SHEETS = {};
const CONFIGS = {};

const getImsToken = async (loadScript) => {
window.adobeid = {
Expand All @@ -26,15 +25,4 @@ const getSheet = async (url) => {
return sheet;
};

const getCustomConfig = async (path) => {
/* c8 ignore next 3 */
if (CONFIGS[path] !== undefined) {
return CONFIGS[path];
}
const resp = await fetch(path);
const config = resp.ok ? await resp.json() : null;
CONFIGS[path] = config;
return config;
};

export { getImsToken, getSheet, getCustomConfig };
export { getImsToken, getSheet };

0 comments on commit 840e037

Please sign in to comment.