Add a search as you type form

As in other places where we have a long list of things where you might
want to jump to a specific thing. We use this pattern where there are
more than 7 things, per the magical number 7[1]

1. https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
This commit is contained in:
Chris Hill-Scott
2020-02-28 16:14:28 +00:00
parent 74dbd2b439
commit d2d5510376
3 changed files with 98 additions and 3 deletions

View File

@@ -143,6 +143,7 @@ def organisation_dashboard(org_id):
end=current_financial_year + 1,
),
selected_year=year,
search_form=SearchByNameForm() if len(services) > 7 else None,
**{
f'total_{key}': sum(service[key] for service in services)
for key in ('emails_sent', 'sms_cost', 'letter_cost')

View File

@@ -1,4 +1,5 @@
{% from "components/big-number.html" import big_number %}
{% from "components/live-search.html" import live_search %}
{% from "components/pill.html" import pill %}
{% extends "org_template.html" %}
@@ -50,10 +51,23 @@
</div>
</div>
</div>
<h2 class="heading-small">By service</h2>
{% if search_form %}
<div class="govuk-!-margin-bottom-5">
{{ live_search(
target_selector='.organisation-service',
show=True,
form=search_form,
label='Search by service'
) }}
</div>
{% endif %}
<h2 class="heading-small {% if search_form %}visually-hidden{% endif %}">By service</h2>
{% for service in services %}
<div class="keyline-block govuk-!-margin-top-2">
<h3 class="govuk-!-font-weight-bold govuk-!-font-size-24 govuk-!-margin-bottom-3 govuk-!-margin-top-1">
<div class="keyline-block govuk-!-margin-top-2 organisation-service">
<h3 class="govuk-!-font-weight-bold govuk-!-font-size-24 govuk-!-margin-bottom-3 govuk-!-margin-top-1 live-search-relevant">
<a href="{{ url_for('main.usage', service_id=service.service_id) }}" class="govuk-link govuk-link--no-visited-state browse-list-link">{{ service.service_name }}</a>
</h3>
<div class="govuk-grid-row">