Skip to content

Commit

Permalink
Enable subproject filters for projects with subprojects (#11674)
Browse files Browse the repository at this point in the history
* Enable subproject filters for projects with subprojects

This at least shows the UI element if it makes sense to show.
Currently there's no way without knowing the query syntax to get subprojects,
which has caused confusion for a few of our users and broke existing behavior.

Refs #11638

* Also show on subprojects

* Update to support subprojects having the right filter

* Fix tests

* Apply suggestions from code review

Co-authored-by: Manuel Kaufmann <[email protected]>

* Check for version

---------

Co-authored-by: Manuel Kaufmann <[email protected]>
  • Loading branch information
ericholscher and humitos authored Oct 15, 2024
1 parent ec370d0 commit 4f1f82f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def test_number_of_queries_project_version_slug(self):
active=True,
)

with self.assertNumQueries(22):
with self.assertNumQueries(24):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down Expand Up @@ -765,7 +765,7 @@ def test_number_of_queries_url(self):
active=True,
)

with self.assertNumQueries(24):
with self.assertNumQueries(26):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_number_of_queries_url_subproject(self):
active=True,
)

with self.assertNumQueries(31):
with self.assertNumQueries(35):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand All @@ -827,7 +827,7 @@ def test_number_of_queries_url_translations(self):
language=language,
)

with self.assertNumQueries(60):
with self.assertNumQueries(62):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down
26 changes: 23 additions & 3 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ def _v1(self, project, version, build, filename, url, request):
# "Include subprojects",
# f"subprojects:{project.slug}/{version.slug}",
# ],
]
if version
else [],
],
"default_filter": f"project:{project.slug}/{version.slug}"
if version
else None,
Expand All @@ -514,6 +512,28 @@ def _v1(self, project, version, build, filename, url, request):
},
}

# Show the subprojects filter on the parent project and subproject
if version:
# TODO: Remove these queries and try to find a way to get this data
# from the resolver, which has already done these queries.
# TODO: Replace this fixed filters with the work proposed in
# https://github.com/readthedocs/addons/issues/22
if project.subprojects.exists():
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
f"subprojects:{project.slug}/{version.slug}",
]
)
if project.superprojects.exists():
superproject = project.superprojects.first().parent
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
f"subprojects:{superproject.slug}/{version.slug}",
]
)

# DocDiff depends on `url=` GET attribute.
# This attribute allows us to know the exact filename where the request was made.
# If we don't know the filename, we cannot return the data required by DocDiff to work.
Expand Down

0 comments on commit 4f1f82f

Please sign in to comment.