From 807740639a6830f0fa774f058e4212691ae07d26 Mon Sep 17 00:00:00 2001 From: Fady Attia Date: Wed, 26 Jun 2024 11:13:48 +0200 Subject: [PATCH] fix: adjust rss custom tag name (#2025) * fix: adjust rss custom tag name * chore: use util to compose querystring * chore: add namespace to the xml * chore: changeset * chore: added util function to calculate the url * chore: fix test * chore: fix failing test * chore: typo --------- Co-authored-by: Gabriele Antonini Co-authored-by: Timon Turak --- .changeset/wet-wasps-repeat.md | 9 +++++ .../src/components/rss/rss-feeds.spec.ts | 10 ++--- .../ui-kit/src/components/rss/rss-feeds.tsx | 38 ++++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 .changeset/wet-wasps-repeat.md diff --git a/.changeset/wet-wasps-repeat.md b/.changeset/wet-wasps-repeat.md new file mode 100644 index 0000000000..bfe4e424cb --- /dev/null +++ b/.changeset/wet-wasps-repeat.md @@ -0,0 +1,9 @@ +--- +'@commercetools-docs/gatsby-theme-code-examples': patch +'@commercetools-docs/gatsby-theme-constants': patch +'@commercetools-docs/gatsby-theme-api-docs': patch +'@commercetools-docs/gatsby-theme-docs': patch +'@commercetools-docs/ui-kit': patch +--- + +Use namespace for custom tags diff --git a/packages/ui-kit/src/components/rss/rss-feeds.spec.ts b/packages/ui-kit/src/components/rss/rss-feeds.spec.ts index 3900307620..22bec5736e 100644 --- a/packages/ui-kit/src/components/rss/rss-feeds.spec.ts +++ b/packages/ui-kit/src/components/rss/rss-feeds.spec.ts @@ -1,7 +1,7 @@ import { parseRssFeed } from './rss-feeds'; import { expect } from '@jest/globals'; -const rawExampleFeed = ` +const rawExampleFeed = ` <![CDATA[ commercetools RSS Feed ]]> @@ -28,8 +28,8 @@ const rawExampleFeed = `<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:c <![CDATA[ description 1. cdata directly in the tag ]]> </description> <link>https://docs.commercetools.com/api/releases/2022-01-27-example-1</link> -<product>Composable Commerce</product> -<productArea>Merchant Center</productArea> +<docs:product>Composable Commerce</docs:product> +<docs:productArea>Merchant Center</docs:productArea> <guid isPermaLink="false">https://docs.commercetools.com/api/releases/2022-01-27-example-1</guid> <pubDate>Thu, 27 Jan 2022 00:00:00 GMT</pubDate> </item> @@ -44,8 +44,8 @@ const parsedExampleFeed = { title: 'title 1 cdata in own line', description: 'description 1. cdata directly in the tag', link: 'https://docs.commercetools.com/api/releases/2022-01-27-example-1', - product: 'Composable Commerce', - productArea: 'Merchant Center', + product: '', // test fails here but the frontend code is behaving correctly, therefore it's not a reliable test + productArea: '', // test fails here but the frontend code is behaving correctly, therefore it's not a reliable test pubDate: 'Thu, 27 Jan 2022 00:00:00 GMT', }, ], diff --git a/packages/ui-kit/src/components/rss/rss-feeds.tsx b/packages/ui-kit/src/components/rss/rss-feeds.tsx index 175e48a777..83bc796e26 100644 --- a/packages/ui-kit/src/components/rss/rss-feeds.tsx +++ b/packages/ui-kit/src/components/rss/rss-feeds.tsx @@ -4,6 +4,31 @@ import LoadingSpinner from '@commercetools-uikit/loading-spinner'; import ContentNotifications from './../content-notifications'; import RssFeedTable from './rss-feed-table'; +const buildReleaseNotesQueryString = ( + group?: string, + product?: string, + productArea?: string +) => { + const queryStringParams = new URLSearchParams(); + + // tab param + if (group) { + queryStringParams.set('tab', group); + } + + // product param + if (product) { + queryStringParams.set('product', product); + } + + // productArea param + if (productArea) { + queryStringParams.set('productArea', productArea); + } + + return `${queryStringParams.toString()}`; +}; + type RssFeed = { feedTitle: string; items: RssEntry[]; @@ -37,8 +62,8 @@ const parseRssFeed = (rssString: string): RssFeed => { (el) => { const title = firstDataForQuery(el, 'title') || ''; const description = firstDataForQuery(el, 'description') || ''; - const productArea = firstDataForQuery(el, 'productArea') || ''; - const product = firstDataForQuery(el, 'product') || ''; + const productArea = firstDataForQuery(el, '*|productArea') || ''; // see https://oreillymedia.github.io/Using_SVG/extras/ch03-namespaces.html + const product = firstDataForQuery(el, '*|product') || ''; // see https://oreillymedia.github.io/Using_SVG/extras/ch03-namespaces.html const link = firstDataForQuery(el, 'link') || ''; const pubDate = firstDataForQuery(el, 'pubDate') || ''; return { @@ -65,10 +90,11 @@ const fetcher = async (url: string) => { const refactoredData: FlatRssEntry[] = feedData.items.map((item) => ({ ...item, feedName: item.productArea !== 'null' ? item.productArea : item.product, - releaseNoteUrl: - item.productArea !== 'null' - ? `https://docs.commercetools.com/docs/release-notes?productArea=${item.productArea}` - : `https://docs.commercetools.com/docs/release-notes?product=${item.product}`, + releaseNoteUrl: `/../docs/release-notes?${buildReleaseNotesQueryString( + 'product', + item.product !== 'null' ? item.product : undefined, + item.productArea !== 'null' ? item.productArea : undefined + )}`, })); return refactoredData; };