From b2b2a38691e2b74d19b149a3d72b75072e1b3ad4 Mon Sep 17 00:00:00 2001 From: Anton Suharev Date: Mon, 21 Oct 2024 17:45:24 -0700 Subject: [PATCH 1/5] fix: if `query` is empty, `Relevance` ordering option in UI should not be visible for /codebases/ --- django/core/jinja_config.py | 5 +--- django/library/views.py | 9 ++++--- frontend/src/apps/codebase_list.ts | 25 +++++++++++++------ .../src/components/CodebaseListSidebar.vue | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/django/core/jinja_config.py b/django/core/jinja_config.py index 9c87d20bd..3af072f37 100644 --- a/django/core/jinja_config.py +++ b/django/core/jinja_config.py @@ -131,10 +131,7 @@ def generate_search_form_inputs(query_params): Returns: list: A list of tuples representing the hidden input fields. """ - # set default ordering to relevance, if it is not specified - search_parameters = { - "ordering": "relevance", - } + search_parameters = {} if query_params: # parse_qsl handles splitting and unquoting key-value pairs and generates a list of tuples # do not include the actual query in the query parameters diff --git a/django/library/views.py b/django/library/views.py index 6b84c4477..8d43942f0 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -399,12 +399,13 @@ def filter_queryset(self, request, queryset, view): criteria.update(id__in=codebases.values_list("id", flat=True)) # or we could include the PL in the query # qs += " ".join(programming_languages) + + default_ordering = "-first_published_at" if ordering: - criteria.update(ordering=ordering) + criteria.update(ordering=ordering if qs else default_ordering) else: - if qs: - # set default ordering for search when ordering is not specified - criteria.update(ordering="relevance") + # set default ordering for search when ordering is not specified + criteria.update(ordering="relevance" if qs else default_ordering) return get_search_queryset(qs, queryset, tags=tags, criteria=criteria) diff --git a/frontend/src/apps/codebase_list.ts b/frontend/src/apps/codebase_list.ts index 4d295df91..1e33c919a 100644 --- a/frontend/src/apps/codebase_list.ts +++ b/frontend/src/apps/codebase_list.ts @@ -8,11 +8,20 @@ import { extractDataParams } from "@/util"; const props = extractDataParams("sidebar", ["languageFacets"]); createApp(CodebaseListSidebar, props).mount("#sidebar"); -createApp(SortBy, { - sortOptions: [ - { value: "relevance", label: "Relevance" }, - { value: "-first_published_at", label: "Publish date: newest" }, - { value: "first_published_at", label: "Publish date: oldest" }, - { value: "-last_modified", label: "Recently Modified" }, - ], -}).mount("#sortby"); +// Function to check if 'query' exists and is not empty +function hasQueryParam(param: string) { + const params = new URLSearchParams(window.location.search); + const value = params.get(param); + return value !== null && value.trim() !== ""; +} + +const relevanceOption = hasQueryParam("query") ? [{ value: "relevance", label: "Relevance" }] : []; + +const sortOptions = [ + ...relevanceOption, + { value: "-first_published_at", label: "Publish date: newest" }, + { value: "first_published_at", label: "Publish date: oldest" }, + { value: "-last_modified", label: "Recently Modified" }, +]; + +createApp(SortBy, { sortOptions }).mount("#sortby"); diff --git a/frontend/src/components/CodebaseListSidebar.vue b/frontend/src/components/CodebaseListSidebar.vue index 4e8a82e9f..9551966be 100644 --- a/frontend/src/components/CodebaseListSidebar.vue +++ b/frontend/src/components/CodebaseListSidebar.vue @@ -120,7 +120,7 @@ const initialFilterValues = { onMounted(() => { if (props.languageFacets) { const localLanguageFacets = { ...props.languageFacets }; - console.log(localLanguageFacets); + // console.log(localLanguageFacets); parsedLanguageFacets = Object.entries(localLanguageFacets) .sort(([, valueA], [, valueB]) => valueB - valueA) // Sort by value in descending order .map(([name, value]) => ({ value: name, label: `${name} (${value})` })); From 8bf3f5d0756eff0bb512c98560afb275412a5511 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Thu, 24 Oct 2024 09:49:45 -0700 Subject: [PATCH 2/5] fix: adjust sort by ordering logic selection Desired behavior: ``` | ordering | qs | default_ordering | criteria['ordering'] | |----------|-------|--------------------|------------------------| | True | True | "relevance" | ordering | | True | False | "-first_published_at" | ordering | | False | True | "relevance" | "relevance" | | False | False | "-first_published_at" | "-first_published_at" | ``` --- django/library/views.py | 10 +++------- frontend/src/apps/codebase_list.ts | 9 +++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/django/library/views.py b/django/library/views.py index 8d43942f0..3b510b163 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -400,13 +400,9 @@ def filter_queryset(self, request, queryset, view): # or we could include the PL in the query # qs += " ".join(programming_languages) - default_ordering = "-first_published_at" - if ordering: - criteria.update(ordering=ordering if qs else default_ordering) - else: - # set default ordering for search when ordering is not specified - criteria.update(ordering="relevance" if qs else default_ordering) - + # default ordering is relevance if there's a query string, otherwise "-first_published_at" + default_ordering = "relevance" if qs else "-first_published_at" + criteria.update(ordering=ordering if ordering else default_ordering) return get_search_queryset(qs, queryset, tags=tags, criteria=criteria) diff --git a/frontend/src/apps/codebase_list.ts b/frontend/src/apps/codebase_list.ts index 1e33c919a..bae8a47ea 100644 --- a/frontend/src/apps/codebase_list.ts +++ b/frontend/src/apps/codebase_list.ts @@ -1,5 +1,6 @@ import "vite/modulepreload-polyfill"; // Ensure that this is needed based on your project setup +import { isEmpty } from "lodash"; import { createApp } from "vue"; import CodebaseListSidebar from "@/components/CodebaseListSidebar.vue"; import SortBy from "@/components/ListSortBy.vue"; @@ -12,16 +13,16 @@ createApp(CodebaseListSidebar, props).mount("#sidebar"); function hasQueryParam(param: string) { const params = new URLSearchParams(window.location.search); const value = params.get(param); - return value !== null && value.trim() !== ""; + return !isEmpty(value); } const relevanceOption = hasQueryParam("query") ? [{ value: "relevance", label: "Relevance" }] : []; const sortOptions = [ ...relevanceOption, - { value: "-first_published_at", label: "Publish date: newest" }, - { value: "first_published_at", label: "Publish date: oldest" }, - { value: "-last_modified", label: "Recently Modified" }, + { value: "-first_published_at", label: "Most recently published" }, + { value: "first_published_at", label: "Earliest published" }, + { value: "-last_modified", label: "Recently modified" }, ]; createApp(SortBy, { sortOptions }).mount("#sortby"); From e97f3ea026ff7d6bab09da71e4c04081d11889ac Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Thu, 24 Oct 2024 12:24:18 -0700 Subject: [PATCH 3/5] fix: simplify order by relevance logic instead of passing strings around and interpreting them downstream, set order_by_relevance directly in the search_backend ES call --- django/core/view_helpers.py | 13 +++++++------ django/library/views.py | 7 +++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/django/core/view_helpers.py b/django/core/view_helpers.py index 1673d7d3e..e3371cf78 100644 --- a/django/core/view_helpers.py +++ b/django/core/view_helpers.py @@ -87,7 +87,13 @@ def build_search_query(input_text: str) -> SearchQuery: def get_search_queryset( - query, queryset, operator="or", fields=None, tags=None, criteria=None + query, + queryset, + operator="or", + fields=None, + tags=None, + criteria=None, + order_by_relevance=False, ): search_backend = get_search_backend() @@ -132,11 +138,6 @@ def get_search_queryset( Set up order by relevance override for search other sort orders are handled by SmallResultSetPagination filtering and SORT_BY_FILTERS """ - order_by_relevance = False - if "ordering" in criteria: - sort_order = criteria.pop("ordering") - if sort_order == "relevance": - order_by_relevance = True """ Filter queryset """ diff --git a/django/library/views.py b/django/library/views.py index 3b510b163..2239c828d 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -400,10 +400,9 @@ def filter_queryset(self, request, queryset, view): # or we could include the PL in the query # qs += " ".join(programming_languages) - # default ordering is relevance if there's a query string, otherwise "-first_published_at" - default_ordering = "relevance" if qs else "-first_published_at" - criteria.update(ordering=ordering if ordering else default_ordering) - return get_search_queryset(qs, queryset, tags=tags, criteria=criteria) + # set order by relevance if there's a query string and no explicit ordering requested + order_by_relevance = qs and not ordering + return get_search_queryset(qs, queryset, tags=tags, criteria=criteria, order_by_relevance=order_by_relevance) class CodebaseViewSet(SpamCatcherViewSetMixin, CommonViewSetMixin, HtmlNoDeleteViewSet): From d67709452232b794850275a6a12765973fff934a Mon Sep 17 00:00:00 2001 From: Anton Suharev Date: Thu, 24 Oct 2024 14:12:30 -0700 Subject: [PATCH 4/5] fix: sort by relevance when order is `relevance`; fix: disabled "Apply Filters" for Event and Jobs --- django/library/views.py | 10 ++++++++-- frontend/src/components/ListSidebar.vue | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/django/library/views.py b/django/library/views.py index 2239c828d..2defb65c9 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -401,8 +401,14 @@ def filter_queryset(self, request, queryset, view): # qs += " ".join(programming_languages) # set order by relevance if there's a query string and no explicit ordering requested - order_by_relevance = qs and not ordering - return get_search_queryset(qs, queryset, tags=tags, criteria=criteria, order_by_relevance=order_by_relevance) + order_by_relevance = qs and (not ordering or ordering == "relevance") + return get_search_queryset( + qs, + queryset, + tags=tags, + criteria=criteria, + order_by_relevance=order_by_relevance, + ) class CodebaseViewSet(SpamCatcherViewSetMixin, CommonViewSetMixin, HtmlNoDeleteViewSet): diff --git a/frontend/src/components/ListSidebar.vue b/frontend/src/components/ListSidebar.vue index 2b393936a..9fe47f9ee 100644 --- a/frontend/src/components/ListSidebar.vue +++ b/frontend/src/components/ListSidebar.vue @@ -56,7 +56,9 @@ export interface SearchProps { clearAllFilters?: () => void; } -const props = defineProps(); +const props = withDefaults(defineProps(), { + isFilterChanged: true, +}); function handleApplyFilters() { isApplyingFiltersLoading.value = true; From 6b7897a70a0acf18fc90dbb0135b78845b27c922 Mon Sep 17 00:00:00 2001 From: Anton Suharev Date: Thu, 24 Oct 2024 14:57:18 -0700 Subject: [PATCH 5/5] fix: remove the option to create non-existent tags in the tag filter on the sidebars: Codebase, Event, Jobs, Profile --- frontend/src/components/CodebaseListSidebar.vue | 1 + frontend/src/components/EventListSidebar.vue | 2 +- frontend/src/components/JobListSidebar.vue | 2 +- frontend/src/components/ProfileListSidebar.vue | 2 +- frontend/src/components/form/TaggerField.vue | 4 +++- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/CodebaseListSidebar.vue b/frontend/src/components/CodebaseListSidebar.vue index 9551966be..5050f8f89 100644 --- a/frontend/src/components/CodebaseListSidebar.vue +++ b/frontend/src/components/CodebaseListSidebar.vue @@ -57,6 +57,7 @@ label="Tags" type="Codebase" placeholder="Language, framework, etc." + :taggable="false" /> diff --git a/frontend/src/components/EventListSidebar.vue b/frontend/src/components/EventListSidebar.vue index 68de0b0ab..e8d587d0a 100644 --- a/frontend/src/components/EventListSidebar.vue +++ b/frontend/src/components/EventListSidebar.vue @@ -7,7 +7,7 @@ >