Skip to content

Commit

Permalink
Merge branch 'main' into ebartholomew/aside-bg-breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
elan-tbx authored Aug 30, 2023
2 parents 9f4ee57 + 53d8c51 commit 6dc7e32
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 31 deletions.
37 changes: 31 additions & 6 deletions libs/blocks/bulk-publish/bulk-publish-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const BULK_STORED_URLS = 'bulkStoredUrls';
const BULK_STORED_RESULTS = 'bulkStoredResults';
const BULK_STORED_OPERATION = 'bulkStoredOperation';
const UNSUPPORTED_SITE_STATUS = 'unsupported domain';
const UNSUPPORTED_ACTION_STATUS = 'unsupported action';
const DUPLICATE_STATUS = 'duplicate';
export const ANONYMOUS = 'anonymous';

Expand Down Expand Up @@ -98,6 +99,7 @@ const siteIsSupported = async (url) => {
const { origin } = new URL(url);
const sites = await getSupportedSites();
return sites.includes(origin);
/* c8 ignore next 3 */
} catch (e) {
return false;
}
Expand All @@ -112,25 +114,35 @@ export const getActionName = (action, useGerund) => {
switch (action) {
case null:
case 'preview':
name = (!useGerund) ? 'Preview' : 'Previewing';
name = (useGerund) ? 'Previewing' : 'Preview';
break;
case 'publish':
name = (!useGerund) ? 'Publish' : 'Publishing';
name = (useGerund) ? 'Publishing' : 'Publish';
break;
case 'unpublish':
name = (!useGerund) ? 'Unpublish' : 'Unpublishing';
name = (useGerund) ? 'Unpublishing' : 'Unpublish';
break;
case 'unpublish&delete':
name = (!useGerund) ? 'Delete' : 'Deleting';
name = (useGerund) ? 'Deleting' : 'Delete';
break;
case 'index':
name = (useGerund) ? 'Indexing' : 'Index';
break;
default:
name = (!useGerund) ? 'Preview & publish' : 'Previewing & publishing';
name = (useGerund) ? 'Previewing & publishing' : 'Preview & publish';
}
return name;
};

