Skip to content

Commit 70a49d6

Browse files
jontsaiJonathan Tsai
authored andcommitted
v3.1.2 Fixes breadcrumbs for report names by preserving case
1 parent 977a85b commit 70a49d6

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# CHANGELOG
22

3-
## v3.1.1 (2021.12-13)
4-
- Removes an incorrect type hint
3+
## v3.1.2 (2022-05-21)
4+
- Fixes breadcrumbs for report names by preserving case
5+
6+
## v3.1.1 (2021-12-13)
7+
- Removes an incorrect type hint
58

69
## v3.1.0 (2021-12-13)
710
- Fixes metric aggregation by customer, service, and owner (#12)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.1
1+
3.1.2

phablytics/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.1.1'
1+
__version__ = '3.1.2'

phablytics/web/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727

2828
# Breadcrumbs are automatically inflected based on the final phrase of a URL path.
29-
# Overrides can be set based on paths in the BREADCRUMBS dict.
30-
BREADCRUMBS = {
29+
# Overrides can be set based on paths in the BREADCRUMB_OVERRIDES dict.
30+
BREADCRUMB_OVERRIDES = {
3131
'/' : 'Home',
3232
'/explore': 'Explore',
3333
'/metrics': 'Metrics',

phablytics/web/utils.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Python Standard Library Imports
22
import copy
3+
import re
34

45
# Third Party (PyPI) Imports
56
from flask import (
@@ -18,12 +19,15 @@
1819
PHABRICATOR_INSTANCE_BASE_URL,
1920
)
2021
from phablytics.web.constants import (
21-
BREADCRUMBS,
22+
BREADCRUMB_OVERRIDES,
2223
NAV_LINKS,
2324
SITE_NAME,
2425
)
2526

2627

28+
REPORT_PATH_REGEX = re.compile(r'^/reports/[^/]+$')
29+
30+
2731
def custom_render_template(template_name, context_data=None):
2832
if context_data is None:
2933
context_data = {}
@@ -79,6 +83,11 @@ def _format_nav_link(nav_link):
7983
return nav_links
8084

8185

86+
def is_report_name_path(path):
87+
result = REPORT_PATH_REGEX.match(path) is not None
88+
return result
89+
90+
8291
def get_breadcrumbs():
8392
breadcrumbs = []
8493

@@ -91,8 +100,26 @@ def get_breadcrumbs():
91100

92101
for i, path_part in enumerate(path_parts):
93102
path = '/'.join(path_parts[:i + 1]) or '/'
103+
path_suffix = '/'.join(path_parts[i + 1:])
94104
is_active = i + 1 == len(path_parts)
95-
name = BREADCRUMBS.get(path, path_part.title())
105+
106+
default_breadcrumb_name = (
107+
path_part
108+
if (
109+
# leave alone if any conditions are satisfied
110+
is_report_name_path(path)
111+
)
112+
# else format breadcrumb as Titlecase
113+
else path_part.title()
114+
)
115+
116+
name = BREADCRUMB_OVERRIDES.get(
117+
path, # get breadcrumb by full path
118+
BREADCRUMB_OVERRIDES.get(
119+
path_suffix, # get breadcrumb by path_suffix
120+
default_breadcrumb_name # fallback: generated breadcrumb based on path
121+
)
122+
)
96123
breadcrumb = {
97124
'name': name,
98125
'url': path,

0 commit comments

Comments
 (0)