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 Menu #41

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft

Main Menu #41

wants to merge 28 commits into from

Conversation

sanjeevz3009
Copy link
Contributor

@sanjeevz3009 sanjeevz3009 commented Nov 26, 2024

What is the context of this PR?

Add a navigation app in Wagtail to manage the main menu, allowing for structured, customisable navigation.

How to review

  • Spin up the ONS BETA Web App Locally as normal.
  • Snippets -> Main Menu -> Add main menu.
  • Fill in the menu content -> After saving every time you should see the preview on the preview panel.
  • Go to Settings -> Navigation Settings -> Choose main menu -> Choose the menu shown so it can be displayed on the website.

Loom walkthrough of the main menu: ATTACH LINK HERE

Follow-up Actions

List any follow-up actions (if applicable), like needed documentation updates or additional testing.

@sanjeevz3009 sanjeevz3009 changed the title Main Menu Main Menu - Back-end Nov 26, 2024
Copy link
Contributor

@zerolab zerolab left a comment

Choose a reason for hiding this comment

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

I know this is a draft. Thought I'd leave a few notes to boot



# Custom LinkBlock to support both pages and URLs
class LinkBlock(StructBlock):
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


# Section StructBlock for columns
class SectionBlock(StructBlock):
section_link = LinkBlock(help_text="Main link for this section (Theme pages or external URLs).")
Copy link
Contributor

Choose a reason for hiding this comment

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

this may need a separate block definition as the requirement says the PageChooserBlock should be limited to Theme page (Wagtail docs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 92 to 94
class Meta:
verbose_name = "Main Menu"
verbose_name_plural = "Main Menus"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and gettext_lazy added.

…ed, section restricted to 3, URL label added, icon for navigation settings added and restricting it to so only 1 main menu can be created
Copy link
Contributor

@helenb helenb left a comment

Choose a reason for hiding this comment

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

Thanks @sanjeevz3009 I have tested locally and it all functions well. A couple of small comments on the validation and example help text.

cms/navigation/models.py Outdated Show resolved Hide resolved
cms/navigation/models.py Outdated Show resolved Hide resolved
cms/navigation/models.py Outdated Show resolved Hide resolved
@sanjeevz3009
Copy link
Contributor Author

Thanks @sanjeevz3009 I have tested locally and it all functions well. A couple of small comments on the validation and example help text.

@helenb Will push my latest code up as I haven't done that. It should be way better =) Might resolve some of the issues raised by you. Thanks Helen, will sort out any issues not addressed already locally and then push it up.

…ate one main menu instance in the wagtail admin. Migration file added.
…ks.base to be reusable across the project. LinkBlock from core.blocks.base is being used instead of the abstract class originally defined in models.py.
…enuViewSet added to restrict creating more than one main menu instance
@sanjeevz3009 sanjeevz3009 changed the title Main Menu - Back-end Main Menu Dec 9, 2024
@helenb
Copy link
Contributor

helenb commented Dec 9, 2024

I don't think the menu is using the styling quite as expected - compare my test with the menu settings (first screenshot) with what is in the prototype (second screenshot). I'm happy to pick that up as a follow-up task.

Screenshot 2024-12-09 at 15 26 12 Screenshot 2024-12-09 at 15 27 37

@sanjeevz3009
Copy link
Contributor Author

sanjeevz3009 commented Dec 9, 2024

@helenb

Thanks for testing this. I fixed the link issues.

As previously for highlights when a user selects a Wagtail page it didn't turn it into a link. Now it does. Same for the topic page.

Also fixed some other edge cases I missed out on previously, so now all should be good on that side.

Let me know if there are any further issues.

Now adding main menu content and it being usable on the website menu should be all good.

Screenshot 2024-12-09 at 18 31 58

So now we are just left with front-end alignment issues.

  • Where if you have only 2 columns the alignment looks weird and goes out of place slightly compared to 3 columns.
  • If you have 3 sections and the 1st one has 5 topics and then the rest of the sections have 3 topics then the the section alignment for that column goes off as well.
  • So there are similar issues like the above.

Would be amazing if you could follow that up on a task. Happy to demo the front-end styling/ alignment issues to you.

Thanks =)

Copy link
Contributor

@zerolab zerolab left a comment

Choose a reason for hiding this comment

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

A few more notes

cms/navigation/models.py Outdated Show resolved Hide resolved

{% set keyLinksList = [] %}

{% if navigation_settings.main_menu and navigation_settings.main_menu.highlights %}
Copy link
Contributor

Choose a reason for hiding this comment

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

these would be better off as properties on NavigationSettings, then

% set navigation_settings = settings.navigation.NavigationSettings %}

{% set pageConfig = {
   ...

   "keyLinksList": navigation_settings.main_menu_highlights,
   "itemsList": navigation_settings.main_menu_items
}
%}

reads so much better in the template

def user_has_permission(self, user: Optional["User"] = None, action: str | None = None) -> bool:
if action == "add" and MainMenu.objects.exists():
return False
return user is not None and user.has_perm(self._get_permission_name(action))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return user is not None and user.has_perm(self._get_permission_name(action))
return super().user_has_permission(user)

cms/navigation/models.py Outdated Show resolved Hide resolved
page = PageChooserBlock(required=False, page_type="themes.ThemePage")

class Meta:
label = "Theme Link"
Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed, for consistency, we need to mark for translation any strings that will be displayed to the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@helenb
Copy link
Contributor

helenb commented Dec 16, 2024

@helenb

Thanks for testing this. I fixed the link issues.

As previously for highlights when a user selects a Wagtail page it didn't turn it into a link. Now it does. Same for the topic page.

Also fixed some other edge cases I missed out on previously, so now all should be good on that side.

Let me know if there are any further issues.

Now adding main menu content and it being usable on the website menu should be all good.

Screenshot 2024-12-09 at 18 31 58

So now we are just left with front-end alignment issues.

  • Where if you have only 2 columns the alignment looks weird and goes out of place slightly compared to 3 columns.
  • If you have 3 sections and the 1st one has 5 topics and then the rest of the sections have 3 topics then the the section alignment for that column goes off as well.
  • So there are similar issues like the above.

Would be amazing if you could follow that up on a task. Happy to demo the front-end styling/ alignment issues to you.

Thanks =)

Thanks @sanjeevz3009 - once you've merged this PR, you could re-assign the ticket to me to do the front-end tweaks.

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