-
Notifications
You must be signed in to change notification settings - Fork 15
fix: pricerangeinput #1437
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?
fix: pricerangeinput #1437
Conversation
Tagging OptionsShould a new tag be published when this PR is merged?
|
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
vtex/utils/transform.ts (2)
787-789: Add explanatory comments for the price range normalization logic.The purpose and format of this transformation aren't immediately clear. Adding comments would help future maintainers understand why this normalization is necessary and what format it expects.
Apply this diff:
+ // Normalize price range format from legacy encoding (e.g., de-3490-a-5690) + // to decimal format (e.g., de-34.90-a-56.90) for full-path filters if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) { value = value.map(v => v.replace(/-(\d{2})$/, '.$1')); }
783-789: Document the relationship between price format normalization inlegacyFacetToFilterandlegacyFacetsNormalize.These functions handle different price range formats in separate code paths. The new code in
getLink(lines 783-789) transformsde-34-a-56-90tode-34-a-56.90, whilelegacyFacetsNormalize(lines 897-911) transformsde-34,90-a-56,90to34.90:56.90. Add a comment explaining which format each normalizes and their distinct purposes to prevent future confusion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
vtex/utils/transform.ts(1 hunks)
🔇 Additional comments (1)
vtex/utils/transform.ts (1)
788-788: Remove this review comment - it is based on a false premise about VTEX's price format.VTEX legacy URLs use a dot as the decimal separator with two decimal places, which is precisely what this transformation assumes. The code is specifically designed to handle VTEX price range facets from the API (used for
PriceRangesin productListingPage.ts), not arbitrary prices. The precondition pattern/de-\d+-a-\d+-\d+/is a VTEX-specific facet URL format, and the regex transformation aligns perfectly with VTEX's standard 2-decimal format. There is no risk of varying decimal places because the VTEX API enforces the standard format.Likely an incorrect or invalid review comment.
| if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) { | ||
| value = value.map(v => v.replace(/-(\d{2})$/, '.$1')); | ||
| } |
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.
🧩 Analysis chain
Incomplete decimal separator normalization for price ranges.
The current logic only replaces the last hyphen-number pair (e.g., converting de-3490-a-5690 to de-3490-a-56.90), leaving the "from" price un-normalized. For consistency, both decimal separators should be converted.
Consider this fix to normalize both prices:
- if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
- value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
- }
+ if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) {
+ value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4'));
+ }This assumes the format is de-[from_int][from_dec]-a-[to_int][to_dec] where the last 2 digits of each number represent the decimal part. If the format is different, please clarify with a comment and adjust the regex accordingly.
Verify the expected input format by running:
🏁 Script executed:
#!/bin/bash
# Description: Find examples of price range URLs in the codebase to understand the format
# Search for price range patterns in code and comments
rg -n -C3 "de-\d+-a-\d+" --type=ts
# Search for test files that might show expected formats
fd -e test.ts -e spec.ts -x rg -l "pricerange|price.range" {}Length of output: 0
---
🏁 Script executed:
```shell
#!/bin/bash
# Read the actual file to see the code context and function
cat vtex/utils/transform.ts | head -850 | tail -70
Length of output: 2183
🏁 Script executed:
#!/bin/bash
# Search for test files and usage examples
fd -name "*.test.ts" -o -name "*.spec.ts" | head -20
# Search for references to legacyFacetToFilter or legacyFacetsNormalize
rg -n "legacyFacet|pricerange" --type=ts -i | head -40Length of output: 8931
🏁 Script executed:
#!/bin/bash
# Search for patterns matching the code being reviewed
rg -n "hasToBeFullpath" --type=ts -C2 | head -50Length of output: 1448
---
🏁 Script executed:
```shell
#!/bin/bash
# Read the legacyFacetsNormalize function to understand existing normalization
sed -n '897,920p' vtex/utils/transform.ts
Length of output: 944
🏁 Script executed:
#!/bin/bash
# Read the normalizeFacet function to see if it handles price normalization
sed -n '1034,1050p' vtex/utils/transform.tsLength of output: 412
🏁 Script executed:
#!/bin/bash
# Search for test files or examples with price range patterns
find . -name "*.test.ts" -o -name "*.spec.ts" | xargs grep -l "de-.*-a-" 2>/dev/null || echo "No test files found with pattern"
# Search for comments or documentation about price format
rg -n "de-\d+" --type=ts -B2 -A2 | head -60Length of output: 3181
🏁 Script executed:
#!/bin/bash
# Look for facet.Link examples in the codebase to understand the input format
rg -n "facet\.Link\|Link.*split" --type=ts -B1 -A1 | head -40Length of output: 0
Incomplete decimal separator normalization for price ranges.
The current logic at lines 787-789 only replaces the last hyphen-number pair, leaving the "from" price un-normalized. For example, de-3490-a-5690 becomes de-3490-a-56.90 instead of de-34.90-a-56.90.
Consider this fix to normalize both prices:
- if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
- value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
- }
+ if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) {
+ value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4'));
+ }This assumes the input format is de-[from_int][from_dec]-a-[to_int][to_dec] where the last 2 digits of each price represent the decimal part. The updated regex correctly transforms both price components, aligned with the expected format documented in legacyFacetsNormalize.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) { | |
| value = value.map(v => v.replace(/-(\d{2})$/, '.$1')); | |
| } | |
| if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) { | |
| value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4')); | |
| } |
🤖 Prompt for AI Agents
In vtex/utils/transform.ts around lines 787 to 789, the current mapping only
converts the trailing two digits of the "to" price to a decimal, leaving the
"from" price un-normalized; update the mapping so both price components are
normalized by replacing the final two-digit groups of each price with a
dot-prefixed decimal (i.e., convert both the two trailing digits before "-a-"
and the two trailing digits at the end), using a single replace call with a
regex that targets both positions and a replacement function that inserts the
'.' before the two-digit groups.
fix price range input string
Summary by CodeRabbit