-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PWA-1673: View Product Attributes values on PDP - Content (#3759)
* PWA-1673: View Product Attributes values on PDP - Content - Updated styling to PDP - Updated page format for PDP * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content - Updated plain html renderer to modify img src * PWA-1673: View Product Attributes values on PDP - Content - Resolved test failure * PWA-1673: View Product Attributes values on PDP - Content - PWA-2534: [bug]: Widget\Link does not convert the link for PWA * PWA-1673: View Product Attributes values on PDP - Content - Add SKU to details list Co-authored-by: Hwashiang (Michael) Yu <[email protected]> Co-authored-by: Devagouda <[email protected]> Co-authored-by: Jason Poteet <[email protected]>
- Loading branch information
1 parent
2704930
commit c1a5670
Showing
23 changed files
with
565 additions
and
146 deletions.
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
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
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
53 changes: 53 additions & 0 deletions
53
packages/peregrine/lib/util/__tests__/resolveLinkProps.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,53 @@ | ||
import resolveLinkProps from '../resolveLinkProps'; | ||
|
||
describe('resolve to internal link', () => { | ||
process.env.MAGENTO_BACKEND_URL = 'http://magento.com/'; | ||
|
||
test('when base url matches', () => { | ||
const linkProps = resolveLinkProps('http://magento.com/cms-page'); | ||
expect(linkProps).toEqual({ | ||
to: '/cms-page' | ||
}); | ||
}); | ||
|
||
test('when base url matches product URL', () => { | ||
const linkProps = resolveLinkProps( | ||
'http://magento.com/product-page.html' | ||
); | ||
expect(linkProps).toEqual({ | ||
to: '/product-page.html' | ||
}); | ||
}); | ||
|
||
test('with root-relative url', () => { | ||
const linkProps = resolveLinkProps('/cms-page'); | ||
expect(linkProps).toEqual({ | ||
to: '/cms-page' | ||
}); | ||
}); | ||
|
||
test('with relative url', () => { | ||
const linkProps = resolveLinkProps('cms-page'); | ||
expect(linkProps).toEqual({ | ||
to: '/cms-page' | ||
}); | ||
}); | ||
}); | ||
|
||
test('resolve to external anchor if external link', () => { | ||
process.env.MAGENTO_BACKEND_URL = 'http://magento.com/'; | ||
const linkProps = resolveLinkProps( | ||
'http://not-magento.com/product-page.html' | ||
); | ||
expect(linkProps).toEqual({ | ||
href: 'http://not-magento.com/product-page.html' | ||
}); | ||
}); | ||
|
||
test('return original input if input is invalid', () => { | ||
process.env.MAGENTO_BACKEND_URL = null; | ||
const linkProps = resolveLinkProps(null); | ||
expect(linkProps).toEqual({ | ||
href: null | ||
}); | ||
}); |
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,26 @@ | ||
import makeUrl from './makeUrl'; | ||
import resolveLinkProps from './resolveLinkProps'; | ||
|
||
/** | ||
* Modifies html string images to use makeUrl as source and resolves links to use internal path. | ||
* | ||
* @param {string} htmlString - the html string to be updated | ||
* @return {string} | ||
*/ | ||
const htmlStringImgUrlConverter = htmlString => { | ||
const temporaryElement = document.createElement('div'); | ||
temporaryElement.innerHTML = htmlString; | ||
for (const imgElement of temporaryElement.getElementsByTagName('img')) { | ||
imgElement.src = makeUrl(imgElement.src, { | ||
type: 'image-wysiwyg', | ||
quality: 85 | ||
}); | ||
} | ||
for (const linkElement of temporaryElement.getElementsByTagName('a')) { | ||
const linkProps = resolveLinkProps(linkElement.href); | ||
linkElement.href = linkProps.to || linkProps.href; | ||
} | ||
return temporaryElement.innerHTML; | ||
}; | ||
|
||
export default htmlStringImgUrlConverter; |
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,25 @@ | ||
/** | ||
* Resolve link properties | ||
* | ||
* @param {string} link | ||
*/ | ||
export default link => { | ||
let isExternalUrl; | ||
const linkProps = {}; | ||
|
||
try { | ||
const baseUrlObj = new URL(process.env.MAGENTO_BACKEND_URL); | ||
const urlObj = new URL(link, baseUrlObj); | ||
isExternalUrl = baseUrlObj.host !== urlObj.host; | ||
|
||
if (isExternalUrl) { | ||
linkProps['href'] = link; | ||
} else { | ||
linkProps['to'] = urlObj.pathname; | ||
} | ||
} catch (e) { | ||
linkProps['href'] = link; | ||
} | ||
|
||
return linkProps; | ||
}; |
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 |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
} | ||
|
||
.contentHtml { | ||
composes: block from global; | ||
composes: inline-block from global; | ||
} |
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 |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
} | ||
|
||
.contentHtml { | ||
composes: block from global; | ||
composes: inline-block from global; | ||
} |
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
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
5 changes: 0 additions & 5 deletions
5
...es/venia-ui/lib/components/ProductFullDetail/CustomAttributes/customAttributes.module.css
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 |
---|---|---|
@@ -1,9 +1,4 @@ | ||
.root { | ||
composes: mt-8 from global; | ||
} | ||
|
||
.title { | ||
composes: font-semibold from global; | ||
} | ||
|
||
.list { | ||
|
Oops, something went wrong.