const executeAction = async (action, url) => {
const operation = (action === 'preview' || action === 'delete') ? 'preview' : 'live';
const allowedActions = ['preview', 'publish', 'delete', 'unpublish', 'index'];
if (!allowedActions.includes(action)) return UNSUPPORTED_ACTION_STATUS;
let operation = action;
if (action === 'delete') {
operation = 'preview';
} else if (action === 'publish' || action === 'unpublish') {
operation = 'live';
}
const siteAllowed = await siteIsSupported(url);
if (!siteAllowed) return UNSUPPORTED_SITE_STATUS;
const { hostname, pathname } = new URL(url);
Expand Down Expand Up @@ -182,6 +194,7 @@ export const executeActions = async (resume, setResult) => {
results.push({
url,
status,
timestamp: new Date(),
});
setResult([...results]);
setLocalStorage(BULK_STORED_URL_IDX, i);
Expand All @@ -202,6 +215,8 @@ export const getCompletion = (results) => {
let publishSuccess = 0;
let deleteSuccess = 0;
let unpublishSuccess = 0;
let indexTotal = 0;
let indexSuccess = 0;

results.forEach((result) => {
const { status } = result;
Expand All @@ -213,6 +228,8 @@ export const getCompletion = (results) => {
if (status.publish === 200) publishSuccess += 1;
if (status.delete === 204) deleteSuccess += 1;
if (status.unpublish === 204) unpublishSuccess += 1;
if (status.index) indexTotal += 1;
if (status.index === 200 || status.index === 202) indexSuccess += 1;
});
return {
preview: {
Expand All @@ -231,6 +248,10 @@ export const getCompletion = (results) => {
total: unpublishTotal,
success: unpublishSuccess,
},
index: {
total: indexTotal,
success: indexSuccess,
},
};
};

Expand All @@ -241,6 +262,7 @@ export const getReport = async (results, action) => {
try {
const urlObj = new URL(result.url);
origin = urlObj.origin;
/* c8 ignore next 3 */
} catch (e) {
origin = result.url;
}
Expand All @@ -261,6 +283,9 @@ export const getReport = async (results, action) => {
if (result.status.publish === 200 || result.status.unpublish === 204) {
origins[origin].success += 1;
}
if (result.status.index === 200) {
origins[origin].success += 1;
}
});
const timestamp = new Date().toISOString();
const { email } = await getUser();
Expand Down
9 changes: 6 additions & 3 deletions libs/blocks/bulk-publish/bulk-publish.css
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ button:hover {
}

.bulk-status-preview,
.bulk-status-publish {
.bulk-status-publish,
.bulk-status-index {
width: 13%;
}

.bulk-status-publish span,
.bulk-status-preview span {
.bulk-status-preview span,
.bulk-status-index span {
display: block;
}

Expand All @@ -278,7 +280,8 @@ button:hover {
}

.bulk-status-publish.status-error .page-status,
.bulk-status-preview.status-error .page-status {
.bulk-status-preview.status-error .page-status,
.bulk-status-index.status-error .page-status {
color: var(--error-color);
font-weight: 700;
line-height: normal;
Expand Down
44 changes: 32 additions & 12 deletions libs/blocks/bulk-publish/bulk-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function SelectBtn({ actionElt, onSelectChange, storedOperationName }) {
<option value="preview&publish" selected="${storedOperationName === 'preview&publish'}">Preview & Publish</option>
<option value="unpublish" selected="${storedOperationName === 'unpublish'}">Unpublish</option>
<option value="unpublish&delete" selected="${storedOperationName === 'unpublish&delete'}">Delete</option>
<option value="index" selected="${storedOperationName === 'index'}">Index</option>
</select>
`;
}
Expand All @@ -61,8 +62,7 @@ function SubmitBtn({ submit }) {
`;
}

function prettyDate() {
const date = new Date();
function prettyDate(date = new Date()) {
const localeDate = date.toLocaleString();
const splitDate = localeDate.split(', ');
return html`
Expand All @@ -72,41 +72,47 @@ function prettyDate() {
}

function bulkPublishStatus(row) {
const status = row.status.publish !== 200
? `Error - Status: ${row.status.publish}`
: '';
return row.status.publish !== 200 && row.status.publish !== undefined && html`
const success = row.status.publish === 200;
const status = success ? '' : `Error - Status: ${row.status.publish}`;
return !success && row.status.publish !== undefined && html`
<span class=page-status>${status}</span>
`;
}

function bulkPreviewStatus(row) {
const status = row.status.preview !== 200
? `Error - Status: ${row.status.preview}`
: '';
const success = row.status.preview === 200;
const status = success ? '' : `Error - Status: ${row.status.preview}`;
return row.status.preview !== 200 && row.status.preview !== undefined && html`
<span class=page-status>${status}</span>
`;
}

function bulkDeleteStatus(row) {
const success = row.status.delete === 204;
const status = row.status.delete === 403
? 'Failed to Delete (Ensure the resource is deleted in SharePoint)'
: `Error - Status: ${row.status.delete}`;
return row.status.delete !== 204 && row.status.delete !== undefined && html`
return !success && row.status.delete !== undefined && html`
<span class=page-status>${status}</span>
`;
}

function bulkUnpublishStatus(row) {
const success = row.status.unpublish === 204;
const status = row.status.unpublish === 403
? 'Failed to Unpublish (Ensure the resource is deleted in SharePoint)'
: `Error - Status: ${row.status.unpublish}`;
return row.status.unpublish !== 204 && row.status.unpublish !== undefined && html`
return !success && row.status.unpublish !== undefined && html`
<span class=page-status>${status}</span>
`;
}

function bulkIndexStatus(row) {
const success = row.status.index === 200 || row.status.index === 202;
const status = success ? '' : `Error - Status: ${row.status.index}`;
return !success && row.status.index !== undefined && html`<span class=page-status>${status}</span>`;
}

function StatusTitle({ bulkTriggered, submittedAction, urlNumber }) {
const name = getActionName(submittedAction, true);
const URLS = (urlNumber > 1) ? 'URLS' : 'URL';
Expand All @@ -120,7 +126,7 @@ function StatusTitle({ bulkTriggered, submittedAction, urlNumber }) {
}

function StatusRow({ row }) {
const timeStamp = prettyDate();
const timeStamp = prettyDate(row?.timestamp);
const errorStyle = 'status-error';
const del = !!row.status.delete || !!row.status.unpublish;
const expectedStatus = del ? 204 : 200;
Expand All @@ -131,6 +137,8 @@ function StatusRow({ row }) {

const previewStatusError = previewStatus === expectedStatus ? '' : errorStyle;
const publishStatusError = publishStatus === expectedStatus ? '' : errorStyle;
const indexSuccess = row.status.index === 200 || row.status.index === 202;
const indexStatusError = indexSuccess ? '' : errorStyle;

return html`
<tr class="bulk-status-row">
Expand All @@ -141,6 +149,9 @@ function StatusRow({ row }) {
<td class="bulk-status-publish ${publishStatusError}">
${publishStatus === expectedStatus && timeStamp} ${pubStatus(row)}
</td>
<td class="bulk-status-index ${indexStatusError}">
${indexSuccess && timeStamp} ${bulkIndexStatus(row)}
</td>
</tr>
`;
}
Expand All @@ -150,6 +161,8 @@ function StatusContent({ resultsElt, result, submittedAction }) {
const displayClass = 'did-bulk';
const bulkPreviewed = name.includes('preview') || name === 'delete' ? displayClass : '';
const bulkPublished = name.includes('publish') || name === 'delete' ? displayClass : '';
const bulkIndexed = name.includes('index') ? displayClass : '';

const del = name === 'delete' || name === 'unpublish';
const headings = {
pre: del ? 'Deleted' : 'Previewed',
Expand All @@ -162,6 +175,7 @@ function StatusContent({ resultsElt, result, submittedAction }) {
<th>URL</th>
<th class="${bulkPreviewed}">${headings.pre}</th>
<th class="${bulkPublished}">${headings.pub}</th>
<th class="${bulkIndexed}">Indexed</th>
</tr>
${result.reverse().map((row) => html`<${StatusRow} row=${row} />`)}
`}
Expand Down Expand Up @@ -198,6 +212,12 @@ function StatusCompletion({ completion }) {
<li><span>Successful:</span> ${completion.unpublish.success} / ${completion.unpublish.total}</li>
</ul>
`}
${completion.index.total > 0 && html`
<ul class="bulk-job-index">
<li><span>Index Job Complete:</span> ${timeStamp}</li>
<li><span>Successful:</span> ${completion.index.success} / ${completion.index.total}</li>
</ul>
`}
</div>
</div>
`;
Expand Down
Loading

0 comments on commit 6dc7e32

Please sign in to comment.