[CDX-418] Feature: Add componentOverrides to FilterGroup#226
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a componentOverrides / filterGroupOverrides API to enable consumer customization of FilterGroup subcomponents (and the whole group) via render-props or static JSX, with accompanying Storybook examples and tests.
Changes:
- Introduces new override types (
FilterGroupOverrides,FilterGroupRenderProps, etc.) insrc/types.ts. - Wires
filterGroupOverridesthroughFiltersandCioPlpGridintoFilterGroupascomponentOverrides. - Adds Storybook stories and Jest tests validating override behavior (root/header/optionsList/rangeSlider).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Adds new public types for FilterGroup overrides and render-props payload. |
| src/components/Filters/Filters.tsx | Adds filterGroupOverrides prop and passes to each FilterGroup. |
| src/components/Filters/FilterGroup.tsx | Wraps default subtrees with RenderPropsWrapper to support slot overrides. |
| src/components/CioPlpGrid/CioPlpGrid.tsx | Extends filterConfigs to include filterGroupOverrides and forwards configs to Filters. |
| src/index.ts | Exports FilterGroupProps (types are also re-exported via export * from './types'). |
| src/stories/components/Filters/Filters.stories.tsx | Adds examples demonstrating each override slot. |
| src/stories/components/CioPlpGrid/CioPlpGrid.stories.tsx | Adds an example demonstrating overrides via filterConfigs. |
| spec/components/Filters/Filters.test.jsx | Adds integration tests for Filters.filterGroupOverrides. |
| spec/components/Filters/FilterGroup.test.jsx | Adds unit tests for FilterGroup.componentOverrides. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
esezen
left a comment
There was a problem hiding this comment.
Looking great, thanks for working on this!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "typescript": "^4.9.4", | ||
| "vite": "^6.3.5", | ||
| "vite-plugin-css-injected-by-js": "^3.1.0", | ||
| "webpack": "^5.94.0" | ||
| "webpack": "^5.94.0", | ||
| "@constructor-io/constructorio-ui-components": "^1.3.2" | ||
| }, |
There was a problem hiding this comment.
@constructor-io/constructorio-ui-components is added under devDependencies, but the library’s published .d.ts now references types from this package (e.g., ComponentOverrideProps, IncludeComponentOverrides). Consumers won’t have this installed when they depend on this package, which will break TypeScript type resolution. Move this to peerDependencies (and optionally also keep it in devDependencies for local development), or remove the external type reference by defining equivalent types locally.
|
|
||
| /** | ||
| * Render props passed to every FilterGroup override function. | ||
| * Provides the full state needed to rebuild any part of a filter group. |
There was a problem hiding this comment.
The JSDoc for FilterGroupRenderProps says it provides the "full state needed to rebuild any part of a filter group", but the props omit several inputs that affect the default rendering/behavior (e.g., initialNumOptions, sliderStep / facetSliderSteps, and isHiddenFilterOptionFn). Either include those in FilterGroupRenderProps (so overrides can faithfully reproduce default behavior) or soften the wording to avoid overstating what’s provided.
| * Provides the full state needed to rebuild any part of a filter group. | |
| * Provides facet data and interaction handlers commonly needed to customize a filter group. |
| const componentOverrides = componentOverridesProp ?? context?.componentOverrides?.filterGroup; | ||
| const [isCollapsed, setIsCollapsed] = useState(false); | ||
|
|
||
| const toggleIsCollapsed = () => setIsCollapsed(!isCollapsed); |
There was a problem hiding this comment.
toggleIsCollapsed uses setIsCollapsed(!isCollapsed), which can apply a stale value under React’s concurrent rendering / batched updates. Use the functional updater form (setIsCollapsed(prev => !prev)) to guarantee correct toggling.
| const toggleIsCollapsed = () => setIsCollapsed(!isCollapsed); | |
| const toggleIsCollapsed = () => setIsCollapsed(prev => !prev); |
| initialBrowseResponse?: GetBrowseResultsResponse; | ||
| staticRequestConfigs?: Partial<RequestConfigs>; | ||
| useShopifyDefaults?: boolean; | ||
| componentOverrides?: Partial<PlpComponentOverrides>; |
There was a problem hiding this comment.
Why Partial here? Also can we please document this in the stories for props
There was a problem hiding this comment.
I will remove, probably all keys there will be not required anyway
There was a problem hiding this comment.
Code Review
This PR adds a well-structured componentOverrides system to FilterGroup, allowing consumers to replace any sub-component slot (root, header, optionsList, rangeSlider) with custom render functions or static nodes, backed by comprehensive tests and Storybook stories.
Inline comments: 7 discussions added
Overall Assessment:
Pull Request Checklist
Before you submit a pull request, please make sure you have to following:
PR Type
What kind of change does this PR introduce?