Skip to content

Commit

Permalink
MWPW-162929: Implements qa feedback and other improvements (#3299)
Browse files Browse the repository at this point in the history
* Sets Auto Select for cotentType as default

* Adds beta link to original bulkpublisher

* Implements qa feedback and other imnprovements

* ESlint errors

* Implements previous PR review comments

* Fixes ESLint errors

---------

Co-authored-by: milo-pr-merge[bot] <169241390+milo-pr-merge[bot]@users.noreply.github.com>
  • Loading branch information
cmiqueo and milo-pr-merge[bot] authored Dec 10, 2024
1 parent cc05e05 commit e38ff7c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 52 deletions.
95 changes: 50 additions & 45 deletions tools/send-to-caas/bulk-publish-to-caas.beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
import comEnterpriseToCaasTagMap from './comEnterpriseToCaasTagMap.js';

const BODY = document.body;
const SIGNEDIN = BODY.querySelector('.status-signed-in');
const SIGNEDOUT = BODY.querySelector('.status-signed-out');
const SIGNEDIN_EL = BODY.querySelector('.status-signed-in');
const SIGNEDOUT_EL = BODY.querySelector('.status-signed-out');

const LS_KEY = 'bulk-publish-caas';
const FIELDS = ['presetSelector', 'host', 'repo', 'owner', 'caasEnvSelector', 'urls', 'contentType', 'publishToFloodgate'];
const FIELDS = ['presetSelector', 'host', 'repo', 'owner', 'caasEnv', 'urls', 'contentType', 'publishToFloodgate'];
const FIELDS_CB = ['draftOnly', 'useHtml', 'usePreview'];
const DEFAULT_VALUES = {
preset: 'default',
Expand Down Expand Up @@ -246,15 +246,14 @@ const processData = async (data, accessToken) => {
errorArr.push([pageUrl, response]);
}
} catch (e) {
// eslint-disable-next-line no-console
console.log(`ERROR: ${e.message}`);
errorArr.push(['Error:', e.message]);
}
}

if (statusModal.modal) statusModal.close();

