Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region selector #556

Merged
merged 33 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2bcaba4
Adding tool button.
seanchoi-dev Mar 8, 2023
99a6c52
Merge branch 'main' into region-selector
seanchoi-dev Mar 9, 2023
fedd071
WIP
seanchoi-dev Mar 9, 2023
53786d4
wip
seanchoi-dev Mar 10, 2023
a4aa9fb
for testing.
seanchoi-dev Mar 10, 2023
ae741c9
For testing
seanchoi-dev Mar 11, 2023
dd598c4
Fixing few stuff after testing.
seanchoi-dev Mar 12, 2023
98a289c
Adjust palette size, change div to ol
seanchoi-dev Mar 12, 2023
5df9d01
Sort the locale array alphabetically.
seanchoi-dev Mar 12, 2023
497f1f3
nit: little refactoring.
seanchoi-dev Mar 12, 2023
d4cecf2
UI/UX update.
seanchoi-dev Mar 13, 2023
ca0dd1b
remove white bg
seanchoi-dev Mar 13, 2023
49797c8
Added guide line for each item
seanchoi-dev Mar 13, 2023
8050153
Fail condition added.
seanchoi-dev Mar 13, 2023
0afb4bb
Merge branch 'main' into region-selector
seanchoi-dev Mar 15, 2023
942dad8
Update libs/blocks/region-selector-loader/region-selector-loader.js
seanchoi-dev Mar 15, 2023
1460647
Print result alphabetically.
seanchoi-dev Mar 15, 2023
5b8a24a
nit: update getAttribute('data-locale') to dataset.locale
seanchoi-dev Mar 15, 2023
40b30ce
Merge branch 'main' into region-selector
seanchoi-dev Mar 15, 2023
5118f69
Color code added for un-previewed webPath.
seanchoi-dev Mar 15, 2023
17b6a27
Updated style as Rikkio and Ryan agreed.
seanchoi-dev Mar 15, 2023
2d5dfe1
Taking off the test code.
seanchoi-dev Mar 15, 2023
8b6f20d
UI/UX update and enabling it on pages as well.
seanchoi-dev Mar 16, 2023
0c380db
Renaming the block
seanchoi-dev Mar 16, 2023
58981d6
Taking off the test urls
seanchoi-dev Mar 16, 2023
1cfe3b8
Added search.
seanchoi-dev Mar 16, 2023
b4fff8a
Matching the search bar size as icons.
seanchoi-dev Mar 16, 2023
b7b29bf
Fixed the set logic.
seanchoi-dev Mar 16, 2023
f5cca62
Polish (#575)
auniverseaway Mar 17, 2023
44ba0dd
Fix security issue
auniverseaway Mar 17, 2023
e93de8f
Merge branch 'main' into region-selector
auniverseaway Mar 17, 2023
5830687
Fix security issue
auniverseaway Mar 17, 2023
24270a0
Merge branch 'region-selector' of github.com:adobecom/milo into regio…
auniverseaway Mar 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/blocks/locale-nav/img/aec-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions libs/blocks/locale-nav/img/word-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions libs/blocks/locale-nav/locale-nav.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
.in-page {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

/*
Common styles for the block region selector loader
*/

.locale-nav {
width: 360px;
height: 360px;
overflow: scroll;
background-color: #303030;
color: #fff;
font-size: 0.875rem;
}

.sk-header {
background: rgb(0 0 0 / 35%);
display: flex;
justify-content: space-between;
padding: 0 12px;
line-height: 36px;
text-transform: uppercase;
font-weight: 700;
}

.actions {
display: grid;
gap: 12px;
grid-template-columns: 48px 60px 60px;
text-align: center;
}

.detail {
display: flex;
justify-content: space-between;
padding: 0 12px;
line-height: 72px;
font-size: 1.125rem;
text-transform: uppercase;
}

.action {
display: inline-block;
overflow: hidden;
text-indent: -1000px;
}

.action.edit {
background: url('./img/word-icon.svg') center / 26px no-repeat;
}

.action.preview, .action.live {
background: url('./img/aec-icon.svg') center / 26px no-repeat;
}

.status-404 {
opacity: 0.25;
pointer-events: none;
}

/* Locale List */
ul.locales {
margin: 0;
padding: 0;
list-style: none;
}

.locale-search-wrapper {
position: relative;
}

.locale-search {
width: 100%;
display: block;
font-family: var(--body-font-family);
background: rgb(0 0 0 / 35%);
border: none;
margin: 0;
padding: 0 12px;
line-height: 36px;
text-transform: uppercase;
font-weight: 700;
color: #FFF;
box-sizing: border-box;
transition: padding .2s ease-in-out;
}

.locale-search-icon {
position: absolute;
content: '';
width: 36px;
height: 36px;
left: -36px;
top: 0;
background: url('/libs/ui/img/spectrum-search.svg') center / 24px no-repeat;
transition: left .2s ease-in-out;
}

.locale-search:hover + .locale-search-icon, .locale-search:focus + .locale-search-icon {
left: 6px;
}

.locale-search:hover, .locale-search:focus {
padding: 0 42px;
}

.locale-search::placeholder {
color: #FFF;
}

.locale-search:focus::placeholder {
color: #676767;
}
107 changes: 107 additions & 0 deletions libs/blocks/locale-nav/locale-nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { createTag, getConfig, getLocale } from '../../utils/utils.js';

const { locales } = getConfig();

const params = new URLSearchParams(window.location.search);
const referrer = params.get('referrer');
const owner = params.get('owner');
const repo = params.get('repo');

const formatJson = (json) => {
const { pathname } = new URL(json.preview.url);
const locale = getLocale(locales, pathname);
const editHref = json.edit.url ? json.edit.url : '#';
return {
locale,
pathname,
edit: createTag('a', { class: `edit action status-${json.edit.status}`, href: editHref, target: '_blank', title: 'Edit' }, 'Edit'),
preview: createTag('a', { class: `preview action status-${json.preview.status}`, href: json.preview.url, target: '_blank', title: 'Preview' }, 'Preview'),
live: createTag('a', { class: `live action status-${json.live.status}`, href: json.live.url, target: '_blank', title: 'Live' }, 'Live'),
};
};

const getDetails = async (path) => {
const url = path
? `https://admin.hlx.page/status/${owner}/${repo}/main${path}?editUrl=auto`
: `https://admin.hlx.page/status/${owner}/${repo}/main?editUrl=${referrer}`;
try {
const res = await fetch(url);
const json = await res.json();
return formatJson(json);
} catch (e) {
return false;
}
};

const getCurrentDetails = async () => {
const { origin, pathname } = new URL(referrer);
const split = origin.split('.');
const topLevel = split.slice(Math.max(split.length - 2, 1)).join('.');
const isEdit = topLevel === 'google.com' || topLevel === 'sharepoint.com';
return isEdit ? getDetails() : getDetails(pathname);
}

const getStatus = async (li, localePath) => {
const page = await getDetails(localePath);
const actions = createTag('div', { class: 'actions' }, [page.edit, page.preview, page.live]);
li.append(actions);
};

const decorateLocales = (current) => {
const currLocale = current.locale.prefix.replace('/', '');
delete locales[currLocale];
return Object.keys(locales).map((key) => {
const prefix = key === '' ? key : `/${key}`;
const localePath = currLocale === ''
? `/${key}${current.pathname}`
: current.pathname.replace(current.locale.prefix, prefix);
const li = createTag('li', { class: 'detail' }, `<span>${key || 'us'}</span>`);
getStatus(li, localePath);
return li;
});
};

const handleSearch = (e, els) => {
const search = e.target.value;
els.forEach((subject) => {
if (subject.textContent.includes(search)) {
subject.style.display = 'flex';
} else {
subject.style.display = 'none';
}
});
};

const decorateSearch = (el, current) => {
const search = createTag('input', { class: 'locale-search', placeholder: 'Locales' });
const icon = createTag('div', { class: 'locale-search-icon' });
const wrapper = createTag('div', { class: 'locale-search-wrapper' }, [search, icon]);
const localeEls = decorateLocales(current);
const list = createTag('ul', { class: 'locales' }, localeEls);
search.addEventListener('keyup', (e) => { handleSearch(e, localeEls); });
el.append(wrapper, list);
};

const decorateHeader = (el, page) => {
const currentHeading = createTag('span', null, 'Current');
const actionsText = '<span>Edit</span><span>Preview</span><span>Live</span>';
const actionsHeading = createTag('div', { class: 'actions' }, actionsText);
const header = createTag('div', { class: 'sk-header' });
header.append(currentHeading, actionsHeading);
const currentLocale = page.locale.prefix.replace('/', '') || 'us';
const currentPage = createTag('div', { class: 'current-page detail' }, `<span>${currentLocale}</span>`);
const currentActions = createTag('div', { class: 'actions' }, [page.edit, page.preview, page.live]);
currentPage.append(currentActions);
el.append(header, currentPage);
};

function detectContext() {
if (window.self === window.top) document.body.classList.add('in-page');
}

export default async function init(el) {
detectContext();
const current = await getCurrentDetails();
decorateHeader(el, current);
decorateSearch(el, current);
}
40 changes: 31 additions & 9 deletions tools/sidekick/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
],
"plugins": [
{
"id": "library",
"title": "Library",
"environments": [ "edit" ],
"isPalette": true,
"paletteRect": "top: auto; bottom: 25px; left: 25px; height: 388px; width: 360px;",
"url": "/tools/library",
"includePaths": [ "**.docx**" ]
},
{
"id": "tools",
"title": "Tools",
"isContainer": true
},
{
"containerId": "tools",
"id": "localize",
"title": "Localize",
"environments": [ "edit" ],
Expand All @@ -18,6 +33,7 @@
"includePaths": [ "**/:x**" ]
},
{
"containerId": "tools",
"id": "floodgate",
"title": "Floodgate",
"environments": [ "edit" ],
Expand All @@ -27,33 +43,39 @@
"includePaths": [ "**/:x**" ]
},
{
"containerId": "tools",
"title": "Send to CaaS",
"id": "sendtocaas",
"environments": ["dev","preview", "live", "prod"],
"event": "send-to-caas",
"excludePaths": ["/tools/caas**", "*.json"]
},
{
"containerId": "tools",
"title": "Check Schema",
"id": "checkschema",
"environments": ["prod"],
"event": "check-schema",
"excludePaths": ["/tools**", "*.json"]
},
{
"id": "library",
"title": "Library",
"environments": [ "edit" ],
"isPalette": true,
"paletteRect": "top: auto; bottom: 20px; left: 20px; height: 398px; width: 360px;",
"url": "/tools/library",
"includePaths": [ "**.docx**" ]
},
{
"containerId": "tools",
"title": "Preflight",
"id": "preflight",
"environments": ["dev", "preview", "live"],
"event": "preflight"
},
{
"containerId": "tools",
"id": "locales",
"title": "Locales",
"environments": [ "edit", "dev", "preview", "live" ],
"isPalette": true,
"passConfig": true,
"passReferrer": true,
"paletteRect": "top: auto; bottom: 25px; left: 75px; height: 388px; width: 360px;",
"url": "/tools/locale-nav",
"includePaths": [ "**.docx**" ]
}
]
}