Skip to content

Commit 69288b6

Browse files
Merge pull request #251 from NHSDigital/reporting-nav-items
Use full navigation items from Mavis cookie
2 parents b50da05 + a9c4d02 commit 69288b6

File tree

2 files changed

+40
-66
lines changed

2 files changed

+40
-66
lines changed

mavis/reporting/assets/scss/_header.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@use "config" as *;
22

3+
.nhsuk-header__navigation-item {
4+
padding-right: nhsuk-spacing(2);
5+
}
6+
37
.app-header__navigation-item--with-count {
48
.app-count {
59
margin-left: nhsuk-spacing(1);
Lines changed: 36 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,49 @@
11
import json
2-
from urllib.parse import unquote
2+
from urllib.parse import unquote_plus
33

4-
from flask import current_app, url_for
4+
from flask import current_app
55
from markupsafe import Markup
66

7-
from mavis.reporting.helpers.mavis_helper import mavis_public_url
7+
FALLBACK_ITEMS = [
8+
{"path": "/programmes", "title": "Programmes"},
9+
{"path": "/patients", "title": "Children"},
10+
{"path": "/sessions", "title": "Sessions"},
11+
{"path": "/vaccines", "title": "Vaccines"},
12+
{"path": "/consent-forms", "title": "Unmatched responses"},
13+
{"path": "/school-moves", "title": "School moves"},
14+
{"path": "/imports", "title": "Imports"},
15+
{"path": "/team", "title": "Your team"},
16+
]
817

918

10-
def parse_navigation_counts_cookie(request):
11-
nav_counts = {}
12-
if cookie_value := request.cookies.get("mavis_navigation_counts"):
19+
def build_navigation_items(request):
20+
items = FALLBACK_ITEMS
21+
if cookie_value := request.cookies.get("mavis_navigation_items"):
1322
try:
14-
decoded_value = unquote(cookie_value)
15-
nav_counts = json.loads(decoded_value)
16-
current_app.logger.info(f"Navigation counts from cookie: {nav_counts}")
23+
decoded_value = unquote_plus(cookie_value)
24+
if parsed := json.loads(decoded_value):
25+
items = parsed
1726
except (json.JSONDecodeError, ValueError):
1827
current_app.logger.warning(
19-
f"Failed to parse navigation counts cookie: {cookie_value}"
28+
f"Failed to parse navigation items cookie: {cookie_value}"
2029
)
21-
else:
22-
current_app.logger.info("No mavis_navigation_counts cookie found")
23-
return nav_counts
24-
25-
26-
def build_nav_item(href, text, nav_counts, active=False, count_key=None):
27-
item = {"href": href, "active": active}
2830

29-
if count_key and (count := nav_counts.get(count_key)) is not None:
30-
badge = (
31-
'<span class="app-count">'
32-
'<span class="nhsuk-u-visually-hidden"> (</span>'
33-
f"{count}"
34-
'<span class="nhsuk-u-visually-hidden">)</span>'
35-
"</span>"
36-
)
37-
item["html"] = Markup(f"{text}{badge}")
38-
item["classes"] = "app-header__navigation-item--with-count"
39-
else:
40-
item["text"] = text
41-
42-
return item
31+
nav_items = []
32+
for item in items:
33+
nav_item = {"href": item["path"], "text": item["title"]}
34+
35+
if (count := item.get("count")) is not None:
36+
badge = (
37+
'<span class="app-count">'
38+
'<span class="nhsuk-u-visually-hidden"> (</span>'
39+
f"{count}"
40+
'<span class="nhsuk-u-visually-hidden">)</span>'
41+
"</span>"
42+
)
43+
nav_item["html"] = Markup(f"{item['title']}{badge}")
44+
nav_item["classes"] = "app-header__navigation-item--with-count"
45+
del nav_item["text"]
4346

47+
nav_items.append(nav_item)
4448

45-
def build_navigation_items(request):
46-
nav_counts = parse_navigation_counts_cookie(request)
47-
return [
48-
build_nav_item(url_for("main.dashboard"), "Reports", nav_counts, active=True),
49-
build_nav_item(
50-
mavis_public_url(current_app, "/sessions"), "Sessions", nav_counts
51-
),
52-
build_nav_item(
53-
mavis_public_url(current_app, "/patients"), "Children", nav_counts
54-
),
55-
build_nav_item(
56-
mavis_public_url(current_app, "/consent-forms"),
57-
"Unmatched responses",
58-
nav_counts,
59-
count_key="unmatched_consent_responses",
60-
),
61-
build_nav_item(
62-
mavis_public_url(current_app, "/school-moves"),
63-
"School moves",
64-
nav_counts,
65-
count_key="school_moves",
66-
),
67-
build_nav_item(
68-
mavis_public_url(current_app, "/vaccines"), "Vaccines", nav_counts
69-
),
70-
build_nav_item(
71-
mavis_public_url(current_app, "/imports"),
72-
"Imports",
73-
nav_counts,
74-
count_key="imports",
75-
),
76-
build_nav_item(
77-
mavis_public_url(current_app, "/team"), "Your team", nav_counts
78-
),
79-
]
49+
return nav_items

0 commit comments

Comments
 (0)