Skip to content

Commit

Permalink
Merge pull request #9 from vtex-apps/dynamicComponentUpdate
Browse files Browse the repository at this point in the history
wrike 480724582 - update dynamic iframe to pass query string args
  • Loading branch information
mvandeusen authored Mar 30, 2020
2 parents 5061ece + 64aa68a commit c504973
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Pass query string to iframe URL.

## [0.1.2] - 2020-02-18
### Fixed
Expand Down
17 changes: 16 additions & 1 deletion react/DynamicIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ const DynamicIframe: StorefrontFunctionComponent<DynamicIframeProps> = ({
}) => {
const {
route: { params },
query = {},
} = useRuntime()

const queryString = Object.keys(query).reduce((acc, key) => {
return `${acc ? acc : '?'}${key}=${query[key]}&`
}, '')

let allParamsExist = true

const src = dynamicSrc.replace(/({[A-z0-9]*})/g, function(match: string) {
const thisParam = match.replace(/{|}/g, '')
if (!thisParam || !params[thisParam]) {
Expand All @@ -27,7 +34,15 @@ const DynamicIframe: StorefrontFunctionComponent<DynamicIframeProps> = ({
if (allParamsExist !== true || src == '' || src == undefined) {
return null
}
return <Iframe title={title} src={src} width={width} height={height} />

return (
<Iframe
title={title}
src={src + queryString}
width={width}
height={height}
/>
)
}

interface DynamicIframeProps {
Expand Down
8 changes: 4 additions & 4 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"classnames": "^2.2.6",
"ramda": "^0.26.1",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-dom": "^16.13.1",
"react-intl": "^2.7.2"
},
"devDependencies": {
Expand All @@ -25,10 +25,10 @@
"eslint-config-vtex-react": "^4.1.0",
"prettier": "^1.18.2",
"tslint-eslint-rules": "^5.4.0",
"typescript": "3.7.3",
"vtex.styleguide": "http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.styleguide@9.104.7/public/@types/vtex.styleguide",
"typescript": "3.8.3",
"vtex.css-handles": "http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.css-handles@0.4.1/public/@types/vtex.css-handles",
"vtex.render-runtime": "http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.render-runtime@8.88.0/public/@types/vtex.render-runtime",
"vtex.css-handles": "http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.css-handles@0.4.1/public/@types/vtex.css-handles"
"vtex.styleguide": "http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.styleguide@9.104.7/public/@types/vtex.styleguide"
},
"version": "0.1.2"
}
28 changes: 23 additions & 5 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4343,7 +4343,17 @@ react-apollo@^2.5.2:
ts-invariant "^0.4.2"
tslib "^1.9.3"

react-dom@^16.8.3, react-dom@^16.8.4:
react-dom@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.19.1"

react-dom@^16.8.4:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962"
integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ==
Expand Down Expand Up @@ -4691,6 +4701,14 @@ scheduler@^0.15.0:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand Down Expand Up @@ -5194,10 +5212,10 @@ type-fest@^0.5.2:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.5.2.tgz#d6ef42a0356c6cd45f49485c3b6281fc148e48a2"
integrity sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==

typescript@3.7.3:
version "3.7.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69"
integrity sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==
typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==

typescript@^3.3.3333:
version "3.5.3"
Expand Down

0 comments on commit c504973

Please sign in to comment.