-
Notifications
You must be signed in to change notification settings - Fork 26
Improved: updated the DxpProductFeatures component(471-bopis) #437
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
base: main
Are you sure you want to change the base?
Conversation
…on selection emits the product id of selected variant.
…cy. (#471_productFeatures)
…uct as a prop, removed the use of the productFeature state, and refactored the component code (471-bopis)
Summary of ChangesHello @R-Sourabh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a new DxpProductFeatures component and a utility for sorting apparel sizes. The changes are a good step forward, but there are several critical and high-severity issues that need to be addressed. The new component is not reactive to prop changes, and the apparel sorter contains bugs in its sorting logic and lacks type safety. I've provided detailed comments and suggestions to fix these issues and improve the overall code quality.
| onMounted(async () => { | ||
| if (props.products && props.products.length > 0) { | ||
| extractProductFeatures(props.products); | ||
| } | ||
| }); |
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.
The component's logic for processing product features is currently in onMounted, which means it only runs once. If the products prop is updated, the component will not react to the changes, leading to stale data being displayed. To fix this, you should use a watcher on the products prop with the immediate: true option. This will run the logic on mount and whenever the products prop changes.
Please also remember to replace onMounted with watch in the import from vue.
watch(() => props.products, (products) => {
if (products && products.length > 0) {
extractProductFeatures(products);
}
}, { immediate: true });
| /^XXXXXXXL.*$/i, | ||
| /^9x.*$/i, | ||
| /^XXXXXXXXL.*$/i, | ||
| /^10x.*$/i, | ||
| /^XXXXXXXXXL.*$/i, | ||
| /^11x.*$/i, | ||
| /^XXXXXXXXXXL.*$/i, | ||
| /^12x.*$/i, | ||
| /^XXXXXXXXXXXL.*$/i, |
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 appear to be copy-paste errors in the regular expressions for sizes from 8x upwards. The number of 'X's in the regex does not match the size it's supposed to represent. For example, 8x points to a regex with 7 'X's. This will cause incorrect sorting for larger apparel sizes.
- The regex for
8xshould have 8 'X's. - The regex for
9xshould have 9 'X's. - ...and so on.
| /^XXXXXXXL.*$/i, | |
| /^9x.*$/i, | |
| /^XXXXXXXXL.*$/i, | |
| /^10x.*$/i, | |
| /^XXXXXXXXXL.*$/i, | |
| /^11x.*$/i, | |
| /^XXXXXXXXXXL.*$/i, | |
| /^12x.*$/i, | |
| /^XXXXXXXXXXXL.*$/i, | |
| /^XXXXXXXXL.*$/i, | |
| /^9x.*$/i, | |
| /^XXXXXXXXXL.*$/i, | |
| /^10x.*$/i, | |
| /^XXXXXXXXXXL.*$/i, | |
| /^11x.*$/i, | |
| /^XXXXXXXXXXXL.*$/i, | |
| /^12x.*$/i, | |
| /^XXXXXXXXXXXXL.*$/i, |
| const props = defineProps({ | ||
| productGroupId: String, | ||
| products: Array | ||
| }); |
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.
The props are not strongly typed. products: Array is not specific and can lead to runtime errors. Using PropType from Vue and defining an interface for the product objects will improve type safety and code clarity. This also helps other developers understand what shape of data the component expects.
To apply this, you'll need to import PropType from vue.
interface Product {
productId: string;
productFeatures: string[];
isVariant: string;
}
const props = defineProps({
productGroupId: String,
products: {
type: Array as PropType<Product[]>,
default: () => []
}
});
| function findRegexMatch(patterns: any, iteration: any, size: any): any { | ||
| if (patterns.length - 1 >= iteration) { | ||
| if (size.search(patterns[iteration].regex) >= 0) { | ||
| return { regex: patterns[iteration].regex, index: patterns[iteration].index, size: size, sizeVal: parseInt(size) || 0 }; | ||
| } | ||
| return findRegexMatch(patterns, iteration = iteration + 1, size); | ||
| } | ||
| return { regex: "No Match", index: parseInt(size.replace(/[^\d.-]/g, '')), size: size, sizeVal: parseInt(size) || 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.
This function uses any for all its types, contains a side effect in its recursive call (iteration = iteration + 1), and has a bug where index can become NaN for non-numeric sizes that don't match any regex. This can be rewritten as a simple, safer loop. The entire file suffers from a lack of typing, which should be addressed.
Note that matchSizesWithRegexes will need to be updated to call this new function correctly (without the iteration argument).
function findRegexMatch(patterns: { regex: RegExp, index: number }[], size: string): { regex: RegExp | string, index: number, size: string, sizeVal: number } {
for (const pattern of patterns) {
if (size.search(pattern.regex) >= 0) {
return { regex: pattern.regex, index: pattern.index, size: size, sizeVal: parseInt(size) || 0 };
}
}
return { regex: "No Match", index: parseInt(size.replace(/[^\d.-]/g, '')) || 0, size: size, sizeVal: parseInt(size) || 0 };
}| const productFeatures = ref({} as Record<string, string[]>); | ||
| const selectedFeatures = ref({} as Record<string, string>); | ||
| const selectedProductId = ref(''); |
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.
| /^x sm.*$/i, | ||
| /^xs.*$/i, | ||
| /^.* xs$/i, | ||
| /^xs/i, |
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.
| "lib": ["es2017","dom"] | ||
| }, |
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.
Related Issues
hotwax/bopis#471
Short Description and Why It's Useful
Screenshots of Visual Changes before/after (If There Are Any)
Is the changes contains any breaking change?
If there are any breaking change include those in the release notes file
Contribution and Currently Important Rules Acceptance