Skip to content

Commit 82d0b73

Browse files
authored
feat: enhance tree search rendering and implementation (#2133)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 3c2b24c commit 82d0b73

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

scancodeio/static/main.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,11 @@ body.full-screen #resource-viewer .message-header {
551551
min-width: 0;
552552
max-width: 100%;
553553
border-right: 1px solid #ccc;
554-
overflow: visible;
554+
min-height: 0;
555+
height: 100vh;
556+
overflow: auto;
555557
display: flex;
556558
flex-direction: column;
557-
min-height: 0;
558559
flex-basis: 25%;
559560
transition: opacity 0.2s ease;
560561
position: relative;
@@ -573,7 +574,6 @@ body.full-screen #resource-viewer .message-header {
573574
top: 0;
574575
z-index: 20;
575576
background: var(--bulma-scheme-main);
576-
padding: .25rem 0 .5rem;
577577
}
578578
#resource-tree-container #clear-search {
579579
display: inline-flex;
@@ -615,7 +615,7 @@ body.full-screen #resource-viewer .message-header {
615615
align-items: center;
616616
gap: .5rem;
617617
color: var(--bulma-text);
618-
font-size: 14px;
618+
font-size: 15px;
619619
line-height: 20px;
620620
font-weight: 400;
621621
white-space: nowrap;
@@ -635,13 +635,13 @@ body.full-screen #resource-viewer .message-header {
635635
}
636636
#resource-tree-container .search-result-item .icon i,
637637
.search-dropdown.search-dropdown-portal .search-result-item .icon i {
638-
font-size: 13px;
638+
font-size: 15px;
639639
}
640640
#resource-tree-container .search-result-path,
641641
.search-dropdown.search-dropdown-portal .search-result-path {
642642
overflow: hidden;
643643
text-overflow: ellipsis;
644-
font-size: 14px;
644+
font-size: 15px;
645645
}
646646
#resource-tree-container .left-pane.collapsed {
647647
opacity: 0;

scanpipe/templates/scanpipe/tree/resource_left_pane.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
<div id="resource-tree" class="resource-tree-scroll">
55
{% include "scanpipe/tree/resource_left_pane_tree.html" with children=children %}
6-
</div>
6+
</div>

scanpipe/templates/scanpipe/tree/resource_search_bar.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
id="file-search-input"
66
class="input is-small"
77
type="text"
8-
placeholder="Go to file..."
8+
placeholder="Go to file"
99
autocomplete="off"
1010
hx-get="{% url 'project_resource_tree_search' project.slug %}"
1111
hx-target="#search-results"
12-
hx-trigger="input changed delay:200ms"
13-
hx-include="this"
12+
hx-trigger="input changed delay:300ms"
1413
name="search"
1514
>
1615
<span class="icon is-small is-left">
@@ -27,4 +26,4 @@
2726
</div>
2827
</div>
2928
<div id="search-results" class="search-dropdown is-hidden"></div>
30-
</div>
29+
</div>

scanpipe/templates/scanpipe/tree/resource_search_results.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}"
1313
data-path="{{ resource.path }}"
1414
title="{{ resource.path }}">
15-
<span class="icon mr-2">
15+
<span class="icon">
1616
{% if resource.is_dir %}
1717
<i class="fas fa-folder"></i>
1818
{% else %}
@@ -24,10 +24,10 @@
2424
{% endfor %}
2525
</div>
2626
{% elif query %}
27-
<div class="has-text-centered px-4 py-5">
28-
<div class="icon is-large has-text-grey-light mb-3">
27+
<div class="has-text-centered py-5">
28+
<div class="icon is-large has-text-grey-light mb-2">
2929
<i class="fas fa-search fa-2x"></i>
3030
</div>
3131
<p class="has-text-grey">No files found matching "{{ query }}"</p>
3232
</div>
33-
{% endif %}
33+
{% endif %}

scanpipe/templates/scanpipe/tree/resource_table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{% if page_obj.has_next %}
4747
<a
4848
class="pagination-next"
49-
hx-get="{% url 'project_resource_tree_right_pane' project.slug path%}?page={{ page_obj.next_page_number }}"
49+
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}?page={{ page_obj.next_page_number }}"
5050
hx-target="#right-pane"
5151
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.next_page_number }}">
5252
Next page

scanpipe/tests/test_views.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ def test_scanpipe_views_project_resource_tree_right_pane_view_empty_directory(se
17421742
self.assertEqual(0, len(resources))
17431743

17441744
def test_scanpipe_views_project_resource_tree_search_view_filters_results(self):
1745-
make_resource_file(self.project1, path="src/FooBar.py")
1745+
r1 = make_resource_file(self.project1, path="src/FooBar.py")
17461746
make_resource_file(self.project1, path="src/other.py")
17471747

17481748
url = reverse(
@@ -1752,9 +1752,7 @@ def test_scanpipe_views_project_resource_tree_search_view_filters_results(self):
17521752

17531753
self.assertEqual(200, response.status_code)
17541754
self.assertEqual("foobar", response.context["query"])
1755-
self.assertEqual(
1756-
["src/FooBar.py"], [r.path for r in response.context["search_results"]]
1757-
)
1755+
self.assertQuerySetEqual([r1], response.context["search_results"])
17581756

17591757
@mock.patch("scanpipe.views.ProjectResourceTreeRightPaneView.paginate_by", 2)
17601758
def test_scanpipe_views_project_resource_tree_right_pane_view_pagination(self):

scanpipe/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
),
138138
path(
139139
"project/<slug:slug>/resource_tree/search/",
140-
views.ProjectResourceSearchView.as_view(),
140+
views.ProjectResourceTreeSearchView.as_view(),
141141
name="project_resource_tree_search",
142142
),
143143
path(

scanpipe/views.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ def get_context_data(self, **kwargs):
28462846
return context
28472847

28482848

2849-
class ProjectResourceSearchView(
2849+
class ProjectResourceTreeSearchView(
28502850
ConditionalLoginRequired,
28512851
ProjectRelatedViewMixin,
28522852
generic.ListView,
@@ -2856,22 +2856,25 @@ class ProjectResourceSearchView(
28562856
context_object_name = "search_results"
28572857
paginate_by = 30
28582858

2859+
def setup(self, request, *args, **kwargs):
2860+
super().setup(request, *args, **kwargs)
2861+
self.search_query = request.GET.get("search", "").strip()
2862+
28592863
def get_queryset(self):
2860-
search_query = self.request.GET.get("search", "").strip()
2861-
if not search_query:
2864+
if not self.search_query:
28622865
return super().get_queryset().none()
28632866

28642867
return (
28652868
super()
28662869
.get_queryset()
2867-
.filter(path__icontains=search_query)
2870+
.filter(path__icontains=self.search_query)
28682871
.only("project_id", "path", "type")
28692872
.order_by("path")
28702873
)
28712874

28722875
def get_context_data(self, **kwargs):
28732876
context = super().get_context_data(**kwargs)
2874-
context["query"] = self.request.GET.get("search", "").strip()
2877+
context["query"] = self.search_query
28752878
return context
28762879

28772880

0 commit comments

Comments
 (0)