SIGNEDIN.style.display = 'none';
SIGNEDOUT.style.display = 'none';
SIGNEDIN_EL.style.display = 'none';
SIGNEDOUT_EL.style.display = 'none';
resetResultsTables();
if (successArr.length) {
showSuccessTable(successArr);
Expand Down Expand Up @@ -307,55 +306,53 @@ const loadFromLS = () => {
const publishWarning = document.querySelector('.publish-warning');
const checkCaasEnv = () => {
// eslint-disable-next-line no-undef
const caasEnvValue = caasEnvSelector.value || 'prod';
// eslint-disable-next-line no-undef
if (caasEnvValue === 'prod' && !draftOnly.checked) {
if (caasEnv.value === 'prod' && !draftOnly.checked) {
publishWarning.style.height = '30px';
} else {
publishWarning.style.height = '0';
}
};

// preset options
// presets options
const presetsJsonPath = 'https://milo.adobe.com/drafts/caas/bppresets.json';
let presetsData = {};

fetchExcelJson(presetsJsonPath).then((presets) => {
const separator = document.querySelector('.separator');
const parent = separator.parentElement;
presetsData = presets;
presets.forEach((preset) => {
const option = document.createElement('option');
option.value = preset.repo;
option.text = `${preset.name} (${preset.repo})`;
parent.insertBefore(option, separator);
const getPresetsData = async () => {
fetchExcelJson(presetsJsonPath).then((presets) => {
const separator = document.querySelector('.separator');
const parent = separator.parentElement;
presetsData = presets;
presets.forEach((preset) => {
const option = document.createElement('option');
option.value = preset.repo;
option.text = `${preset.name} (${preset.repo})`;
parent.insertBefore(option, separator);
});
});
});
};

const resetAdvancedOptions = () => {
/* eslint-disable no-undef */
caasEnvSelector.value = 'prod';
caasEnv.value = 'prod';
contentType.value = 'auto';
draftOnly.checked = false;
useHtml.checked = false;
usePreview.checked = false;
publishToFloodgate.value = 'default';
/* eslint-enable no-undef */
};

/* eslint-disable no-nested-ternary */
const useDarkTheme = localStorage.getItem('bp-theme') === 'dark'
? true
: localStorage.getItem('bp-theme') === 'light'
? false
: window.matchMedia('(prefers-color-scheme: dark)').matches;
/* eslint-enable no-nested-ternary */

if (useDarkTheme) {
document.querySelector('.bulk-publisher').classList.add('dark');
document.querySelector('#option-dark').checked = true;
} else {
document.querySelector('#option-light').checked = true;
}
const setTheme = () => {
const theme = localStorage.getItem('bp-theme');
const useDarkTheme = theme === 'dark'
|| (theme !== 'light' && window.matchMedia('(prefers-color-scheme: dark)').matches);

if (useDarkTheme) {
document.querySelector('.bulk-publisher').classList.add('dark');
document.querySelector('#option-dark').checked = true;
} else {
document.querySelector('#option-light').checked = true;
}
};

// eslint-disable-next-line no-undef
presetSelector.addEventListener('change', () => {
Expand All @@ -378,11 +375,17 @@ presetSelector.addEventListener('change', () => {
const ls = localStorage.getItem(LS_KEY);
const config = ls ? JSON.parse(ls) : {};
config.presetSelector = selectedPreset.id || 'default';
// eslint-disable-next-line no-undef
config.caasEnv = caasEnv.value;
config.host = selectedPreset.host || '';
config.owner = selectedPreset.owner || '';
config.repo = selectedPreset.repo || '';
config.contentType = selectedPreset.contentType;
config.useHtml = selectedPreset.useHtml === 'true';
if (selectedPreset.contentType === '' || selectedPreset.contentType?.toLowerCase() === 'auto') {
config.contentType = 'auto';
} else {
config.contentType = selectedPreset.contentType;
}

setConfig(config);
window.localStorage.setItem(LS_KEY, JSON.stringify(getConfig()));
Expand All @@ -395,11 +398,11 @@ const clearResultsButton = document.querySelector('.clear-results');
clearResultsButton.addEventListener('click', () => {
resetResultsTables();
clearResultsButton.style.display = 'none';
SIGNEDIN.style.display = 'block';
SIGNEDIN_EL.style.display = 'block';
});

// eslint-disable-next-line no-undef
caasEnvSelector.addEventListener('change', () => {
caasEnv.addEventListener('change', () => {
checkCaasEnv();
});

Expand All @@ -412,10 +415,10 @@ const checkUserStatus = async () => {
const accessToken = await checkIms(false);
if (accessToken) {
document.querySelector('.status-checking').style.display = 'none';
SIGNEDIN.style.display = 'block';
SIGNEDIN_EL.style.display = 'block';
} else {
document.querySelector('.status-checking').style.display = 'none';
SIGNEDOUT.style.display = 'block';
SIGNEDOUT_EL.style.display = 'block';
}
return true;
};
Expand Down Expand Up @@ -457,7 +460,7 @@ helpButtons.forEach((btn) => {

case 'content-type-fallback':
showAlert(`<p><b>ContentType Fallback</b></p>
<p>This is the <b>content-type</b> tag that will be applied to all cards that do not have
<p>This is the <b>content-type</b> tag that will be applied to all cards that do not have
a specific <b>content-type</b> tag included in their metadata.</p>`);
break;

Expand Down Expand Up @@ -485,7 +488,7 @@ helpButtons.forEach((btn) => {
case 'use-preview':
showAlert(`<p><b>Use Preview Content</b>
<p>When this option is checked, the tool will publish content from:
<p><tt>https://main--{repo}--{owner}.hlx.<b>page</b></tt>
<p><tt>https://stage--{repo}--{owner}.hlx.<b>page</b></tt>
<p>This can be useful for testing before publishing to production.</p>`);
break;

Expand All @@ -510,6 +513,8 @@ themeOptions.forEach((btn) => {
});

const init = async () => {
setTheme();
await getPresetsData();
await loadTingleModalFiles(loadScript, loadStyle);
await loadCaasTags();
loadFromLS();
Expand All @@ -532,7 +537,7 @@ const init = async () => {
host: document.getElementById('host').value,
project: '',
branch: 'main',
caasEnv: document.getElementById('caasEnvSelector').value || 'prod',
caasEnv: document.getElementById('caasEnv').value || 'prod',
contentType: document.getElementById('contentType').value,
repo: document.getElementById('repo').value,
owner: document.getElementById('owner').value,
Expand Down
4 changes: 2 additions & 2 deletions tools/send-to-caas/bulkpublish.beta.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ body {

.main {
display: flex;
height: calc(100% - 126px);
min-height: calc(100% - 126px);
}

.bulk-publisher .title {
Expand All @@ -58,7 +58,7 @@ body {
background: linear-gradient(45deg, #aaa, #eee);
border-right: solid 1px #aaa;
overflow-y: auto;
height: 100%;
min-height: 100%;
}

dd.content {
Expand Down
10 changes: 5 additions & 5 deletions tools/send-to-caas/bulkpublisher.beta.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ <h5 class="basic-settings">Basic Settings</h5>
<h4>Advanced Options</h4>

<div class="field">
<label for="caasEnvSelector">CaaS Enviroment<span class="help caas-env" title="Help about this functionality">(?)</span></label>
<select name="caasEnvSelector" id="caasEnvSelector">
<label for="caasEnv">CaaS Enviroment<span class="help caas-env" title="Help about this functionality">(?)</span></label>
<select name="caasEnv" id="caasEnv">
<option value="dev">Dev</option>
<option value="stage">Stage</option>
<option value="prod" selected>Production</option>
Expand All @@ -62,7 +62,7 @@ <h4>Advanced Options</h4>
<div class="field">
<label for="contentType">ContentType Fallback: <span class="help content-type-fallback" title="Help about this functionality">(?)</span></label>
<select name="contentType" id="contentType">
<option value="">Auto Detect</option>
<option value="auto">Auto Detect</option>
<option value="caas:content-type/announcements">Announcements</option>
<option value="caas:content-type/application">Application</option>
<option value="caas:content-type/article">Article</option>
Expand Down Expand Up @@ -132,7 +132,7 @@ <h4>Advanced Options</h4>
</div>
<div id="use-preview-cb" class="field checkbox">
<input type="checkbox" id="usePreview" name="usePreview" />
<label for="usePreview">Use Preview Content <span class="help use-preview" title="Help about this functionality">(?)</span></label>
<label for="usePreview">Use Preview Content (*.page)<span class="help use-preview" title="Help about this functionality">(?)</span></label>
</div>
<!--
<div class="field">
Expand All @@ -153,7 +153,7 @@ <h4>Advanced Options</h4>

<div class="urls">
<h2>URLs</h2>
<p>Note: This tool is in <b>BETA</b> stage. Please report any issues in the <b>#javelin-friends</b> channel on Slack.</p>
<p><i><b>Note</b>: This tool is in <b>BETA</b> stage. Please report any issues in the <b>#javelin-friends</b> channel on Slack.</i></p>
<p>Enter a URL or list of URLs, each on a separate line, to be sent to CaaS.</p>
<textarea id="urls"
name="urls"
Expand Down
20 changes: 20 additions & 0 deletions tools/send-to-caas/bulkpublisher.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@
<head>
<link rel="stylesheet" href="/libs/ui/controls/accordion.css" />
<link rel="stylesheet" href="./bulkpublish.css" />
<style>
.bpv2 {
background: linear-gradient(90deg, #6F9B0033, #6F9B00);
font-family: system-ui, sans-serif;
text-align: right;
padding: 8px;
color: white;
animation: slide-bg 1.5s;
}
.bpv2 a {
color: white;
}
@keyframes slide-bg {
from {background-position: -1600px}
to {background-position: 0}
}
</style>
</head>

<body>
<div class="bulk-publisher">
<p class="bpv2">
Try the new <a href="./bulkpublisher.beta.html">CaaS Bulk Publisher v2 (Beta)</a>
</p>
<div class="main">
<div class="options-panel">
<dt class="title is-expanded">
Expand Down

0 comments on commit e38ff7c

Please sign in to comment.