Skip to content

Commit 8d140f9

Browse files
authored
Merge pull request #13 from companieshouse/tferns-IDVA6-1397-fix-navbar
IDVA6-1397: Fix navbar, allow passing required arguments
2 parents e63c9a0 + a3d255c commit 8d140f9

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ Available as a normal npm dependency([here on npmjs](https://www.npmjs.com/packa
7777
|`CH_NODE_UTILS_DROP_LANG_QUERY_PARAM`| It could be set to [drop the lang="xx" query param](https://github.com/companieshouse/ch-node-utils/blob/f9e5c47a86206f0b12e4e536c4c459db16747631/src/middleware/manageLocales.middleware.ts#L25) from the current URL ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L50)) |
7878
|`CH_NODE_UTILS_LOG_LVL`| It could be set to ["TRACE" or "DEBUG" (case insensitive)](https://github.com/companieshouse/ch-node-utils/blob/24bc717477d21082439d1b460108cb0d60465f0f/src/utils/log.ts#L2) to dump internal info while inside ch-node-utils ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L49))|
7979
80-
### Menu navigation bar
81-
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and at the moment contains links to the following service:
80+
### Menu Navigation Bar
8281
83-
- Authorised agent
82+
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and currently contains links to the following services:
83+
84+
- Authorised agent (conditional)
8485
- Your companies
8586
- Your filings
8687
- Companies you follow
@@ -90,7 +91,30 @@ A menu navigation bar component has been added to make it easier to add links po
9091
9192
The "Authorised agent" menu item appears conditionally if the logged user has ACSP membership.
9293
93-
The navbar requires importing language files from the `locales` folder in ch-node-utils and making them available to all Nunjuck templates using the [`addGlobal()` function](https://mozilla.github.io/nunjucks/api.html#addglobal) in `app.ts`. At the moment only English and Welsh language versions are supported. It also requires a flag `displayAuthorisedAgent` set the same way for displaying the "Authorised agent" menu item. If the logged user has ACSP membership, this flag should be set to `'yes'`.
94+
#### Usage
95+
96+
To use the predefined navbar, import the macro and call it with the required parameters:
97+
98+
```nunjucks
99+
{% from "navbar.njk" import addPredefinedNavbar %}
100+
101+
{{ addPredefinedNavbar(userEmailAddress, chsMonitorGuiUrl, lang, displayAuthorisedAgent) }}
102+
```
103+
104+
The macro requires the following parameters:
105+
106+
- `userEmailAddress`: The email address of the logged-in user
107+
- `chsMonitorGuiUrl`: The URL for the "Companies you follow" link
108+
- `lang`: An object containing language-specific strings for localization
109+
- `displayAuthorisedAgent`: A flag for displaying the "Authorised agent" menu item. If the logged user has ACSP membership, this flag should be set to `'yes'`
110+
111+
#### Localization
112+
113+
The navbar uses translations from `@companieshouse/ch-node-utils` (this) package. To set this up:
114+
115+
1. Ensure the `@companieshouse/ch-node-utils` package is installed. i.e `npm i @companieshouse/ch-node-utils`
116+
2. Update your i18 middleware to load and merge translations from both sources. (`@companieshouse/ch-node-utils/locales`)
117+
3. Add the `@companieshouse/ch-node-utils/templates` directory to the Nunjucks loader paths.
94118

95119
The navbar also requires the use of styles provided in the [ch.gov.uk.css](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/stylesheets/ch.gov.uk.css) stylesheet (you can either add the provided link to the head section or include specific styles in your own stylesheet)
96120

@@ -99,4 +123,3 @@ The navbar also requires the use of styles provided in the [ch.gov.uk.css](https
99123
It also requires the [navbar.js](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/javascripts/lib/navbar.js) script to be added to the footer to make the navbar work in mobile mode
100124

101125
`<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>`
102-

templates/navbar.njk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ It receives:
2626
- href: the URL of the page the menu item will point to
2727
- displayText: the text to display in the anchor
2828
- userDisplayText: a text identifying the logged user, e.g. email address or name
29+
- lang: an object containing language-specific strings for localization
2930
#}
30-
{% macro addNavbar(signInHref, menuItems, userDisplayText) %}
31+
{% macro addNavbar(signInHref, menuItems, userDisplayText, lang) %}
3132
<div class="js-toggle-nav" id="global-nav">
3233
<nav role="navigation" class="content" aria-label="{{ lang.mainNavbar or 'The main navigation bar' }}">
3334
{% if userDisplayText %}
@@ -57,8 +58,10 @@ A macro that adds a menu navigation bar with predefined items.
5758
It receives:
5859
- userDisplayText: a text identifying the logged user, e.g. email address or name
5960
- chsMonitorGuiUrl: the URL for the 'Companies you follow' link
61+
- lang: an object containing language-specific strings for localization
62+
- displayAuthorisedAgent: a flag indicating whether to display the 'Authorised agent' menu item
6063
#}
61-
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl) %}
64+
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl, lang, displayAuthorisedAgent) %}
6265
{% set menuItems = [
6366
{ id: "authorised-agent", href: "/authorised-agent", displayText: lang.authorisedAgent or "Authorised agent" } if displayAuthorisedAgent === "yes",
6467
{ id: "your-companies", href: "/your-companies", displayText: lang.yourCompanies or "Your companies" },
@@ -69,6 +72,6 @@ It receives:
6972
{ id: "user-signout", href: "/signout", displayText: lang.signOut or "Sign out" }
7073
] | reject("falsy") %}
7174

72-
{{ addNavbar("/signin", menuItems, userDisplayText) }}
75+
{{ addNavbar("/signin", menuItems, userDisplayText, lang) }}
7376

74-
{% endmacro %}
77+
{% endmacro %}

0 commit comments

Comments
 (0)