Skip to content

Commit

Permalink
fix: adjust order by in codebase search component
Browse files Browse the repository at this point in the history
if search query is empty, the ordering parameter should default to most recently published. otherwise, should be order by relevance

- deps: pin MarkupSafe for regression in 3.0.x (refs comses/planning#277)
- minor text refinement, change to "clear search" and include for queries as well

should not offer a sort by relevance when there is no search query but that's for a later date

Co-authored-by: Allen Lee <[email protected]>
  • Loading branch information
asuworks and alee authored Oct 16, 2024
1 parent eeeb7a6 commit b8bc243
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion django/core/jinja2/base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
</div>
</noscript>
{% if not is_production() %}
<div class='alert alert-danger mt-3'>
<div class='alert alert-danger m-0'>
<i class='fas fa-flask me-2'></i>
You are currently accessing a <b>test version of the comses.net website</b>. Information that you
view or store here will <b>not be preserved</b> and may not be consistent.
Expand Down
67 changes: 36 additions & 31 deletions django/core/jinja2/common.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@
</div>
{% endmacro %}

{% macro build_paginator_url_params(page_number, query_params) %}{%- if query_params %}{{ query_params }}&amp;{%endif
-%}page={{page_number}}{% endmacro %}
{% macro build_paginator_url_params(page_number, query_params) %}
{%- if query_params %}{{ query_params }}&amp;{%endif-%}page={{page_number}}
{% endmacro %}

{% macro page_nav(url_name, list_state) %}
<nav aria-label="Page navigation">
Expand All @@ -127,7 +128,7 @@
<a class='page-link'
href="{{ url(url_name) }}?{{ build_paginator_url_params(1, list_state.query_params) }}">1</a>
</li>
{% for page in list_state.range -%}
{% for page in list_state.range -%}
{% if loop.first and page > 2 %}
<li class='page-item disabled'>
<span class='page-link'>&hellip;</span>
Expand All @@ -137,42 +138,46 @@
<a href="{{ url(url_name) }}?{{ build_paginator_url_params(page, list_state.query_params) }}"
class="page-link">{{ page }}</a>
</li>
{% if loop.last and page < list_state.num_pages - 1 -%} <li class="page-item disabled">
{% if loop.last and page < list_state.num_pages - 1 -%}
<li class="page-item disabled">
<span class='page-link'>&hellip;</span>
</li>
{% endif %}
{% endfor %}
{% if list_state.num_pages > 1 -%}
<li class="page-item {{ " active" if list_state.is_last_page }}">
<a href="{{ url(url_name) }}?{{ build_paginator_url_params(list_state.num_pages, list_state.query_params) }}"
class="page-link">{{ list_state.num_pages }}</a>
</li>
{% endif %}
<li class='page-item {{ "disabled" if list_state.is_last_page }}'>
<a class='page-link'
href='{{ url(url_name) }}?{{ build_paginator_url_params(list_state.current_page + 1, list_state.query_params) }}'
aria-label='Previous'>
<span aria-hidden='true'>&raquo;</span>
<span class='sr-only'>Next</span>
</a>
</li>
{% endif %}
{% endfor %}
{% if list_state.num_pages > 1 -%}
<li class="page-item {{ " active" if list_state.is_last_page }}">
<a href="{{ url(url_name) }}?{{ build_paginator_url_params(list_state.num_pages, list_state.query_params) }}"
class="page-link">{{ list_state.num_pages }}</a>
</li>
{% endif %}
<li class='page-item {{ "disabled" if list_state.is_last_page }}'>
<a class='page-link'
href='{{ url(url_name) }}?{{ build_paginator_url_params(list_state.current_page + 1, list_state.query_params) }}'
aria-label='Previous'>
<span aria-hidden='true'>&raquo;</span>
<span class='sr-only'>Next</span>
</a>
</li>
</ul>
</nav>
{% endmacro %}

{% macro paginator(url_name, list_state) %}
<p>Displaying {{ list_state.num_results }} of <strong>{{ list_state.count }}</strong> results
{% if list_state.query %}
for <strong>'{{ list_state.query }}'</strong>
{% endif %}
{% if list_state.filter_display_terms %}
{% for term in list_state.filter_display_terms %}
<span class="badge bg-gray ms-1">{{ term }}</span>
{% endfor %}
<a class="text-warn ms-1" href="{{ url(url_name) }}">
<i class="fas fa-times"></i> clear filters
</a>
<p>Displaying {{ list_state.num_results }} of <strong>{{ list_state.count }}</strong> results
{% if list_state.query or list_state.filter_display_terms %}
{% if list_state.query %}
for <strong>&quot;{{ list_state.query }}&quot;</strong>
{% endif %}
{% if list_state.filter_display_terms %}
{% for term in list_state.filter_display_terms %}
<span class="badge bg-gray ms-1">{{ term }}</span>
{% endfor %}
{% endif %}
<a class="text-warn ms-1" href="{{ url(url_name) }}">
<i class="fas fa-times"></i> clear search
</a>
{% endif %}

</p>
{% if list_state.count %}
<div class="d-flex justify-content-between mb-3">
Expand Down
6 changes: 3 additions & 3 deletions django/core/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
SORT_BY_FILTERS = defaultdict(
lambda: "Sort by: Relevance", # default sort by relevance
{
"-first_published_at": "Sort by: Publish date: newest",
"first_published_at": "Sort by: Publish date: oldest",
"-last_modified": "Sort by: Recently Modified",
"-first_published_at": "Sort by: Recently published",
"first_published_at": "Sort by: Earliest published",
"-last_modified": "Sort by: Recently modified",
},
)

Expand Down
1 change: 1 addition & 0 deletions django/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ html2text>=2016.9.19
jinja2==3.1.4
jsonschema==4.19.0
markdown==3.6
MarkupSafe<3.0.0 # FIXME: remove after regression in 3.0.x is patched https://github.com/comses/planning/issues/277
nltk>=3.8.1,<4.0.0
numpy==1.26.4
pandas==2.2.2
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/CodebaseListSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ const initializeFilterValues = () => {
values.endDate = urlParams.get("publishedBefore")
? new Date(urlParams.get("publishedBefore")!)
: null;
values.ordering = urlParams.get("ordering") || "-first_published_at";
values.ordering =
urlParams.get("ordering") || (urlParams.get("query") ? "relevance" : "-first_published_at");
initialFilterValues.value = { ...values };
};
Expand Down

0 comments on commit b8bc243

Please sign in to comment.