Skip to content

Commit db4518d

Browse files
committed
Clean up absoluteUrl
1 parent 5f9738e commit db4518d

File tree

2 files changed

+0
-51
lines changed

2 files changed

+0
-51
lines changed

packages/template-retail-react-app/app/utils/url.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,6 @@ import {
1313
getSiteByReference
1414
} from '@salesforce/retail-react-app/app/utils/site-utils'
1515
import {HOME_HREF, urlPartPositions} from '@salesforce/retail-react-app/app/constants'
16-
import {isAbsoluteURL} from '@salesforce/retail-react-app/app/page-designer/utils'
17-
18-
/**
19-
* Constructs an absolute URL from a given path and an optional application origin.
20-
* TODO: How should this work with base path?
21-
*
22-
* @param {string} path - The relative URL path to be appended to the origin.
23-
* @param {string} [appOrigin] - The optional application origin (e.g., "https://example.com").
24-
* If not provided, the function will call `getAppOrigin()`.
25-
* @returns {string} - The fully qualified URL as a string.
26-
*/
27-
export const absoluteUrl = (path, appOrigin) => {
28-
// If path is not provided or already an absolute URL, return it as-is
29-
if (!path || isAbsoluteURL(path)) {
30-
return path
31-
}
32-
33-
// absoluteUrl is not a react hook so we cannot use the useAppOrigin hook here
34-
return new URL(path, appOrigin || getAppOrigin()).toString()
35-
}
3616

3717
/**
3818
* Modifies a given url by adding/updating query parameters.

packages/template-retail-react-app/app/utils/url.test.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getPathWithLocale,
1414
rebuildPathWithParams,
1515
removeQueryParamsFromPath,
16-
absoluteUrl,
1716
createUrlTemplate,
1817
removeSiteLocaleFromPath,
1918
serverSafeEncode
@@ -394,36 +393,6 @@ describe('removeQueryParamsFromPath test', () => {
394393
})
395394
})
396395

397-
describe('absoluteUrl', function () {
398-
test('return undefined when path is not provided', () => {
399-
const url = absoluteUrl()
400-
expect(url).toBeUndefined()
401-
})
402-
403-
test('return expected when path is a relative url', () => {
404-
const url = absoluteUrl('/uk/en/women/dresses')
405-
expect(url).toBe('https://www.example.com/uk/en/women/dresses')
406-
})
407-
408-
test('return expected when path is an absolute url', () => {
409-
const url = absoluteUrl('https://www.example.com/uk/en/women/dresses')
410-
expect(url).toBe('https://www.example.com/uk/en/women/dresses')
411-
})
412-
413-
test('return expected when path is a relative url and appOrigin is provided', () => {
414-
const url = absoluteUrl('uk/en/women/dresses', 'https://www.custom.com')
415-
expect(url).toBe('https://www.custom.com/uk/en/women/dresses')
416-
})
417-
418-
test('return expected when path is an absolute url and appOrigin is provided', () => {
419-
const url = absoluteUrl(
420-
'https://www.example.com/uk/en/women/dresses',
421-
'https://www.should-be-ignored.com'
422-
)
423-
expect(url).toBe('https://www.example.com/uk/en/women/dresses')
424-
})
425-
})
426-
427396
describe('removeSiteLocaleFromPath', function () {
428397
test('return path without site alias and locale', () => {
429398
const pathName = removeSiteLocaleFromPath('/uk/en-GB/account/wishlist')

0 commit comments

Comments
 (0)