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

[Main nav] Navigation column [TP-266] #12047

Conversation

jhonatan-lopes
Copy link
Contributor

@jhonatan-lopes jhonatan-lopes commented Mar 14, 2024

Description

Implement a NavColumn and NavButton blocks.

Link to sample test page:
Related PRs/issues:

Checklist

Tests

  • Is the code I'm adding covered by tests?

Changes in Models:

  • Did I update or add new fake data?
  • [ ] Did I squash my migration?
  • [ ] Are my changes backward-compatible. If not, did I schedule a deploy with the rest of the team?

Documentation:

  • Is my code documented?
  • [ ] Did I update the READMEs or wagtail documentation?

Merge Method
💡❗Remember to use squash merge when merging non-feature branches into main

┆Issue is synchronized with this Jira Story

@jhonatan-lopes jhonatan-lopes changed the base branch from main to feature-branch/main-nav-dropdown March 14, 2024 17:59
class NavColumn(blocks.StructBlock):
title = blocks.CharBlock(max_length=100)
links = blocks.ListBlock(NavItem, min_num=1, max_num=4)
button = blocks.ListBlock(NavButton, required=False, min_num=0, max_num=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @jhonatan-lopes, is this dev pattern of encompassing a block w/ max_num=1 in a ListBlock useful for:

  1. Cleaner UI by hiding fields if child block not used
  2. Additional control by not requiring the child block itself (and then requiring the child block fields if it's been added)
  3. Anything else I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @robdivincenzo, this is documented here: https://docs.wagtail.org/en/stable/topics/streamfield.html#limiting-block-counts

Basically, we can use min_num and max_num to limit the number of blocks in a ListBlock or StreamBlock combination. In this case, we need at least one link and at most 4. Button, on the other hand, is optional, so we use the ListBlock with min_num=0 and max_num=1.

Copy link
Collaborator

@robdivincenzo robdivincenzo left a comment

Choose a reason for hiding this comment

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

LGTM @jhonatan-lopes, great work! One comment, but not a change request

@jhonatan-lopes jhonatan-lopes merged commit a96ddfa into feature-branch/main-nav-dropdown Mar 15, 2024
8 checks passed
@jhonatan-lopes jhonatan-lopes deleted the feature/TP-266/navigation-column branch March 15, 2024 16:55
jhonatan-lopes added a commit that referenced this pull request Mar 28, 2024
* Add description to NavLinkBlock

* Rename NavLinkBlock to NavItem

* Add NavButtonBlock

* Fix test name

* Add a NavColumn model
jhonatan-lopes added a commit that referenced this pull request Apr 3, 2024
* Add description to NavLinkBlock

* Rename NavLinkBlock to NavItem

* Add NavButtonBlock

* Fix test name

* Add a NavColumn model
jhonatan-lopes added a commit that referenced this pull request Apr 4, 2024
* Add description to NavLinkBlock

* Rename NavLinkBlock to NavItem

* Add NavButtonBlock

* Fix test name

* Add a NavColumn model
jhonatan-lopes added a commit that referenced this pull request Apr 18, 2024
* Add description to NavLinkBlock

* Rename NavLinkBlock to NavItem

* Add NavButtonBlock

* Fix test name

* Add a NavColumn model
jhonatan-lopes added a commit that referenced this pull request Apr 29, 2024
* Add description to NavLinkBlock

* Rename NavLinkBlock to NavItem

* Add NavButtonBlock

* Fix test name

* Add a NavColumn model
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.

2 participants