From a89ded202d8d36548addd53619ce5e2ac445a307 Mon Sep 17 00:00:00 2001 From: Dragana Trajkovic Date: Tue, 25 Jun 2024 12:06:16 +0200 Subject: [PATCH 1/4] MWPW-152988 - filter and sort labels not authorable from the block --- .../knowledge-base-overview.js | 7 ++++ eds/blocks/partner-news/partner-news.js | 9 ++++- eds/components/PartnerCards.js | 36 +++++++++---------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js index 8e77441..598b6b2 100644 --- a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js +++ b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js @@ -40,6 +40,13 @@ export default async function init(el) { '{{search}}': 'Search', }; + const liList = Array.from(el.querySelectorAll('li')); + liList.forEach(liEl => { + let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); + localizedText[`{{${liContent}}}`] = liContent; + }); + const deps = await Promise.all([ localizationPromises(localizedText, config), import(`${miloLibs}/features/spectrum-web-components/dist/theme.js`), diff --git a/eds/blocks/partner-news/partner-news.js b/eds/blocks/partner-news/partner-news.js index 936c5b7..ce0b791 100644 --- a/eds/blocks/partner-news/partner-news.js +++ b/eds/blocks/partner-news/partner-news.js @@ -38,9 +38,16 @@ export default async function init(el) { '{{previous-month}}': 'Previous month', '{{results}}': 'Results', '{{search}}': 'Search', - '{{show-all}}': 'Show all' + '{{show-all}}': 'Show all', }; + const liList = Array.from(el.querySelectorAll('li')); + liList.forEach(liEl => { + let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); + localizedText[`{{${liContent}}}`] = liContent; + }); + const deps = await Promise.all([ localizationPromises(localizedText, config), import(`${miloLibs}/features/spectrum-web-components/dist/theme.js`), diff --git a/eds/components/PartnerCards.js b/eds/components/PartnerCards.js index 657e9e8..613ac24 100644 --- a/eds/components/PartnerCards.js +++ b/eds/components/PartnerCards.js @@ -123,35 +123,33 @@ export class PartnerCards extends LitElement { this.blockData.title = titleEl.innerText.trim(); }, 'filter': (cols) => { - const [filterKeyEl, filterValueEl, filterTagsKeysEl, filterTagsValueEl] = cols; - const filterKey = filterKeyEl.innerText.trim().toLowerCase().replaceAll(' ', '-'); - const filterValue = filterValueEl.innerText.trim(); - const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase()); - const filterTagsValue = Array.from(filterTagsValueEl.querySelectorAll('li'), (li) => li.innerText.trim()); + const [filterKeyEl, filterTagsKeysEl] = cols; + const filterKey = filterKeyEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-')); if (!filterKey || !filterTagsKeys.length) return; let filterObj = { key: filterKey, - value: filterValue, - tags: filterTagsKeys.map((tagKey, tagIndex) => ({ - key: tagKey.replaceAll(' ', '-'), - parentKey: filterKey, - value: filterTagsValue[tagIndex], - checked: false + value: this.blockData.localizedText[`{{${filterKey}}}`], + tags: filterTagsKeys.map((tagKey) => ({ + key: tagKey, + parentKey: filterKey, + value: this.blockData.localizedText[`{{${tagKey}}}`], + checked: false })) }; this.blockData.filters.push(filterObj); }, 'sort': (cols) => { - const [sortKeysEl, sortValuesEl] = cols; - const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase()); - const sortValues = Array.from(sortValuesEl.querySelectorAll('li'), (li) => li.innerText.trim()); + const [sortKeysEl] = cols; + const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-')); - const sortItems = sortKeys.map((sortKey, sortIndex) => ({ - key: sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey, - value: sortValues[sortIndex] - })); + const sortItems = sortKeys.map((sortKey) => { + const key = sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey; + const value = this.blockData.localizedText[`{{${key}}}`]; + return { key, value }; + }); const defaultKey = sortKeys.find(key => key.endsWith('_default')).slice(0, -8) || sortKeys[0]; const defaultValue = sortItems.find(e => e.key === defaultKey).value; @@ -173,7 +171,7 @@ export class PartnerCards extends LitElement { const rows = Array.from(this.blockData.tableData); rows.forEach((row) => { const cols = Array.from(row.children); - const rowTitle = cols[0].innerText.trim().toLowerCase().replaceAll(' ', '-'); + const rowTitle = cols[0].innerText.trim().toLowerCase().replace(/ /g, '-'); const colsContent = cols.slice(1); if (blockDataActions[rowTitle]) blockDataActions[rowTitle](colsContent); }); From 3b230204feb6793d37e0fe1d38b7c77191b498f6 Mon Sep 17 00:00:00 2001 From: Dragana Trajkovic Date: Tue, 25 Jun 2024 13:46:37 +0200 Subject: [PATCH 2/4] MWPW-152988 - populateLocalizedTextFromListItems moved to utils --- .../knowledge-base-overview/knowledge-base-overview.js | 9 ++------- eds/blocks/partner-news/partner-news.js | 9 ++------- eds/scripts/utils.js | 9 +++++++++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js index 598b6b2..28d8896 100644 --- a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js +++ b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js @@ -1,4 +1,4 @@ -import { getLibs, replaceText, getConfig } from './../../scripts/utils.js'; +import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from './../../scripts/utils.js'; import { KnowledgeBaseOverview } from './KnowledgeBaseOverview.js'; function declareKnowledgeBaseOverview() { @@ -40,12 +40,7 @@ export default async function init(el) { '{{search}}': 'Search', }; - const liList = Array.from(el.querySelectorAll('li')); - liList.forEach(liEl => { - let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); - if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); - localizedText[`{{${liContent}}}`] = liContent; - }); + populateLocalizedTextFromListItems(el, localizedText); const deps = await Promise.all([ localizationPromises(localizedText, config), diff --git a/eds/blocks/partner-news/partner-news.js b/eds/blocks/partner-news/partner-news.js index ce0b791..7a2bbd5 100644 --- a/eds/blocks/partner-news/partner-news.js +++ b/eds/blocks/partner-news/partner-news.js @@ -1,4 +1,4 @@ -import { getLibs, replaceText, getConfig } from './../../scripts/utils.js'; +import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from './../../scripts/utils.js'; import { PartnerNews } from './PartnerNews.js'; function declarePartnerNews() { @@ -41,12 +41,7 @@ export default async function init(el) { '{{show-all}}': 'Show all', }; - const liList = Array.from(el.querySelectorAll('li')); - liList.forEach(liEl => { - let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); - if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); - localizedText[`{{${liContent}}}`] = liContent; - }); + populateLocalizedTextFromListItems(el, localizedText); const deps = await Promise.all([ localizationPromises(localizedText, config), diff --git a/eds/scripts/utils.js b/eds/scripts/utils.js index 4ac3747..918eead 100644 --- a/eds/scripts/utils.js +++ b/eds/scripts/utils.js @@ -55,3 +55,12 @@ export { createTag, localizeLink, getConfig }; const { replaceText } = await import(`${miloLibs}/features/placeholders.js`); export { replaceText }; + +export function populateLocalizedTextFromListItems(el, localizedText) { + const liList = Array.from(el.querySelectorAll('li')); + liList.forEach(liEl => { + let liContent = liEl.innerText.trim().toLowerCase().replace(/ /g, '-'); + if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); + localizedText[`{{${liContent}}}`] = liContent; + }); +} From f64021bcd3e74f30d81694ebe913e5e7eaa33aff Mon Sep 17 00:00:00 2001 From: Dragana Trajkovic Date: Tue, 25 Jun 2024 13:56:44 +0200 Subject: [PATCH 3/4] MWPW-152988 - unit test fix --- .../knowledge-base-overview/mocks/body.html | 132 +++++++++++------- test/blocks/partner-news/mocks/body.html | 132 +++++++++++------- 2 files changed, 156 insertions(+), 108 deletions(-) diff --git a/test/blocks/knowledge-base-overview/mocks/body.html b/test/blocks/knowledge-base-overview/mocks/body.html index 2f86f56..a2b0093 100644 --- a/test/blocks/knowledge-base-overview/mocks/body.html +++ b/test/blocks/knowledge-base-overview/mocks/body.html @@ -1,86 +1,110 @@
Title
-
Sample Title for Card Collection
+
Filters refactor
+
+
+
+
Cards per page
+
6
+
Filter
-
Audience
-
Audience
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
    +
  • Applications
  • +
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
    +
  • sign
  • +
  • advertising-cloud
  • +
  • analytics
  • +
  • audience-manager
  • +
  • campaign
  • +
  • commerce
  • +
  • customer-journey-analytics
  • +
  • document-cloud
  • +
  • document-services
  • +
  • experience-cloud
  • +
  • experience-manager
  • +
  • experience-platform
  • +
  • journey-optimizer
  • +
  • marketo-engage
  • +
  • microsoft
  • +
  • real-time-cdp
  • +
  • target
  • +
  • workfront
  • +
Filter
-
Region
-
Region
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. EMEA
  6. -
  7. Japan
  8. -
+
    +
  • audience
  • +
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. Europe, Middle East & Africa
  6. -
  7. Japan
  8. -
+
    +
  • marketing
  • +
  • sales
  • +
  • practice-lead
  • +
  • technical
  • +
Filter
-
product
-
Product
-
    -
  1. adobe-experience-manager
  2. -
  3. adobe-analytics
  4. -
  5. adobe-target
  6. -
+
    +
  • region
  • +
-
    -
  1. Experience manager
  2. -
  3. Analytics
  4. -
  5. Target
  6. -
+
    +
  • americas
  • +
  • asia-pacific
  • +
  • emea
  • +
  • japan
  • +
-
Sort
+
Filter
-
    -
  1. newest_default
  2. -
  3. oldest
  4. -
  5. a-z
  6. -
  7. z-a
  8. -
+
    +
  • topic
  • +
-
    -
  1. Date: newest
  2. -
  3. Date: oldest
  4. -
  5. Title: A-Z
  6. -
  7. Title: Z-A
  8. -
+
    +
  • analyst-reports
  • +
  • amplify
  • +
  • certification-credentials
  • +
  • enablement-training
  • +
  • events
  • +
  • executive-insights
  • +
  • industries
  • +
  • marketing
  • +
  • program-benefits
  • +
  • programs-contests
  • +
  • product-releases
  • +
  • selling
  • +
  • solutions
  • +
  • specialization
  • +
+
+
+
+
Sort
+
+
    +
  • newest
  • +
  • oldest_default
  • +
+
diff --git a/test/blocks/partner-news/mocks/body.html b/test/blocks/partner-news/mocks/body.html index 0e5cb3f..d5ef1ca 100644 --- a/test/blocks/partner-news/mocks/body.html +++ b/test/blocks/partner-news/mocks/body.html @@ -1,86 +1,110 @@
Title
-
Sample Title for Card Collection
+
Filters refactor
+
+
+
+
Cards per page
+
6
+
Filter
-
Audience
-
Audience
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
    +
  • Applications
  • +
-
    -
  1. Marketing
  2. -
  3. Sales
  4. -
  5. Practice Lead
  6. -
  7. Technical
  8. -
+
    +
  • sign
  • +
  • advertising-cloud
  • +
  • analytics
  • +
  • audience-manager
  • +
  • campaign
  • +
  • commerce
  • +
  • customer-journey-analytics
  • +
  • document-cloud
  • +
  • document-services
  • +
  • experience-cloud
  • +
  • experience-manager
  • +
  • experience-platform
  • +
  • journey-optimizer
  • +
  • marketo-engage
  • +
  • microsoft
  • +
  • real-time-cdp
  • +
  • target
  • +
  • workfront
  • +
Filter
-
Region
-
Region
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. EMEA
  6. -
  7. Japan
  8. -
+
    +
  • audience
  • +
-
    -
  1. Americas
  2. -
  3. Asia Pacific
  4. -
  5. Europe, Middle East & Africa
  6. -
  7. Japan
  8. -
+
    +
  • marketing
  • +
  • sales
  • +
  • practice-lead
  • +
  • technical
  • +
Filter
-
product
-
Product
-
    -
  1. adobe-experience-manager
  2. -
  3. adobe-analytics
  4. -
  5. adobe-target
  6. -
+
    +
  • region
  • +
-
    -
  1. Experience manager
  2. -
  3. Analytics
  4. -
  5. Target
  6. -
+
    +
  • americas
  • +
  • asia-pacific
  • +
  • emea
  • +
  • japan
  • +
-
Sort
+
Filter
-
    -
  1. newest_default
  2. -
  3. oldest
  4. -
  5. a-z
  6. -
  7. z-a
  8. -
+
    +
  • topic
  • +
-
    -
  1. Date: newest
  2. -
  3. Date: oldest
  4. -
  5. Title: A-Z
  6. -
  7. Title: Z-A
  8. -
+
    +
  • analyst-reports
  • +
  • amplify
  • +
  • certification-credentials
  • +
  • enablement-training
  • +
  • events
  • +
  • executive-insights
  • +
  • industries
  • +
  • marketing
  • +
  • program-benefits
  • +
  • programs-contests
  • +
  • product-releases
  • +
  • selling
  • +
  • solutions
  • +
  • specialization
  • +
+
+
+
+
Sort
+
+
    +
  • newest
  • +
  • oldest_default
  • +
+
From c39d7735ec823060cbde335a8d9f64c9e15211aa Mon Sep 17 00:00:00 2001 From: Dragana Trajkovic Date: Tue, 25 Jun 2024 13:58:50 +0200 Subject: [PATCH 4/4] MWPW-152988 - unit test fix2 --- test/blocks/knowledge-base-overview/mocks/body.html | 2 +- test/blocks/partner-news/mocks/body.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/blocks/knowledge-base-overview/mocks/body.html b/test/blocks/knowledge-base-overview/mocks/body.html index a2b0093..0635b8b 100644 --- a/test/blocks/knowledge-base-overview/mocks/body.html +++ b/test/blocks/knowledge-base-overview/mocks/body.html @@ -1,7 +1,7 @@
Title
-
Filters refactor
+
Sample Title for Card Collection
diff --git a/test/blocks/partner-news/mocks/body.html b/test/blocks/partner-news/mocks/body.html index d5ef1ca..2468b1a 100644 --- a/test/blocks/partner-news/mocks/body.html +++ b/test/blocks/partner-news/mocks/body.html @@ -1,7 +1,7 @@
Title
-
Filters refactor
+
Sample Title for Card Collection