Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filtrage des questions en utilisant les étiquettes #794

Merged
merged 10 commits into from
Oct 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -190,32 +190,26 @@
'''
# ---
# name: TestTopicListView.test_clickable_tags[10-?page=2-clickable_tags_page2][clickable_tags_page2]
'<a class="tag bg-info-lighter text-info" href="/topics/?tag=tag&amp;filter=">tag</a>'
'<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?tag=tag&amp;filter=" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filtertopics-button">tag</button>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Laisser un a permettrait d’ouvrir les pages dans des onglets.

# ---
# name: TestTopicListView.test_clickable_tags[None-None-clickable_tags_page1][clickable_tags_page1]
'<a class="tag bg-info-lighter text-info" href="/topics/?tag=tag&amp;filter=">tag</a>'
# ---
# name: TestTopicListView.test_clickable_tags[clickable_tags_page1]
'<a class="tag bg-info-lighter text-info" href="/topics/?tag=tag&amp;filter=">tag</a>'
# ---
# name: TestTopicListView.test_clickable_tags[clickable_tags_page2]
'<a class="tag bg-info-lighter text-info" href="/topics/?tag=tag&amp;filter=">tag</a>'
'<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?tag=tag&amp;filter=" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filtertopics-button">tag</button>'
# ---
# name: TestTopicListView.test_filter_dropdown_with_tags[filter_dropdown_with_tags]
'''
<div class="dropdown-menu dropdown-menu-end" id="filterTopicsDropdown">
<ul class="list-unstyled">

<li>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=ALL&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filtertopics-button">Les plus récentes</button>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=ALL&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filter-ontag-button">Les plus récentes</button>
</li>

<li>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=NEW&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filtertopics-button">En attente de réponse</button>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=NEW&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filter-ontag-button">En attente de réponse</button>
</li>

<li>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=CERTIFIED&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filtertopics-button">Réponse certifiée</button>
<button class="dropdown-item matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=CERTIFIED&amp;tag=tag" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="filter-ontag-button">Réponse certifiée</button>
</li>

</ul>
Expand Down Expand Up @@ -289,36 +283,30 @@
# name: test_queryset_for_tagged_topic[1][1-tagged_topics]
'''
<div class="flex-grow-1" id="topic-list-filter-header">
<span class="h5 m-0">1 question
avec l'étiquette buckley
</span>
<span class="h5 m-0">1 question</span>

<span class="fs-sm">
sous l'étiquette
<button aria-label="Supprimer ce filtre" class="tag bg-info text-white matomo-event" data-bs-placement="top" data-bs-title="Supprimer ce filtre" data-bs-toggle="tooltip" data-matomo-action="unfilter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="unfilter-ontag-button">
<i class="ri-close-fill ri-xs"></i>buckley
</button>
</span>

</div>
'''
# ---
# name: test_queryset_for_tagged_topic[2][2-tagged_topics]
'''
<div class="flex-grow-1" id="topic-list-filter-header">
<span class="h5 m-0">2 questions
avec l'étiquette buckley
</span>
</div>
'''
# ---
# name: test_queryset_for_tagged_topic[tagged_topic]
'''
<div class="flex-grow-1" id="topic-list-filter-header">
<span class="h5 m-0">1 question
avec l'étiquette buckley
</span>
</div>
'''
# ---
# name: test_queryset_for_tagged_topic[tagged_topics]
'''
<div class="flex-grow-1" id="topic-list-filter-header">
<span class="h5 m-0">2 questions
avec l'étiquette buckley
</span>
<span class="h5 m-0">2 questions</span>

<span class="fs-sm">
sous l'étiquette
<button aria-label="Supprimer ce filtre" class="tag bg-info text-white matomo-event" data-bs-placement="top" data-bs-title="Supprimer ce filtre" data-bs-toggle="tooltip" data-matomo-action="unfilter" data-matomo-category="engagement" data-matomo-option="topics" hx-get="/topics/?filter=" hx-push-url="true" hx-swap="outerHTML" hx-target="#topicsarea" id="unfilter-ontag-button">
<i class="ri-close-fill ri-xs"></i>buckley
</button>
</span>

</div>
'''
# ---
2 changes: 1 addition & 1 deletion lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ def test_clickable_tags(
url = topics_url + query_param if query_param else topics_url
response = client.get(url)
assert response.status_code == 200
assert str(parse_response_to_soup(response, selector="a.tag")) == snapshot(name=snapshot_name)
assert str(parse_response_to_soup(response, selector="#filtertopics-button")) == snapshot(name=snapshot_name)

def test_filter_dropdown_with_tags(self, client, db, public_forum_with_topic, topics_url, snapshot):
response = client.get(topics_url + "?tag=tag")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@
<div class="col-12 col-sm">
<div class="d-flex align-items-center">
<div class="flex-grow-1" id="topic-list-filter-header">
<span class="h5 m-0">{{ paginator.count }} question{{ paginator.count|pluralizefr }}
{% if active_tag %}avec l'étiquette {{ active_tag.name|lower }}{% endif %}
</span>
<span class="h5 m-0">{{ paginator.count }} question{{ paginator.count|pluralizefr }}</span>
{% if active_tag %}
<span class="fs-sm">
sous l'étiquette
<button id="unfilter-ontag-button"
hx-target="#topicsarea"
hx-swap="outerHTML"
hx-push-url="true"
hx-get="{{ filter_dropdown_endpoint }}?filter={{ active_filter.name }}"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-title="Supprimer ce filtre"
aria-label="Supprimer ce filtre"
class="tag bg-info text-white matomo-event"
data-matomo-category="engagement"
data-matomo-action="unfilter"
data-matomo-option="topics">
<i class="ri-close-fill ri-xs"></i>{{ active_tag.name|lower }}
</button>
</span>
{% endif %}
</div>
<div>
<span class="fs-sm">Filtrer par :</span>
Expand All @@ -17,7 +35,7 @@
<ul class="list-unstyled">
{% for filter in filters %}
<li>
<button id="filtertopics-button"
<button id="filter-ontag-button"
hx-target="#topicsarea"
hx-swap="outerHTML"
hx-push-url="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{% load url_add_query %}
{% for tag in tags %}
{% url_add_query request.path tag=tag.slug filter=active_filter.value as url_with_query_params %}
<a href="{{ url_with_query_params }}" class="tag bg-info-lighter text-info">{{ tag.name }}</a>
<button id="filtertopics-button"
hx-target="#topicsarea"
hx-swap="outerHTML"
hx-push-url="true"
hx-get="{{ url_with_query_params }}"
class="tag bg-info-lighter text-info matomo-event"
data-matomo-category="engagement"
data-matomo-action="filter"
data-matomo-option="topics">{{ tag.name }}</button>
{% endfor %}