-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(other): MERC-7797 Added feature to render Widgets in the regions of supported page types. #726
Conversation
2899f97
to
3f483f3
Compare
const cachedGraphQLResponse = cache.get(graphQLDataReqSignature); | ||
|
||
if (internals.options.useCache && cachedGraphQLResponse) { | ||
({ regionResponse } = cachedGraphQLResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's extracting cached value of regionResponse
instead of making a graphQL call.
8d5e5d3
to
c650ef2
Compare
♻️ Addressed comments. |
* @param {number} entityId | ||
* @returns {Promise<renderedRegions: array}>} | ||
*/ | ||
async function getRenderedRegionsByPageTypeAndEntityId({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda surprised these need to be two separate functions, isn't really just affecting the query slightly when you don't supply an entity id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait right as I clicked the button I realized that parsing the response is slightly different too, yeah fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the GraphQL Playground to build the query it pretty handy because it does the validation of whether a pageType needs entityId or not. I am guessing that was the reasoning for having separate function as its difficult to make a argument conditionally required on the same function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry I was speaking of these functions, not the graphql query itself. But anyway yeah given that it's a different graphql field think this makes sense.
UNSUBSCRIBE: 'UNSUBSCRIBE', | ||
}; | ||
|
||
const templateFileToPageTypeMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really wish we could fetch this from somewhere or include it as a library or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mapping is in Storefront also now, so we technically are doing this in 3 places. BCApp, Storefront and now in Stencil CLI 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we in hurry with this ticket, so we are introducing here tech debt? If so, lets create a ticket to address it by adding an endpoint to Storefront (or other more relevant service)
server/lib/page-type-util.js
Outdated
return false; | ||
} | ||
|
||
return pageTypeWithEntityId.indexOf(pageType) >= 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually necessary? Can we not just check if the entityId is present and just trust that it's correct rather than checking another list we have to maintain here?
@@ -137,6 +138,7 @@ class PencilResponse { | |||
this.data.context.in_production = false; | |||
|
|||
paper.addDecorator(makeDecorator(request, this.data.context)); | |||
paper.setContent(this.data.renderedRegions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What?!? My mind is blown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have paper helper which we use in Storefront renderer as well which takes input of an object with keys as the regionName and value as the html. So I am formatting it and just feeding it here. I was doing literal search a replace before I thought of figuring out how storefront renderer does it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah sorry that was not actually a question, I was just amazed how simple it was. I know you told me before about this, just seeing it is kind of amazing.
|
||
const networkUtils = new NetworkUtils(); | ||
|
||
const internals = { | ||
options: {}, | ||
cacheTTL: 1000 * 15, // 15 seconds | ||
graphQLCacheTTL: 1000 * 300, // 5 minutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought for the future, it might be worth considering literally never refreshing the cache without user intervention, or making it a cli setting or something. Just imagining in the vast majority of use cases the user wouldn't be expecting or needing the widgets to update. (I don't really have a sense for how many users are using stencil cli at any given time, admittedly it's probably only a handful so not a huge deal at the moment).
Mostly just reacting to this sort of being a weird in-between solution that doesn't serve anyone that well. If you do want to see widgets changing (if you're working on them at the same time as you use stencil cli), 5 minutes is really long and you're probably better off restarting stencil cli each time you change them. And if you don't, there's no need to ever refresh the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an option to start the stencil-cli without using cache stencil start --no-cache
. So it might be work changing the TTL to say 60mins or more. I think the TTL is not optional and would throw an error if not provided.
9331828
to
785ffa2
Compare
♻️ Addressed comments. |
lib/content-api-client.js
Outdated
}); | ||
|
||
const { | ||
site: { content }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is content
variable for readability?
It's possible to do like this:
site: { content }, | |
const { site: { regions: { renderedRegionsByPageType } } } = response.data.data |
lib/content-api-client.js
Outdated
renderedRegions: regions, | ||
}; | ||
} catch (err) { | ||
console.log(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.error
lib/content-api-client.js
Outdated
renderedRegions: regions, | ||
}; | ||
} catch (err) { | ||
console.log(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.error
It's also possible to highlight error with red color like here https://github.com/bigcommerce/stencil-cli/blob/master/lib/release/release.js#L145
server/index.js
Outdated
@@ -27,6 +27,8 @@ function buildManifest(srcManifest, options) { | |||
pluginsByName['./plugins/renderer/renderer.module'].customLayouts = | |||
options.dotStencilFile.customLayouts; | |||
pluginsByName['./plugins/renderer/renderer.module'].themePath = options.themePath; | |||
pluginsByName['./plugins/renderer/renderer.module'].storeUrl = | |||
parsedSecureUrl.protocol + '//' + parsedSecureUrl.host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a variable storeUrl
and reuse it on line 16 as well
UNSUBSCRIBE: 'UNSUBSCRIBE', | ||
}; | ||
|
||
const templateFileToPageTypeMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we in hurry with this ticket, so we are introducing here tech debt? If so, lets create a ticket to address it by adding an endpoint to Storefront (or other more relevant service)
@jairo-bc I have created a ticket MERC-7975 to address the mapping tech debt and will look into it in a follow up PR. |
♻️ Addressed all the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What?
Added logic to rendered the widgets in the respective regions of a page. This is done by making GraphQL request for each page request and setting the content via the paper handlebar helper
setContent
.Tickets / Documentation
Add links to any relevant tickets and documentation.
@junedkazi Would appreciate your input on this PR.