From c5f69e5de4c01de73b5ac3349bf0b61ccd81d62e Mon Sep 17 00:00:00 2001 From: Sartxi Date: Wed, 29 May 2024 11:38:33 -0600 Subject: [PATCH 1/5] render links --- libs/blocks/locui/status/view.js | 19 +++++++++++++++---- libs/blocks/locui/utils/miloc.js | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/blocks/locui/status/view.js b/libs/blocks/locui/status/view.js index 28dfdbf362..e038f09d08 100644 --- a/libs/blocks/locui/status/view.js +++ b/libs/blocks/locui/status/view.js @@ -5,11 +5,22 @@ function toggleDesc(e) { e.target.closest('.locui-status-toast').classList.toggle('open'); } -function renderMessage(description) { +export function renderLinks(str) { + const linkPattern = /\[(.*?)\]\((.*?)\)/g; + const link = linkPattern.exec(str); + if (link) { + const message = str.replace(linkPattern, ''); + const [text, href] = link.slice(1); + return html`${message.slice(0, -1)} ${text}`; + } + return str; +} + +function renderDescription(description) { let message = description; if (Array.isArray(description) && description.length > 1) { - message = html`
    ${description.map((desc) => html`
  1. ${desc}
  2. `)}
`; - } + message = html`
    ${description.map((desc) => html`
  1. ${renderLinks(desc)}
  2. `)}
`; + } else return renderLinks(message[0]); return message; } @@ -23,7 +34,7 @@ function Toast({ status }) { ${status.description && html`
Expand
`} ${status.description && html` -

${renderMessage(status.description)}

`} +

${renderDescription(status.description)}

`} `; } diff --git a/libs/blocks/locui/utils/miloc.js b/libs/blocks/locui/utils/miloc.js index c910a36bc7..efdf48646a 100644 --- a/libs/blocks/locui/utils/miloc.js +++ b/libs/blocks/locui/utils/miloc.js @@ -52,6 +52,10 @@ export async function getProjectStatus() { setStatus('service-error'); } + if (json.projectStatus === 'not-found') { + setStatus('service-error', 'error', json.projectStatusText); + } + if (json.projectStatus === 'sync') { allowSyncToLangstore.value = false; } From 8a46f7dbf9b8d8fb1a3d6b159a0d86a9a88068a1 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Wed, 29 May 2024 12:48:13 -0600 Subject: [PATCH 2/5] render links in language error modal --- libs/blocks/locui/langs/modal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/blocks/locui/langs/modal.js b/libs/blocks/locui/langs/modal.js index bf35931191..9cfa2e9a78 100644 --- a/libs/blocks/locui/langs/modal.js +++ b/libs/blocks/locui/langs/modal.js @@ -2,6 +2,7 @@ import { html, render } from '../../../deps/htm-preact.js'; import { urls } from '../utils/state.js'; import Url from '../url/view.js'; import { origin } from '../utils/franklin.js'; +import { renderLinks } from '../status/view.js'; function Modal({ lang, prefix, error }) { const localeUrls = urls.value.map( @@ -13,7 +14,7 @@ function Modal({ lang, prefix, error }) { return html`

${statusText}

Errors reported for ${lang.Language}:

-
    ${errors.map((err) => html`
  1. ${err}
  2. `)}
+
    ${errors.map((err) => html`
  1. ${renderLinks(err)}
  2. `)}
`; } From 8aacac76fef7555a9f92cbcfb09326cbc10f5560 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Wed, 29 May 2024 15:22:00 -0600 Subject: [PATCH 3/5] refine after testing --- libs/blocks/locui/status/view.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/blocks/locui/status/view.js b/libs/blocks/locui/status/view.js index e038f09d08..545b100a9b 100644 --- a/libs/blocks/locui/status/view.js +++ b/libs/blocks/locui/status/view.js @@ -9,9 +9,14 @@ export function renderLinks(str) { const linkPattern = /\[(.*?)\]\((.*?)\)/g; const link = linkPattern.exec(str); if (link) { - const message = str.replace(linkPattern, ''); + const msg = str.replace(linkPattern, ''); const [text, href] = link.slice(1); - return html`${message.slice(0, -1)} ${text}`; + return html` + + ${msg.substring(0, link.index)} + ${text} + ${msg.substring(link.index, msg.length)} + `; } return str; } From 496e74bbf4dadf2234c44c1a02eead0fc5541fbf Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 3 Jun 2024 09:37:29 -0600 Subject: [PATCH 4/5] adjust disabled --- libs/blocks/locui/url/tabs.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/blocks/locui/url/tabs.js b/libs/blocks/locui/url/tabs.js index e6211a81cc..6c5220114e 100644 --- a/libs/blocks/locui/url/tabs.js +++ b/libs/blocks/locui/url/tabs.js @@ -11,19 +11,19 @@ function Actions({ item }) { const isDisabled = (status) => (!status || status !== 200 ? ' disabled' : ''); const itemUrl = urls.value.find((url) => url.pathname === item.value.path || url.langstore.pathname === item.value.path); - const disableExcel = itemUrl?.valid !== undefined && !itemUrl.valid; + const disabled = itemUrl?.valid !== undefined && !itemUrl.valid; return html`
+ class="locui-url-action locui-url-action-edit${isExcel}${disabled ? ' disabled' : ''}" + onClick=${(e) => { if (!disabled) openWord(e, item); }}>Edit + onClick=${(e) => { if (!disabled) handleAction(e, item, true); }}>Preview + onClick=${(e) => { if (!disabled) handleAction(e, item); }}>Live
`; } From b0eeff91a851a4282a7d25a5ba0b02c618dd375e Mon Sep 17 00:00:00 2001 From: Sartxi Date: Mon, 3 Jun 2024 12:09:49 -0600 Subject: [PATCH 5/5] check for validation before throwing error --- libs/blocks/locui/actions/view.js | 2 +- libs/blocks/locui/loc/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/blocks/locui/actions/view.js b/libs/blocks/locui/actions/view.js index 55c2d728d0..f3550cb98b 100644 --- a/libs/blocks/locui/actions/view.js +++ b/libs/blocks/locui/actions/view.js @@ -19,7 +19,7 @@ import { } from './index.js'; export default function Actions() { - const hasErrors = urls.value.filter((url) => !url.valid)?.length > 0; + const hasErrors = urls.value.filter((url) => url.valid !== undefined && !url.valid)?.length > 0; const canAct = allowSyncToLangstore.value || allowSendForLoc.value || allowRollout.value diff --git a/libs/blocks/locui/loc/index.js b/libs/blocks/locui/loc/index.js index f61a23b45a..4c7c8a0fd7 100644 --- a/libs/blocks/locui/loc/index.js +++ b/libs/blocks/locui/loc/index.js @@ -104,7 +104,7 @@ async function loadDetails() { setStatus('details', 'info', 'Validating Project Configuration'); urls.value = await validatedUrls(projectUrls); if (json.settings) loadProjectSettings(json.settings.data); - const errors = urls.value.filter((url) => !url.valid); + const errors = urls.value.filter((url) => url.valid !== undefined && !url.valid); if (errors?.length > 0) { setStatus('details', 'error', 'Invalid URLs.', errors.map((url) => (`${url.href} was not found.`))); } else {