Skip to content

Commit

Permalink
v3.1.2 Fixes breadcrumbs for report names by preserving case
Browse files Browse the repository at this point in the history
  • Loading branch information
jontsai authored and Jonathan Tsai committed May 22, 2022
1 parent 977a85b commit 70a49d6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# CHANGELOG

## v3.1.1 (2021.12-13)
- Removes an incorrect type hint
## v3.1.2 (2022-05-21)
- Fixes breadcrumbs for report names by preserving case

## v3.1.1 (2021-12-13)
- Removes an incorrect type hint

## v3.1.0 (2021-12-13)
- Fixes metric aggregation by customer, service, and owner (#12)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1
3.1.2
2 changes: 1 addition & 1 deletion phablytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.1.1'
__version__ = '3.1.2'
4 changes: 2 additions & 2 deletions phablytics/web/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


# Breadcrumbs are automatically inflected based on the final phrase of a URL path.
# Overrides can be set based on paths in the BREADCRUMBS dict.
BREADCRUMBS = {
# Overrides can be set based on paths in the BREADCRUMB_OVERRIDES dict.
BREADCRUMB_OVERRIDES = {
'/' : 'Home',
'/explore': 'Explore',
'/metrics': 'Metrics',
Expand Down
31 changes: 29 additions & 2 deletions phablytics/web/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Python Standard Library Imports
import copy
import re

# Third Party (PyPI) Imports
from flask import (
Expand All @@ -18,12 +19,15 @@
PHABRICATOR_INSTANCE_BASE_URL,
)
from phablytics.web.constants import (
BREADCRUMBS,
BREADCRUMB_OVERRIDES,
NAV_LINKS,
SITE_NAME,
)


REPORT_PATH_REGEX = re.compile(r'^/reports/[^/]+$')


def custom_render_template(template_name, context_data=None):
if context_data is None:
context_data = {}
Expand Down Expand Up @@ -79,6 +83,11 @@ def _format_nav_link(nav_link):
return nav_links


def is_report_name_path(path):
result = REPORT_PATH_REGEX.match(path) is not None
return result


def get_breadcrumbs():
breadcrumbs = []

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

for i, path_part in enumerate(path_parts):
path = '/'.join(path_parts[:i + 1]) or '/'
path_suffix = '/'.join(path_parts[i + 1:])
is_active = i + 1 == len(path_parts)
name = BREADCRUMBS.get(path, path_part.title())

default_breadcrumb_name = (
path_part
if (
# leave alone if any conditions are satisfied
is_report_name_path(path)
)
# else format breadcrumb as Titlecase
else path_part.title()
)

name = BREADCRUMB_OVERRIDES.get(
path, # get breadcrumb by full path
BREADCRUMB_OVERRIDES.get(
path_suffix, # get breadcrumb by path_suffix
default_breadcrumb_name # fallback: generated breadcrumb based on path
)
)
breadcrumb = {
'name': name,
'url': path,
Expand Down

0 comments on commit 70a49d6

Please sign in to comment.