Skip to content

Commit

Permalink
Merge branch 'main' into dp-3072-data-product-detail-page
Browse files Browse the repository at this point in the history
  • Loading branch information
LavMatt authored Feb 21, 2024
2 parents c631878 + 4afe602 commit e48cd3b
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 199 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/format-code.yml

This file was deleted.

50 changes: 46 additions & 4 deletions home/forms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,55 @@ def get_domain_choices():
return [
("urn:li:domain:HMCTS", "HMCTS"),
("urn:li:domain:HMPPS", "HMPPS"),
("urn:li:domain:OPG", "OPG"),
("urn:li:domain:HQ", "HQ"),
("urn:li:domain:LAA", "LAA"),
("urn:li:domain:OPG", "OPG"),
]


def get_subdomain_choices(domain):
# TODO: pull in the subdomains from the catalogue client so we don't need to hardcode
return {
"urn:li:domain:HMPPS": [
("urn:li:domain:2feb789b-44d3-4412-b998-1f26819fabf9", "Prisons"),
("urn:li:domain:abe153c1-416b-4abb-be7f-6accf2abb10a", "Probation"),
],
"urn:li:domain:HMCTS": [
("urn:li:domain:4d77af6d-9eca-4c44-b189-5f1addffae55", "Civil courts"),
("urn:li:domain:31754f66-33df-4a73-b039-532518bc765e", "Crown courts"),
("urn:li:domain:81adfe94-1284-46a2-9179-945ad2a76c14", "Family courts"),
(
"urn:li:domain:b261176c-d8eb-4111-8454-c0a1fa95005f",
"Magistrates courts",
),
],
"urn:li:domain:OPG": [
(
"urn:li:domain:bc091f6c-7674-4c82-a315-f5489398f099",
"Lasting power of attourney",
),
(
"urn:li:domain:efb9ade3-3c5d-4c5c-b451-df9f2d8136f5",
"Supervision orders",
),
],
"urn:li:domain:HQ": [
("urn:li:domain:9fb7ff13-6c7e-47ef-bef1-b13b23fd8c7a", "Estates"),
("urn:li:domain:e4476e66-37a1-40fd-83b9-c908f805d8f4", "Finance"),
("urn:li:domain:0985731b-8e1c-4b4a-bfc0-38e58d8ba8a1", "People"),
("urn:li:domain:a320c915-0b43-4277-9769-66615aab4adc", "Performance"),
],
"urn:li:domain:LAA": [
(
"urn:li:domain:24344488-d770-437a-ba6f-e6129203b927",
"Civil legal advice",
),
("urn:li:domain:Legal%20Aid", "Legal aid"),
("urn:li:domain:5c423c06-d328-431f-8634-7a7e86928819", "Public defender"),
],
}.get(domain, [])


def get_sort_choices():
return [
("relevance", "Relevance"),
Expand All @@ -32,9 +76,7 @@ class SearchForm(forms.Form):
max_length=100,
strip=False,
required=False,
widget=forms.TextInput(
attrs={"class": "govuk-input search-input", "aria-label": "Search"}
),
widget=forms.TextInput(attrs={"class": "govuk-input search-input"}),
)
domains = forms.MultipleChoiceField(
choices=get_domain_choices,
Expand Down
16 changes: 14 additions & 2 deletions home/service/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
from data_platform_catalogue.search_types import MultiSelectFilter, SortOption
from django.core.paginator import Paginator

from home.forms.search import SearchForm
from home.forms.search import SearchForm, get_subdomain_choices

from .base import GenericService


def domains_with_their_subdomains(domains: list[str]) -> list[str]:
"""
When assets are tagged to subdomains, they are not included in search results if
we filter by domain alone. We need to include all possible subdomains in the filter.
"""
return [
subdomain
for domain in domains
for (subdomain, _) in get_subdomain_choices(domain)
] + domains


class SearchService(GenericService):
def __init__(self, form: SearchForm, page: str, items_per_page: int = 20):
self.form = form
Expand All @@ -24,7 +36,7 @@ def _get_search_results(self, page: str, items_per_page: int):
form_data = {}
query = form_data.get("query", "")
sort = form_data.get("sort", "relevance")
domains = form_data.get("domains", [])
domains = domains_with_their_subdomains(form_data.get("domains", []))
filter_value = [MultiSelectFilter("domains", domains)] if domains else []
page_for_search = str(int(page) - 1)
if sort == "ascending":
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"@ministryofjustice/frontend": "^2.1.0",
"govuk-frontend": "^5.0.0",
"govuk-frontend": "^5.1.0",
"sass": "^1.70.0"
},
"scripts": {
Expand Down
Loading

0 comments on commit e48cd3b

Please sign in to comment.