Skip to content

Commit

Permalink
Filter by name or puid to projects dashbaord (#778)
Browse files Browse the repository at this point in the history
* chore: Added filter by name or puid to projects dashbaord

* chore: Normalized i18n

* chore: Fixed personal project search

* chore: Simplified using only params

* chore: Removed slicing the personal param
  • Loading branch information
joshsadam authored Sep 25, 2024
1 parent adaac51 commit 4d54e70
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dashboard/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def set_default_sort
end

def authorized_projects(finder_params)
if finder_params[:personal]
if finder_params[:personal] == 'true'
authorized_scope(Project, type: :relation, as: :personal)
else
authorized_scope(Project, type: :relation)
Expand Down
35 changes: 10 additions & 25 deletions app/views/dashboard/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@

<div class="bg-white dark:bg-slate-800">
<div
class="
flex
text-sm
font-medium
text-center
border-b
text-slate-500
border-slate-200
dark:text-slate-400
dark:border-slate-700
"
class="flex text-sm font-medium text-center border-b text-slate-500 border-slate-200 dark:text-slate-400 dark:border-slate-700"
>
<ul class="flex flex-wrap -mb-px">
<li class="mr-2">
Expand All @@ -33,7 +23,7 @@
end
),
aria: {
current: params[:personal] ? "false" : "page"
current: params[:personal] ? "false" : "page",
} %>
</li>
<li class="mr-2">
Expand All @@ -48,30 +38,25 @@
end
),
aria: {
current: params[:personal] ? "page" : "false"
current: params[:personal] ? "page" : "false",
} %>
</li>
</ul>
<div class="flex flex-row items-center ml-auto space-x-2 font-normal">
<%= search_form_for @q, url: dashboard_projects_url(**request.query_parameters.slice(:personal)), html: {"data-controller": "filters"} do |f| %>
<%= search_form_for @q, url: dashboard_projects_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %>
<input type="hidden" name="format" value="turbo_stream"/>
<%= f.label :namespace_name_cont, t(".search.placeholder"), class: "sr-only" %>
<input type="hidden" name="personal" value="<%= params['personal'] %>">
<%= f.label :namespace_name_or_namespace_puid_cont,
t(".search.placeholder"),
class: "sr-only" %>
<div class="relative lg:w-72">
<div
class="
absolute
inset-y-0
left-0
flex
items-center
pl-3
pointer-events-none
"
class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none "
>
<%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %>
</div>
<%= turbo_frame_tag "project_hidden_values" %>
<%= f.search_field :namespace_name_cont,
<%= f.search_field :namespace_name_or_namespace_puid_cont,
"data-action": "filters#submit",
class:
"block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500",
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ en:
row:
samples: Samples
search:
placeholder: Filter by name
placeholder: Filter by name or puid
sorting:
created_at_asc: Oldest created
created_at_desc: Last created
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fr:
row:
samples: Samples
search:
placeholder: Filter by name
placeholder: Filter by name or puid
sorting:
created_at_asc: Oldest created
created_at_desc: Last created
Expand Down
12 changes: 12 additions & 0 deletions test/system/dashboard/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def setup
assert_no_selector 'a', text: I18n.t(:'components.pagination.previous')
end

test 'can search the list of projects by puid' do
visit dashboard_projects_url

assert_selector 'h1', text: I18n.t(:'dashboard.projects.index.title')
assert_text 'Displaying items 1-20 of 38 in total'
assert_selector 'tr', count: 20

fill_in I18n.t(:'dashboard.projects.index.search.placeholder'), with: @project.puid

assert_selector 'tr', count: 1
end

test 'can sort the list of projects' do
visit dashboard_projects_url

Expand Down

0 comments on commit 4d54e70

Please sign in to comment.