Skip to content

feat: add showRegion, showCountry props for Address#143

Open
asanehisa wants to merge 3 commits intomainfrom
address
Open

feat: add showRegion, showCountry props for Address#143
asanehisa wants to merge 3 commits intomainfrom
address

Conversation

@asanehisa
Copy link
Contributor

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: fea114b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Walkthrough

This pull request extends the Address component with showCountry and showRegion boolean flags (both defaulting to true). When using locale-based address formatting, these flags filter out the corresponding address fields before rendering. A new cleanupAddressLine utility handles comma normalization by trimming leading/trailing commas and collapsing consecutive separators. The changes include new Storybook story variants and comprehensive test coverage validating the feature across US and Argentine address formats. Explicit custom lines bypass the filtering logic but still undergo cleanup.

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate relatedness to the changeset. Add a pull request description explaining the purpose, motivation, and behavior of the new showRegion and showCountry props.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add showRegion, showCountry props for Address' directly and accurately describes the primary changes—adding two new boolean props to the Address component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch address

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@asanehisa asanehisa marked this pull request as ready for review March 5, 2026 19:59
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
packages/pages-components/src/components/address/address.test.tsx (2)

103-117: Assertion logic may pass incorrectly if only one element exists.

The expression expect(countryEl && regionEl).toBeTruthy() will only be truthy if both elements exist. If only one is present (e.g., countryEl is truthy but regionEl is null), the test would fail even though it's testing that custom lines bypass filtering. This is actually correct behavior for this test case, but separate assertions would make the intent clearer and provide better failure diagnostics.

Suggested improvement for clarity
-    expect(countryEl && regionEl).toBeTruthy();
+    expect(countryEl).toBeTruthy();
+    expect(regionEl).toBeTruthy();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/pages-components/src/components/address/address.test.tsx` around
lines 103 - 117, The combined assertion using `expect(countryEl &&
regionEl).toBeTruthy()` can hide which element is missing; update the test "does
not apply showCountry/showRegion when custom lines are provided" to assert each
element separately by replacing the single boolean expression with two
assertions `expect(countryEl).toBeTruthy()` and `expect(regionEl).toBeTruthy()`
so failures clearly indicate whether `countryEl` or `regionEl` (queried in the
test) is missing when rendering the `Address` component with
`lines={[["region"], ["countryCode"]]}`.

94-101: Assertion logic may not verify both elements as intended.

The expression expect(countryEl && regionEl).toBeFalsy() will pass if either element is null/falsy, not necessarily both. If countryEl is null, the expression short-circuits and evaluates to null (falsy) regardless of regionEl.

Consider using separate assertions for clarity:

Proposed fix
-    expect(countryEl && regionEl).toBeFalsy();
+    expect(countryEl).toBeFalsy();
+    expect(regionEl).toBeFalsy();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/pages-components/src/components/address/address.test.tsx` around
lines 94 - 101, The test "hides both country and region in default format when
both are false" currently uses a combined assertion that can short-circuit;
update the assertion in address.test.tsx to assert each element individually:
check that the result of screen.queryByText("US") (countryEl) is null/falsy and
separately that screen.queryByText("AL") (regionEl) is null/falsy so both
absence conditions are verified for the Address component when showCountry and
showRegion are false.
packages/pages-components/CHANGELOG.md (1)

5-9: Missing changelog entry for the new showCountry and showRegion feature.

This PR adds new showCountry and showRegion props to the Address component, but the changelog only contains formatting changes. A new entry should be added under "New Features" to document this addition.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/pages-components/CHANGELOG.md` around lines 5 - 9, Changelog is
missing an entry for the new Address component props; add a "New Features"
bullet documenting the addition of showCountry and showRegion props for the
Address component (mention the prop names showCountry and showRegion and the
Address component), following the existing changelog style (short description,
PR link and commit hash format) and place it under the "New Features" section
alongside the other entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/pages-components/CHANGELOG.md`:
- Around line 5-9: Changelog is missing an entry for the new Address component
props; add a "New Features" bullet documenting the addition of showCountry and
showRegion props for the Address component (mention the prop names showCountry
and showRegion and the Address component), following the existing changelog
style (short description, PR link and commit hash format) and place it under the
"New Features" section alongside the other entries.

In `@packages/pages-components/src/components/address/address.test.tsx`:
- Around line 103-117: The combined assertion using `expect(countryEl &&
regionEl).toBeTruthy()` can hide which element is missing; update the test "does
not apply showCountry/showRegion when custom lines are provided" to assert each
element separately by replacing the single boolean expression with two
assertions `expect(countryEl).toBeTruthy()` and `expect(regionEl).toBeTruthy()`
so failures clearly indicate whether `countryEl` or `regionEl` (queried in the
test) is missing when rendering the `Address` component with
`lines={[["region"], ["countryCode"]]}`.
- Around line 94-101: The test "hides both country and region in default format
when both are false" currently uses a combined assertion that can short-circuit;
update the assertion in address.test.tsx to assert each element individually:
check that the result of screen.queryByText("US") (countryEl) is null/falsy and
separately that screen.queryByText("AL") (regionEl) is null/falsy so both
absence conditions are verified for the Address component when showCountry and
showRegion are false.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 261fb068-c8be-4ab9-b5a9-0ba2c8a29044

📥 Commits

Reviewing files that changed from the base of the PR and between 4c0f44d and fea114b.

⛔ Files ignored due to path filters (3)
  • packages/pages-components/.storybook/snapshots/__snapshots__/components-address--address-hide-country-and-region.png is excluded by !**/*.png
  • packages/pages-components/.storybook/snapshots/__snapshots__/components-address--address-hide-country.png is excluded by !**/*.png
  • packages/pages-components/.storybook/snapshots/__snapshots__/components-address--address-hide-region.png is excluded by !**/*.png
📒 Files selected for processing (5)
  • packages/pages-components/CHANGELOG.md
  • packages/pages-components/src/components/address/address.stories.tsx
  • packages/pages-components/src/components/address/address.test.tsx
  • packages/pages-components/src/components/address/address.tsx
  • packages/pages-components/src/components/address/types.ts

expect(countryEl && regionEl).toBeFalsy();
});

it("does not apply showCountry/showRegion when custom lines are provided", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this what we want? Obviously an ambiguous situation, could see it either way

Copy link
Contributor Author

@asanehisa asanehisa Mar 5, 2026

Choose a reason for hiding this comment

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

Oh i had assumed yes based on:

Update pages-components to allow for hiding both country and region (separately) when using the standard formatting.

but might've misunderstood

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I wasn't specifically thinking about this when I wrote that. I feel like we should honor the options even if you use custom. It would be dumb to use both but if you have the option then it makes sense that it works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you want a comma if there's no region

expect(countryEl && regionEl).toBeFalsy();
});

it("does not apply showCountry/showRegion when custom lines are provided", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I wasn't specifically thinking about this when I wrote that. I feel like we should honor the options even if you use custom. It would be dumb to use both but if you have the option then it makes sense that it works.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants