@companieshouse/ch-node-utils 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -5
- package/locales/cy/navbar.json +12 -0
- package/locales/en/navbar.json +12 -0
- package/package.json +3 -2
- package/templates/navbar.njk +7 -4
package/README.md
CHANGED
|
@@ -77,10 +77,11 @@ Available as a normal npm dependency([here on npmjs](https://www.npmjs.com/packa
|
|
|
77
77
|
|`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)) |
|
|
78
78
|
|`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))|
|
|
79
79
|
|
|
80
|
-
### Menu
|
|
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
|
|
82
81
|
|
|
83
|
-
|
|
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)
|
|
84
85
|
- Your companies
|
|
85
86
|
- Your filings
|
|
86
87
|
- Companies you follow
|
|
@@ -90,7 +91,30 @@ A menu navigation bar component has been added to make it easier to add links po
|
|
|
90
91
|
|
|
91
92
|
The "Authorised agent" menu item appears conditionally if the logged user has ACSP membership.
|
|
92
93
|
|
|
93
|
-
|
|
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.
|
|
94
118
|
|
|
95
119
|
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)
|
|
96
120
|
|
|
@@ -99,4 +123,3 @@ The navbar also requires the use of styles provided in the [ch.gov.uk.css](https
|
|
|
99
123
|
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
|
|
100
124
|
|
|
101
125
|
`<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>`
|
|
102
|
-
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mainNavbar": "Y prif far llywio",
|
|
3
|
+
"clickToExpandOrCollapse": "Cliciwch i ehangu neu gwympo",
|
|
4
|
+
"signInOrRegister": "Mewngofnodwch / Cofrestrwch",
|
|
5
|
+
"yourCompanies": "Eich cwmnïau",
|
|
6
|
+
"authorisedAgent": "Asiant awdurdodedig",
|
|
7
|
+
"yourFilings": "Eich ffeilio",
|
|
8
|
+
"companiesYouFollow": "Cwmnïau rydych yn dilyn",
|
|
9
|
+
"basket": "Basged",
|
|
10
|
+
"manageAccount": "Rheoli cyfrif",
|
|
11
|
+
"signOut": "Allgofnodi"
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mainNavbar": "The main navigation bar",
|
|
3
|
+
"clickToExpandOrCollapse": "Click to expand or collapse",
|
|
4
|
+
"signInOrRegister": "Sign in / Register",
|
|
5
|
+
"yourCompanies": "Your companies",
|
|
6
|
+
"authorisedAgent": "Authorised agent",
|
|
7
|
+
"yourFilings": "Your filings",
|
|
8
|
+
"companiesYouFollow": "Companies you follow",
|
|
9
|
+
"basket": "Basket",
|
|
10
|
+
"manageAccount": "Manage account",
|
|
11
|
+
"signOut": "Sign out"
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companieshouse/ch-node-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"author": "companieshouse",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"templates"
|
|
9
|
+
"templates",
|
|
10
|
+
"locales"
|
|
10
11
|
],
|
|
11
12
|
"description": "set of node utils which can be used across repos/projects",
|
|
12
13
|
"repository": {
|
package/templates/navbar.njk
CHANGED
|
@@ -26,8 +26,9 @@ It receives:
|
|
|
26
26
|
- href: the URL of the page the menu item will point to
|
|
27
27
|
- displayText: the text to display in the anchor
|
|
28
28
|
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
29
|
+
- lang: an object containing language-specific strings for localization
|
|
29
30
|
#}
|
|
30
|
-
{% macro addNavbar(signInHref, menuItems, userDisplayText) %}
|
|
31
|
+
{% macro addNavbar(signInHref, menuItems, userDisplayText, lang) %}
|
|
31
32
|
<div class="js-toggle-nav" id="global-nav">
|
|
32
33
|
<nav role="navigation" class="content" aria-label="{{ lang.mainNavbar or 'The main navigation bar' }}">
|
|
33
34
|
{% if userDisplayText %}
|
|
@@ -57,8 +58,10 @@ A macro that adds a menu navigation bar with predefined items.
|
|
|
57
58
|
It receives:
|
|
58
59
|
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
59
60
|
- 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
|
|
60
63
|
#}
|
|
61
|
-
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl) %}
|
|
64
|
+
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl, lang, displayAuthorisedAgent) %}
|
|
62
65
|
{% set menuItems = [
|
|
63
66
|
{ id: "authorised-agent", href: "/authorised-agent", displayText: lang.authorisedAgent or "Authorised agent" } if displayAuthorisedAgent === "yes",
|
|
64
67
|
{ id: "your-companies", href: "/your-companies", displayText: lang.yourCompanies or "Your companies" },
|
|
@@ -69,6 +72,6 @@ It receives:
|
|
|
69
72
|
{ id: "user-signout", href: "/signout", displayText: lang.signOut or "Sign out" }
|
|
70
73
|
] | reject("falsy") %}
|
|
71
74
|
|
|
72
|
-
{{ addNavbar("/signin", menuItems, userDisplayText) }}
|
|
75
|
+
{{ addNavbar("/signin", menuItems, userDisplayText, lang) }}
|
|
73
76
|
|
|
74
|
-
{% endmacro %}
|
|
77
|
+
{% endmacro %}
|