Skip to content

Commit

Permalink
chore: adapt release notes back links to the new format (#2005)
Browse files Browse the repository at this point in the history
* chore: adapt release notes back links to the new format

* chore: changeset
  • Loading branch information
gabriele-ct authored Jun 17, 2024
1 parent 7c8ee9e commit cf28c03
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 61 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-chefs-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-docs/gatsby-theme-docs': patch
---

Adapt the release notes pages back links to the new parameters format
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useReleaseNotesConfig = () => {
product,
title
);
return `/docs/release-notes${queryString}`; // only prod url
return `/docs/release-notes?${queryString}`; // only prod url
};

return { getReleaseNotesUrl };
Expand Down
35 changes: 12 additions & 23 deletions packages/gatsby-theme-docs/src/utils/release-notes.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
export const MIN_DATERANGE = 0;
export const MAX_DATERANGE = 2537011284;

export const buildReleaseNotesQueryString = (group, product, productArea) => {
let searchState = {
range: {
dateTimestamp: `${MIN_DATERANGE}:${MAX_DATERANGE}`,
},
};
const queryStringParams = new URLSearchParams();

// tab param
if (group) {
searchState.configure = {
...searchState.configure,
facetFilters: `group:${group}`,
};
queryStringParams.set('tab', group);
}

// product param
if (product) {
searchState.refinementList = {
...searchState.refinementList,
product: [product],
};
queryStringParams.set('product', product);
}

// productArea param
if (productArea) {
searchState.refinementList = {
...searchState.refinementList,
productArea: [productArea],
};
queryStringParams.set('productArea', productArea);
}
return searchState.refinementList
? `?searchState=${encodeURIComponent(JSON.stringify(searchState))}`
: '';

return `${queryStringParams.toString()}`;
};
45 changes: 8 additions & 37 deletions packages/gatsby-theme-docs/src/utils/release-notes.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
MAX_DATERANGE,
MIN_DATERANGE,
buildReleaseNotesQueryString,
} from './release-notes';
import { buildReleaseNotesQueryString } from './release-notes';

describe('buildReleaseNotesQueryString', () => {
it('should return a query string with product and productArea', () => {
Expand All @@ -16,23 +12,11 @@ describe('buildReleaseNotesQueryString', () => {
productArea
);

const expectedValue = {
range: {
dateTimestamp: `${MIN_DATERANGE}:${MAX_DATERANGE}`,
},
configure: {
facetFilters: `group:${group}`,
},
refinementList: {
product: [product],
productArea: [productArea],
},
};
const expectedStringValue = encodeURIComponent(
JSON.stringify(expectedValue)
);

expect(queryString).toBe(`?searchState=${expectedStringValue}`);
const expectedValue = `tab=${group}&product=${product.replace(
' ',
'+'
)}&productArea=${productArea.replace(' ', '+')}`;
expect(queryString).toBe(expectedValue);
});

it('should return a query string with only product', () => {
Expand All @@ -41,22 +25,9 @@ describe('buildReleaseNotesQueryString', () => {

const queryString = buildReleaseNotesQueryString(group, product);

const expectedValue = {
range: {
dateTimestamp: `${MIN_DATERANGE}:${MAX_DATERANGE}`,
},
configure: {
facetFilters: `group:${group}`,
},
refinementList: {
product: [product],
},
};
const expectedStringValue = encodeURIComponent(
JSON.stringify(expectedValue)
);
const expectedValue = `tab=${group}&product=${product}`;

expect(queryString).toBe(`?searchState=${expectedStringValue}`);
expect(queryString).toBe(expectedValue);
});

it('should return an empty query string if no arguments are provided', () => {
Expand Down

0 comments on commit cf28c03

Please sign in to comment.