Skip to content
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

fix(masthead): container should respect user's L0 data #11420

Conversation

jkaeser
Copy link
Member

@jkaeser jkaeser commented Jan 19, 2024

Related Ticket(s)

Previously fixed in #10986, but that was unwittingly wiped away by #11252

Description

Fixes an issue where <c4d-masthead-container> wipes away user-set L0 data with translations fetched from an API.

This PR takes a different approach from the original fix. The root problem is that the masthead container isn't aware of any l0Data passed in before setting that property with translation data. I figured we can make the container a little smarter and handle the logic internally rather than adding another property to the masthead composite and complicating the public API.

In order to facilitate this, I needed the ConnectMixin to pass a reference to the class instance into the mapStateToProps function it expects classes to define. This empowers the container to first check if it has L0 data before resorting to the translations API data.

As a result, users can reliably set the l0Data property on either <c4d-masthead-container> or <c4d-masthead-composite> and expect the same outcome.

Changelog

New

  • ConnectMixin passes a class instance reference as an argument in the mapStateToProps function.

Changed

  • <c4d-masthead-container> will prefer using L0 data passed by user before resorting to automatically fetched translation data.

It can be useful to check instance data before reaching out to Redux store
to set properties.
@jkaeser jkaeser added package: web components Work necessary for the IBM.com Library web components package owner: Innovation Team used when the engineering work will be done by Hybrid Cloud with DDS engineers as consultants labels Jan 19, 2024
@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Jan 19, 2024

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Jan 19, 2024

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Jan 19, 2024

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Jan 19, 2024

@jkaeser jkaeser marked this pull request as ready for review January 19, 2024 19:54
@jkaeser jkaeser requested a review from a team as a code owner January 19, 2024 19:54
@jkaeser jkaeser requested review from ariellalgilmore, annawen1, m4olivei and andy-blum and removed request for a team January 19, 2024 19:54
@jkaeser
Copy link
Member Author

jkaeser commented Jan 19, 2024

@annawen1 I'm curious to hear your thoughts on this one, since it takes a different approach to a fix you added back in September.

@annawen1
Copy link
Member

annawen1 commented Feb 1, 2024

@annawen1 I'm curious to hear your thoughts on this one, since it takes a different approach to a fix you added back in September.

Oh yeah, I didn't think to look into the ConnectMixin! This LGTM!

Copy link
Contributor

@IgnacioBecerra IgnacioBecerra left a comment

Choose a reason for hiding this comment

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

LGTM!!

@IgnacioBecerra IgnacioBecerra added the Ready to merge Label for the pull requests that are ready to merge label Feb 1, 2024
@kodiakhq kodiakhq bot merged commit cf2f60d into carbon-design-system:main Feb 1, 2024
12 of 19 checks passed
@jkaeser jkaeser deleted the fix/masthead-container-custom-links branch February 2, 2024 15:58
kodiakhq bot pushed a commit that referenced this pull request Feb 29, 2024
### Related Ticket(s)

none

### Description

#11420 ensures support for customizing the L0 nav items, but it doesn't account for the `navLinks` property. This PR adds that support, and it also includes a test to make sure L0 customization is working as expected.

## To test

1. Visit this Codepen example: https://codepen.io/jakaeser/pen/LYavrKK
2. See that the custom L0 nav items are not applying.
3. Comment out the v2 latest CDN <script>, then uncomment the deploy preview CDN <script>
4. Verify the custom L0 nav items apply.
5. In the Pen's JS, replace the `l0Data` property with `navLinks`. Verify the custom L0 items still apply.

### Changelog

**New**

- Adds an e2e test for customizing L0 items.

**Changed**

- Supports `navLinks` property when using `<c4d-masthead-container>` and customizing L0 items.
- Corrects the prefixes used in masthead e2e tests.

<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "test: e2e": Codesandbox examples and e2e integration tests -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
@IgnacioBecerra IgnacioBecerra self-assigned this Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 eyes needed owner: Innovation Team used when the engineering work will be done by Hybrid Cloud with DDS engineers as consultants package: web components Work necessary for the IBM.com Library web components package Ready to merge Label for the pull requests that are ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants