Skip to content

Conversation

@thiagopereira-vtex
Copy link

This pull request adds support for passing custom Activity Flow data attributes to product summary components, enabling more flexible analytics and tracking. The changes introduce new props to handle these attributes and ensure they are correctly spread onto relevant HTML elements in both individual product summaries and product summary lists.

Activity Flow data attributes support:

  • Added an afDataAttributes prop to ProductSummaryCustom and ProductSummaryWrapper, allowing custom data attributes to be spread onto the section element for each product summary. [1] [2] [3] [4]
  • Introduced an afDataAttributesList prop to ProductSummaryList and ProductSummaryListWithoutQuery, enabling an array of data attribute objects to be passed and applied to each corresponding product summary in the list. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated rendering logic in ProductSummaryListWithoutQuery to pass the correct data attributes from afDataAttributesList to each product summary based on its index. [1] [2]
  • Extended type definitions to document the new props and provide usage examples for Activity Flow data attributes. [1] [2] [3] [4]

@thiagopereira-vtex thiagopereira-vtex requested review from a team as code owners October 24, 2025 12:43
@thiagopereira-vtex thiagopereira-vtex requested review from RodrigoTadeuF, leo-prange-vtex and vmourac-vtex and removed request for a team October 24, 2025 12:43
@vtex-io-ci-cd
Copy link
Contributor

vtex-io-ci-cd bot commented Oct 24, 2025

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot
Copy link

vtex-io-docs-bot bot commented Oct 24, 2025

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

Copy link
Contributor

@salesfelipe salesfelipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it is missing a changelog entry

* { 'data-af-category': 'clothing', 'data-af-position': '2' }
* ]}
*/
afDataAttributesList?: Array<Record<string, string>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it is better to be a function instead. Something like (product: Product) => Record<string,string>

So each element calls the function before rendering and gets the data attributes..

Just wondering because by receiving a fixed list, you need the data upfront, which is fine for Recommendations, but not for the other Static shelfs and since this is a shared component....

@salesfelipe salesfelipe added the enhancement New feature or request label Oct 30, 2025
Copy link
Contributor

@salesfelipe salesfelipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but I'm wondering wether we should be so explicity about Acitivitty Flow. This feature allow us to add data attributes to our HTML Elements, do we really want to be attached to AF on this level?

# Conflicts:
#	CHANGELOG.md
#	react/ProductSummaryCustom.tsx
style={{ maxWidth: PRODUCT_SUMMARY_MAX_WIDTH }}
ref={inViewRef}
data-van-aid={eventParameters}
{...(extraProductProps ?? {})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to put it as the first attribute on the section? The idea is to avoid overriding attributes defined above with this spread, like className, so we don't change the value of attributes set by the component itself.

listName?: string
position?: number
placement?: string
extraProductProps?: Record<string, string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to prefix all attributes with data-*? It can be a check.
Is an way to avoid others unexpected attributes.

thiagopereira-vtex and others added 2 commits December 8, 2025 17:01
…yCustom

Added a runtime validation to ensure all keys in extraProductProps start with 'data-'. Invalid keys will trigger a console warning. Updated the type definition for extraProductProps to enforce this requirement.
Comment on lines 53 to 66
// Validate that all keys in extraProductProps start with 'data-'
if (extraProductProps) {
const invalidKeys = Object.keys(extraProductProps).filter(
(key) => !key.startsWith('data-')
)

if (invalidKeys.length > 0) {
console.warn(
`extraProductProps contains keys that don't start with 'data-': ${invalidKeys.join(
', '
)}`
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code warns about keys that don't start with data-, but it doesn't filter them out, extraProductProps is still passed to the section as-is.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for custom Activity Flow data attributes to product summary components, enabling flexible analytics and tracking capabilities.

  • Introduces extraProductProps and buildExtraProductProps props for passing custom data attributes to product summaries
  • Implements sanitization logic to ensure only valid data-* attributes are applied
  • Extends both individual product summary and list components to support these new props

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
react/ProductSummaryCustom.tsx Adds extraProductProps prop, implements sanitizeDataAttributes function to validate data attributes, and spreads sanitized attributes onto the section element
react/ProductSummaryListWithoutQuery.tsx Introduces buildExtraProductProps function prop that generates product-specific data attributes and passes them to individual product summaries
react/ProductSummaryList.tsx Adds buildExtraProductProps prop and forwards it to ProductSummaryListWithoutQuery component
react/utils/shouldShowSponsoredBadge.ts Minor whitespace formatting change
react/mocks/vtex.render-runtime.js Minor whitespace formatting change
CHANGELOG.md Documents the addition of optional props support for Product Summary components

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <[email protected]>
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
Copy link
Contributor

@vmourac-vtex vmourac-vtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagopereira-vtex pedi um review do Copilot para ajudar. Gostei de algumas recomendações, acho que vale olhar.
No mais faço só uma sugestão de mover a função de sanitização para um local mais adequado.

Comment on lines 36 to 67
/**
* Type for data attributes that must start with 'data-'
* Note: TypeScript 3.9 doesn't support template literal types,
* so this is a documentation type. Runtime validation ensures keys start with 'data-'
*/
type DataAttributes = Record<string, string>

const sanitizeDataAttributes = (
extraProductProps?: DataAttributes
): DataAttributes | undefined => {
if (!extraProductProps) return undefined

const sanitized: DataAttributes = {}
const invalidKeys: string[] = []

Object.keys(extraProductProps).forEach((key) => {
if (key.startsWith('data-')) {
sanitized[key] = extraProductProps[key]
} else {
invalidKeys.push(key)
}
})

if (invalidKeys.length > 0) {
console.warn(
`extraProductProps contains keys that don't start with 'data-': ${invalidKeys.join(
', '
)}`
)
}

return sanitized
Copy link
Contributor

@vmourac-vtex vmourac-vtex Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagopereira-vtex Além da consideração acima feita pelo Copilot, sobre o retorno da função, sugiro somente de mover a função para fora ProductSummaryCustom, para a pasta /utils/, em um arquivo dedicado ou dentro de /utils/normalize.

A ideia é só desacoplar a função do componente para torna-la mais testável e reutilizável

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
@vtex-apps vtex-apps deleted a comment from Copilot AI Dec 9, 2025
Moved the data attributes type definition and sanitization logic into a separate utility function. This improves code organization and maintains the validation of keys starting with 'data-'. Updated the component to utilize the new utility for handling extra product properties.
Copy link
Contributor

@vmourac-vtex vmourac-vtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants