From 689d0046ade833e262dd8bdbecf7596566ad0afb Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Fri, 15 Nov 2024 15:18:47 +0100 Subject: [PATCH 1/6] fix error: TypeError: event.target.closest(...) is null --- packages/plugins/src/menu/Help.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index e5b9ef26aa..2e2705eb9b 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -43,12 +43,14 @@ async function getLinkedPages(path: string[]): Promise { } const page = path[path.length - 1].replace(/ /g, '-'); - const res = await fetch(`/public/md/${page}.md`); + const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); + const MD_LINK = `$1` const unlinkedMd = md.replace( /\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g, - `$1` + MD_LINK ); + const header = html`
${page === 'Home' ? aboutBox(edition.version) : html``} ${unsafeHTML(marked.parse(unlinkedMd))} From d4376a36b0e09e5df0cd3db65b98fee9c8083a00 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Fri, 15 Nov 2024 16:38:58 +0100 Subject: [PATCH 2/6] refactoring - Help.ts: move regex into explainatory variables - finder-list.ts: remove unnecessary Fn --- packages/openscd/src/finder-list.ts | 9 ++++----- packages/plugins/src/menu/Help.ts | 15 ++++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/openscd/src/finder-list.ts b/packages/openscd/src/finder-list.ts index f4bcfcf5c0..a98582e53b 100644 --- a/packages/openscd/src/finder-list.ts +++ b/packages/openscd/src/finder-list.ts @@ -91,9 +91,6 @@ export class FinderList extends LitElement { return path.join('/'); } - getDisplayString(entry: string, path: string[]): string { - return entry; - } @query('div') container!: Element; @@ -153,9 +150,11 @@ export class FinderList extends LitElement { html` JSON.stringify(p)) + .map(p => { + return JSON.stringify(p) + }) .includes(JSON.stringify(path.concat(entry)))} - >${this.getDisplayString(entry, path)}${entry}` )} `; diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index 2e2705eb9b..d4514a6cd9 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -9,6 +9,10 @@ import { newWizardEvent, Wizard } from '@openscd/open-scd/src/foundation.js'; import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js'; import { Directory } from '@openscd/open-scd/src/finder-list.js'; +const GITHUB_WIKI_LINK_PATTERN = /https:\/\/github\.com\/openscd\/open-scd\/wiki\/([^)]*)/g; +const MD_LINK_TITLE_PATTERN =/[^\\]]*/; +const HYPHEN_PATTERN = /-/g; + function aboutBox(version: string) { return html`
@@ -45,10 +49,10 @@ async function getLinkedPages(path: string[]): Promise { const page = path[path.length - 1].replace(/ /g, '-'); const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); - const MD_LINK = `$1` + const MD_LINK_REPLACEMENT = `$1` const unlinkedMd = md.replace( - /\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g, - MD_LINK + new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), + MD_LINK_REPLACEMENT ); const header = html`
@@ -56,8 +60,9 @@ async function getLinkedPages(path: string[]): Promise { ${unsafeHTML(marked.parse(unlinkedMd))}
`; const entries = Array.from( - md.matchAll(/\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g) - ).map(([_, child]) => child.replace(/-/g, ' ')); + md.matchAll( new RegExp(`\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g')) + + ).map(([_, child]) => child.replace(HYPHEN_PATTERN, ' ')); return { path, header, entries }; } From 291dbf6cea249df58d55604febbea6527578faf9 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 09:57:21 +0100 Subject: [PATCH 3/6] fix failing test Test was failing for previously removing the "getDisplayString" method --- packages/openscd/test/unit/finder-list.test.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/openscd/test/unit/finder-list.test.ts b/packages/openscd/test/unit/finder-list.test.ts index d7a62c0b35..5af6bd1718 100644 --- a/packages/openscd/test/unit/finder-list.test.ts +++ b/packages/openscd/test/unit/finder-list.test.ts @@ -30,9 +30,6 @@ function getTitle(path: Path): string { return `Testing ${path[path.length - 1]}`; } -function getDisplayString(entry: string, path: string[]) { - return 'Testing ' + path.length + ' ' + entry; -} async function read(path: Path): Promise { const dir = path[path.length - 1]; @@ -111,9 +108,8 @@ describe('finder-list', () => { .property('children') .to.have.lengthOf(pathA.length)); - describe('when provided with .getTitle and .getDisplayString methods', () => { + describe('when provided with .getTitle method', () => { beforeEach(async () => { - element.getDisplayString = getDisplayString; element.getTitle = getTitle; element.requestUpdate(); await element.updateComplete; @@ -126,7 +122,7 @@ describe('finder-list', () => { .to.satisfy((l: string) => l.startsWith('Testing ')); }); - it('overrides list-item text content using .getDisplayString', () => { + it('overrides list-item text content using', () => { expect(element.container.querySelector('mwc-list-item')) .property('text') .to.satisfy((t: string) => t.startsWith('Testing ')); From a0c86a0dd068fe46bb9592a2d0a03dd8b5d41bf8 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 15:15:26 +0100 Subject: [PATCH 4/6] refactorings --- packages/plugins/src/menu/Help.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index d4514a6cd9..664b4c1ca0 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -10,7 +10,7 @@ import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js'; import { Directory } from '@openscd/open-scd/src/finder-list.js'; const GITHUB_WIKI_LINK_PATTERN = /https:\/\/github\.com\/openscd\/open-scd\/wiki\/([^)]*)/g; -const MD_LINK_TITLE_PATTERN =/[^\\]]*/; +const MD_LINK_TITLE_PATTERN ='([^\\]]*)'; const HYPHEN_PATTERN = /-/g; function aboutBox(version: string) { @@ -49,9 +49,9 @@ async function getLinkedPages(path: string[]): Promise { const page = path[path.length - 1].replace(/ /g, '-'); const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); - const MD_LINK_REPLACEMENT = `$1` + const MD_LINK_REPLACEMENT = `$1` const unlinkedMd = md.replace( - new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), + new RegExp(`\\[${MD_LINK_TITLE_PATTERN}\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), MD_LINK_REPLACEMENT ); From 5ec582d3af8e3f2c76eeed3d51657e51f5bfa7a2 Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 18 Nov 2024 15:17:34 +0100 Subject: [PATCH 5/6] reinstate deleted Fn --- packages/openscd/src/finder-list.ts | 9 +++++---- packages/openscd/test/unit/finder-list.test.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/openscd/src/finder-list.ts b/packages/openscd/src/finder-list.ts index a98582e53b..f4bcfcf5c0 100644 --- a/packages/openscd/src/finder-list.ts +++ b/packages/openscd/src/finder-list.ts @@ -91,6 +91,9 @@ export class FinderList extends LitElement { return path.join('/'); } + getDisplayString(entry: string, path: string[]): string { + return entry; + } @query('div') container!: Element; @@ -150,11 +153,9 @@ export class FinderList extends LitElement { html` { - return JSON.stringify(p) - }) + .map(p => JSON.stringify(p)) .includes(JSON.stringify(path.concat(entry)))} - >${entry}${this.getDisplayString(entry, path)}` )} `; diff --git a/packages/openscd/test/unit/finder-list.test.ts b/packages/openscd/test/unit/finder-list.test.ts index 5af6bd1718..d7a62c0b35 100644 --- a/packages/openscd/test/unit/finder-list.test.ts +++ b/packages/openscd/test/unit/finder-list.test.ts @@ -30,6 +30,9 @@ function getTitle(path: Path): string { return `Testing ${path[path.length - 1]}`; } +function getDisplayString(entry: string, path: string[]) { + return 'Testing ' + path.length + ' ' + entry; +} async function read(path: Path): Promise { const dir = path[path.length - 1]; @@ -108,8 +111,9 @@ describe('finder-list', () => { .property('children') .to.have.lengthOf(pathA.length)); - describe('when provided with .getTitle method', () => { + describe('when provided with .getTitle and .getDisplayString methods', () => { beforeEach(async () => { + element.getDisplayString = getDisplayString; element.getTitle = getTitle; element.requestUpdate(); await element.updateComplete; @@ -122,7 +126,7 @@ describe('finder-list', () => { .to.satisfy((l: string) => l.startsWith('Testing ')); }); - it('overrides list-item text content using', () => { + it('overrides list-item text content using .getDisplayString', () => { expect(element.container.querySelector('mwc-list-item')) .property('text') .to.satisfy((t: string) => t.startsWith('Testing ')); From 334772a86aff7225b4f395592fc529748c63269c Mon Sep 17 00:00:00 2001 From: Sergio Alvarenga Date: Mon, 7 Apr 2025 16:47:34 +0200 Subject: [PATCH 6/6] feat: add translations for new communication wizard --- packages/openscd/src/translations/de.ts | 1 + packages/openscd/src/translations/en.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/openscd/src/translations/de.ts b/packages/openscd/src/translations/de.ts index 67e314ede6..8cca3e42bb 100644 --- a/packages/openscd/src/translations/de.ts +++ b/packages/openscd/src/translations/de.ts @@ -93,6 +93,7 @@ export const de: Translations = { select: '{{tagName}} auswählen', edit: '{{tagName}} bearbeiten', add: '{{tagName}} hinzufügen', + selectAp: 'ConnectedAP auswählen' }, }, openSCD: { diff --git a/packages/openscd/src/translations/en.ts b/packages/openscd/src/translations/en.ts index ca983fd40d..5291895a73 100644 --- a/packages/openscd/src/translations/en.ts +++ b/packages/openscd/src/translations/en.ts @@ -91,6 +91,7 @@ export const en = { select: 'Select {{tagName}}', edit: 'Edit {{tagName}}', add: 'Add {{tagName}}', + selectAp: 'Select New ConnectedAP' }, }, openSCD: {