-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create utils for generating release notes urls with right filte…
…rs (#1998) * feat: calculate the release notes url based on product and productArea * chore: release notes links to point to the new search page
- Loading branch information
1 parent
5c2fffd
commit 3ddd920
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-docs/gatsby-theme-docs': patch | ||
--- | ||
|
||
Add util function to calculate the url for release notes page with pre initialized fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export const MIN_DATERANGE = 0; | ||
export const MAX_DATERANGE = 2537011284; | ||
|
||
// TODO: this could be used to generate sitemap.xml urls query strings | ||
const mapSiteTitleToFacetFilter = new Map([ | ||
['Merchant Center', { productArea: 'Merchant Center' }], | ||
['HTTP API', { productArea: 'HTTP API' }], | ||
['Checkout', { product: 'Checkout' }], | ||
['Connect', { product: 'Connect' }], | ||
['Frontend Development', { productArea: 'Frontend Development' }], | ||
['Frontend Studio', { productArea: 'Frontend Studio' }], | ||
['Import API', { productArea: 'Import API' }], | ||
[ | ||
'Merchant Center Customizations', | ||
{ productArea: 'Merchant Center Customizations' }, | ||
], | ||
]); | ||
|
||
export const buildReleaseNotesQueryString = (product, productArea) => { | ||
let searchState = { | ||
range: { | ||
dateTimestamp: `${MIN_DATERANGE}:${MAX_DATERANGE}`, | ||
}, | ||
}; | ||
if (product) { | ||
searchState.refinementList = { | ||
...searchState.refinementList, | ||
product: [product], | ||
}; | ||
} | ||
if (productArea) { | ||
searchState.refinementList = { | ||
...searchState.refinementList, | ||
product: [productArea], | ||
}; | ||
} | ||
return searchState.refinementList | ||
? `?searchState=${encodeURIComponent(JSON.stringify(searchState))}` | ||
: ''; | ||
}; | ||
|
||
export const getReleaseNotesQueryStringBySiteTitle = (siteTitle) => { | ||
const productArea = mapSiteTitleToFacetFilter.get(siteTitle); | ||
if (productArea) { | ||
return buildReleaseNotesQueryString( | ||
productArea.product, | ||
productArea.productArea | ||
); | ||
} | ||
return ''; | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/gatsby-theme-docs/src/utils/release-notes.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
buildReleaseNotesQueryString, | ||
getReleaseNotesQueryStringBySiteTitle, | ||
} from './release-notes'; | ||
|
||
describe('buildReleaseNotesQueryString', () => { | ||
it('should return a query string with product and productArea', () => { | ||
const product = 'Merchant Center'; | ||
const productArea = 'Frontend Development'; | ||
|
||
const queryString = buildReleaseNotesQueryString(product, productArea); | ||
|
||
expect(queryString).toBe( | ||
'?searchState=%7B%22range%22%3A%7B%22dateTimestamp%22%3A%220%3A2537011284%22%7D%2C%22refinementList%22%3A%7B%22product%22%3A%5B%22Frontend%20Development%22%5D%7D%7D' | ||
); | ||
}); | ||
|
||
it('should return a query string with only product', () => { | ||
const product = 'Checkout'; | ||
|
||
const queryString = buildReleaseNotesQueryString(product); | ||
|
||
expect(queryString).toBe( | ||
'?searchState=%7B%22range%22%3A%7B%22dateTimestamp%22%3A%220%3A2537011284%22%7D%2C%22refinementList%22%3A%7B%22product%22%3A%5B%22Checkout%22%5D%7D%7D' | ||
); | ||
}); | ||
|
||
it('should return an empty query string if no arguments are provided', () => { | ||
const queryString = buildReleaseNotesQueryString(); | ||
|
||
expect(queryString).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('getReleaseNotesQueryStringBySiteTitle', () => { | ||
it('should return a query string with productArea for "Merchant Center"', () => { | ||
const siteTitle = 'Merchant Center'; | ||
const queryString = getReleaseNotesQueryStringBySiteTitle(siteTitle); | ||
expect(queryString).toBe( | ||
'?searchState=%7B%22range%22%3A%7B%22dateTimestamp%22%3A%220%3A2537011284%22%7D%2C%22refinementList%22%3A%7B%22product%22%3A%5B%22Merchant%20Center%22%5D%7D%7D' | ||
); | ||
}); | ||
|
||
it('should return an empty query string if siteTitle is not found', () => { | ||
const siteTitle = 'Non-existent Title'; | ||
const queryString = getReleaseNotesQueryStringBySiteTitle(siteTitle); | ||
expect(queryString).toBe(''); | ||
}); | ||
}); | ||
|
||
it('should return an empty query string if siteTitle is not found', () => { | ||
const siteTitle = 'Non-existent Title'; | ||
const queryString = getReleaseNotesQueryStringBySiteTitle(siteTitle); | ||
expect(queryString).toBe(''); | ||
}); |