-
Notifications
You must be signed in to change notification settings - Fork 13
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
add specification filter #11
base: master
Are you sure you want to change the base?
Conversation
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:
And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.
|
Beep boop 🤖 I noticed you didn't make any changes at the
In order to keep track, I'll create an issue if you decide now is not a good time
|
Hey, can you leave a workspace to test it? |
react/ProductSpecification.tsx
Outdated
let specifications = group.specifications; | ||
|
||
if (filter.specificationNames?.length > 0 && filter.type == 'show') { | ||
specifications = specifications.filter((specification) => | ||
filter.specificationNames.includes(specification.originalName) ) | ||
} | ||
if (filter.specificationNames?.length > 0 && filter.type == 'hide') { | ||
specifications = specifications.filter((specification) => | ||
!filter.specificationNames.includes(specification.originalName) ) | ||
} |
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.
I think a way to remove this mutability. Feel free to argue 😅
What do you think about this suggestion?
const identityNoop = <T extends any>(x) => x // type the generics better, if possible.
type specificationFilterFunction = (specificationName: string) => boolean
interface UseFilterSpecification {
specification: Array<{ originalName: string }>
filters: {
show: specificationFilterFunction,
hide: specificationFilterFunction,
}
}
const filterSpecification = ({ specification, filters: { show, hide } }: UseFilterSpecification) => {
return specifications.filter(({ originalName }) => show(originalName) && hide(originalName))
}
let specifications = group.specifications; | |
if (filter.specificationNames?.length > 0 && filter.type == 'show') { | |
specifications = specifications.filter((specification) => | |
filter.specificationNames.includes(specification.originalName) ) | |
} | |
if (filter.specificationNames?.length > 0 && filter.type == 'hide') { | |
specifications = specifications.filter((specification) => | |
!filter.specificationNames.includes(specification.originalName) ) | |
} | |
const specifications = filterSpecification({ | |
specifications: group.specifications, | |
filters: { | |
hide: filter.type === 'show' ? (specification) => filter.specificationNames.includes(specification) : identityNoop, | |
show: filter.type === 'hide' ? !(specification) => !filter.specificationNames.includes(specification) : identityNoop | |
} | |
}) |
That's it 😄 , you can rename or change or even disagree. If you feel more comfortable discussing in Portuguese, we can switch to PT-BR.
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 suggestion seems not to escalate if we want to handle unlimited filters, but for now, it looks good.
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.
I think a way to remove this mutability. Feel free to argue 😅
What do you think about this suggestion?
const identityNoop = <T extends any>(x) => x // type the generics better, if possible. type specificationFilterFunction = (specificationName: string) => boolean interface UseFilterSpecification { specification: Array<{ originalName: string }> filters: { show: specificationFilterFunction, hide: specificationFilterFunction, } } const filterSpecification = ({ specification, filters: { show, hide } }: UseFilterSpecification) => { return specifications.filter(({ originalName }) => show(originalName) && hide(originalName)) }That's it 😄 , you can rename or change or even disagree. If you feel more comfortable discussing in Portuguese, we can switch to PT-BR.
I make some adapts to fix errors but i'm not find the cause of this error: Argument of type 'string' is not assignable to parameter of type 'never'.
This just appear in hide function.
react/ProductSpecification.tsx
Outdated
let specifications = group.specifications; | ||
|
||
if (filter.specificationNames?.length > 0 && filter.type == 'show') { | ||
specifications = specifications.filter((specification) => | ||
filter.specificationNames.includes(specification.originalName) ) | ||
} | ||
if (filter.specificationNames?.length > 0 && filter.type == 'hide') { | ||
specifications = specifications.filter((specification) => | ||
!filter.specificationNames.includes(specification.originalName) ) | ||
} |
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 suggestion seems not to escalate if we want to handle unlimited filters, but for now, it looks good.
Co-authored-by: Igor Brasileiro <brasileiro456@gmail.com>
Co-authored-by: Igor Brasileiro <brasileiro456@gmail.com>
@IncognitaDev, we've created this [CONTRIBUTING.md] to help new contributions. Can you take a look there? |
Sure, but I don't find it. Wich repo contains ? |
What does this PR do? *
this PR add prop to filter specifications inside group specifications
How to test it? *
create a product specifications table and pass
filter
prop toproduct-specifications
likefilter
props osproduct-specification-group
but withspecificationNames
insteadspecificationGroups
.Describe alternatives you've considered, if any. *
Related to / Depends on *