Skip to content

Commit

Permalink
feat(options): do not use giturl anymore (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe authored Sep 9, 2024
1 parent 99db251 commit 08a4e50
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 117 deletions.
6 changes: 0 additions & 6 deletions src/extension/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "Es gibt noch keine Konfiguration, die exportiert werden kann"
},
"config_invalid_giturl": {
"message": "Ungültige Repository-URL"
},
"config_invalid_host": {
"message": "Ungültiger Host-Name"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "Lokale Entwicklungs-URL: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "Repository-URL: https://github.com/…"
},
"config_manual_host_placeholder": {
"message": "Produktions-Host-Name (optional)"
},
Expand Down
21 changes: 13 additions & 8 deletions src/extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@
"config_invalid_export": {
"message": "You don't have any configuration to export yet"
},
"config_invalid_giturl": {
"message": "Invalid repository URL"
},
"config_invalid_host": {
"message": "Invalid hostname"
},
"config_invalid_import": {
"message": "Choose a valid file to import"
},
"config_invalid_mountpoints": {
"message": "Invalid Content URL"
},
"config_invalid_import": {
"message": "Choose a valid file to import"
"config_invalid_org_site": {
"message": "Invalid org or site name"
},
"config_invalid_shareurl": {
"message": "Invalid sharing URL"
Expand All @@ -197,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "Local Development URL: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "Repository URL: https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "Production Hostname (optional)"
},
Expand All @@ -212,12 +209,20 @@
"config_manual_mountpoints_placeholder": {
"message": "Content URL: https://..."
},
"config_manual_org_placeholder": {
"message": "Organization Name",
"description": "Organization name as in the config service"
},
"config_manual_previewHost_placeholder": {
"message": "Custom Preview Hostname (optional)"
},
"config_manual_project_placeholder": {
"message": "Project Name (optional)"
},
"config_manual_site_placeholder": {
"message": "Site Name",
"description": "Site name as in the config service"
},
"config_manual_title": {
"message": "Add manually"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "Aún no tiene ninguna configuración para exportar"
},
"config_invalid_giturl": {
"message": "URL del repositorio no válida"
},
"config_invalid_host": {
"message": "Nombre de host no válido"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "URL de desarrollo local: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "URL del repositorio: https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "Nombre de host de producción (opcional)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "Vous n'avez pas encore de configuration à exporter."
},
"config_invalid_giturl": {
"message": "URL de référentiel non valide"
},
"config_invalid_host": {
"message": "Nom d’hôte non valide"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "URL de développement local : http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "URL du référentiel : https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "Nom d'hôte de production (facultatif)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "Non hai ancora alcuna configurazione da esportare"
},
"config_invalid_giturl": {
"message": "URL archivio non valido"
},
"config_invalid_host": {
"message": "Nome host non valido"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "URL di sviluppo locale: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "URL archivio: https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "Nome host di produzione (facoltativo)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "書き出す設定がまだありません"
},
"config_invalid_giturl": {
"message": "無効なリポジトリ URL"
},
"config_invalid_host": {
"message": "無効なホスト名"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "ローカル開発 URL : http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "リポジトリ URL : https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "実稼動ホスト名 (オプション)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "아직 내보낼 구성이 없습니다."
},
"config_invalid_giturl": {
"message": "잘못된 저장소 URL"
},
"config_invalid_host": {
"message": "잘못된 호스트 이름"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "로컬 개발 URL: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "저장소 URL: https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "프로덕션 호스트 이름(선택 사항)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "Ainda não há nenhuma configuração a ser exportada"
},
"config_invalid_giturl": {
"message": "URL de repositório inválido"
},
"config_invalid_host": {
"message": "Nome de host inválido"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "URL de desenvolvimento local: http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "URL do repositório: https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "Hostname de produção (opcional)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "您还没有任何可导出的配置"
},
"config_invalid_giturl": {
"message": "无效的存储库 URL"
},
"config_invalid_host": {
"message": "无效主机名"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "本地开发 URL:http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "存储库 URL:https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "生产主机名称(可选)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
"config_invalid_export": {
"message": "您還沒有任何可匯出的設定"
},
"config_invalid_giturl": {
"message": "存放庫 URL 無效"
},
"config_invalid_host": {
"message": "主機名稱無效"
},
Expand All @@ -200,9 +197,6 @@
"config_manual_devOrigin_placeholder": {
"message": "本機開發 URL:http://localhost:3000"
},
"config_manual_giturl_placeholder": {
"message": "存放庫 URL:https://github.com/..."
},
"config_manual_host_placeholder": {
"message": "生產主機名稱 (選填)"
},
Expand Down
6 changes: 0 additions & 6 deletions src/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ async function getConfigFromTabUrl(tabUrl) {
...getGitHubSettings(share.giturl),
giturl: undefined,
};
} else if (tabUrl.startsWith(GH_URL)) {
// github url
return {
...share,
...getGitHubSettings(tabUrl),
};
} else {
try {
// check if hlx.page, hlx.live, aem.page or aem.live url
Expand Down
10 changes: 6 additions & 4 deletions src/extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<div id="configEditor" class="config">
<div>
<p><input type="text" id="edit-project"></p>
<p class="mandatory"><input type="url" id="edit-giturl"></p>
<p class="mandatory"><input type="url" id="edit-org"></p>
<p class="mandatory"><input type="url" id="edit-site"></p>
<p class="mandatory"><input type="url" id="edit-mountpoints"></p>
<p class="advanced-only"><input type="text" id="edit-previewHost"></p>
<p class="advanced-only"><input type="text" id="edit-liveHost"></p>
Expand Down Expand Up @@ -65,15 +66,16 @@ <h2>__MSG_config_projects__
<div>
<h3>__MSG_config_shareurl_title__</h3>
<p class="help">__MSG_config_shareurl_description__</p>
<p class="mandatory"><input type="url" id="shareurl" placeholder="__MSG_config_shareurl_placeholder__"></p>
<p class="mandatory"><input type="url" id="add_shareurl" placeholder="__MSG_config_shareurl_placeholder__"></p>
<p><button id="addShareConfigButton" title="__MSG_add__">__MSG_add__</button></p>
</div>
</div>
<div>
<div>
<h3>__MSG_config_manual_title__</h3>
<p class="mandatory"><input type="url" id="giturl" placeholder="__MSG_config_manual_giturl_placeholder__"></p>
<p><input type="text" id="project" placeholder="__MSG_config_manual_project_placeholder__"></p>
<p class="mandatory"><input type="text" id="add_org" placeholder="__MSG_config_manual_org_placeholder__"></p>
<p class="mandatory"><input type="text" id="add_site" placeholder="__MSG_config_manual_site_placeholder__"></p>
<p><input type="text" id="add_project" placeholder="__MSG_config_manual_project_placeholder__"></p>
<p><button id="addManualConfigButton" title="__MSG_add__">__MSG_add__</button></p>
</div>
</div>
Expand Down
41 changes: 23 additions & 18 deletions src/extension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import {
MANIFEST,
getState,
getGitHubSettings,
isValidShareURL,
getShareSettings,
i18n,
Expand All @@ -33,11 +32,6 @@ function getInnerHost(owner, repo, ref) {
return `${ref}--${repo}--${owner}.hlx.page`;
}

function isValidGitHubURL(giturl) {
return giturl.startsWith('https://github.com/')
&& Object.keys(getGitHubSettings(giturl)).length === 3;
}

function isValidMountpoint(mountpoints) {
return !mountpoints.some((mountpoint) => mountpoint.trim() === '');
}
Expand Down Expand Up @@ -225,7 +219,8 @@ function editProject(i) {
}
};
const save = async () => {
const giturl = document.querySelector('#edit-giturl').value;
const org = document.querySelector('#edit-org').value;
const site = document.querySelector('#edit-site').value;
const mountpoints = [
document.querySelector('#edit-mountpoints').value,
];
Expand All @@ -234,9 +229,9 @@ function editProject(i) {
window.alert(i18n('config_invalid_mountpoints'));
return;
}
if (!isValidGitHubURL(giturl)) {
if (!org && !site) {
// eslint-disable-next-line no-alert
window.alert(i18n('config_invalid_giturl'));
window.alert(i18n('config_invalid_org_site'));
return;
}
const host = document.querySelector('#edit-host').value;
Expand All @@ -256,7 +251,8 @@ function editProject(i) {
}

const input = {
giturl: document.querySelector('#edit-giturl').value,
owner: org,
repo: site,
mountpoints,
project: document.querySelector('#edit-project').value,
previewHost,
Expand Down Expand Up @@ -288,7 +284,14 @@ function editProject(i) {
document.getElementById(`config-${i}`).replaceWith(editorFragment);
// pre-fill form
document.querySelectorAll('#configEditor input').forEach((field) => {
const key = field.id.split('-')[1];
const fieldId = field.id.split('-')[1];
let key = fieldId;
if (fieldId === 'org') {
key = 'owner';
}
if (fieldId === 'site') {
key = 'repo';
}
const value = project[key];
if (typeof value === 'object') {
field.value = value[0] || '';
Expand All @@ -297,7 +300,7 @@ function editProject(i) {
} else {
field.value = project[key] || '';
}
field.setAttribute('placeholder', i18n(`config_manual_${key}_placeholder`));
field.setAttribute('placeholder', i18n(`config_manual_${fieldId}_placeholder`));
const label = document.querySelector(`#configEditor label[for="${field.id}"]`);
if (label) {
label.textContent = i18n(`config_manual_${key}`) || label.textContent;
Expand Down Expand Up @@ -384,7 +387,7 @@ window.addEventListener('DOMContentLoaded', () => {
});

document.getElementById('addShareConfigButton').addEventListener('click', async () => {
const shareurl = document.getElementById('shareurl').value;
const shareurl = document.getElementById('add_shareurl').value;
// check share url
if (isValidShareURL(shareurl)) {
await addProject(getShareSettings(shareurl), (added) => {
Expand All @@ -400,11 +403,13 @@ window.addEventListener('DOMContentLoaded', () => {
});

document.getElementById('addManualConfigButton').addEventListener('click', async () => {
const giturl = document.getElementById('giturl').value;
if (isValidGitHubURL(giturl)) {
const org = document.getElementById('add_org').value;
const site = document.getElementById('add_site').value;
if (org && site) {
await addProject({
giturl,
project: document.getElementById('project').value,
owner: org,
repo: site,
project: document.getElementById('add_project').value,
}, (added) => {
if (added) {
drawProjects();
Expand All @@ -413,7 +418,7 @@ window.addEventListener('DOMContentLoaded', () => {
});
} else {
// eslint-disable-next-line no-alert
window.alert(i18n('config_invalid_giturl'));
window.alert(i18n('config_invalid_org_site'));
}
});

Expand Down
Loading

0 comments on commit 08a4e50

Please sign in to comment.