Skip to content

Commit

Permalink
Fix: Sample selection refresh (#798)
Browse files Browse the repository at this point in the history
* refreshing during sample selection

* applying turbo refresh to group samples selection

* fixing tests

* adding a new project samples test

* fixing visibility within test

* verifying samples displayed

* trying an alternate solution

* fixing tests
  • Loading branch information
ksierks authored Oct 4, 2024
1 parent 1b68011 commit e8800ab
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 41 deletions.
3 changes: 2 additions & 1 deletion app/controllers/groups/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SamplesController < Groups::ApplicationController
include Sortable

def index
@timestamp = DateTime.current
@pagy, @samples = pagy_with_metadata_sort(@q.result)
@has_samples = authorized_samples.count.positive?
end
Expand All @@ -26,7 +27,7 @@ def select
respond_to do |format|
format.turbo_stream do
if params[:select].present?
@q = authorized_samples.ransack(search_params)
@q = authorized_samples.ransack(search_params.merge({ updated_at_lt: params[:timestamp] }))
@selected_sample_ids = @q.result.select(:id).pluck(:id)
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/projects/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SamplesController < Projects::ApplicationController # rubocop:disable Metr
include Sortable

def index
@timestamp = DateTime.current
@pagy, @samples = pagy_with_metadata_sort(@q.result)
@has_samples = @project.samples.size.positive?
end
Expand Down Expand Up @@ -83,7 +84,7 @@ def select
respond_to do |format|
format.turbo_stream do
if params[:select].present?
@q = load_samples.ransack(search_params)
@q = load_samples.ransack(search_params.merge({ updated_at_lt: params[:timestamp] }))
@samples = @q.result.select(:id)
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/groups/samples/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
class:
"flex items-center px-4 py-2 bg-slate-100 text-slate-600 dark:bg-slate-600 dark:text-slate-300
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
) %>
<% else %>
<% dropdown.with_item(
Expand Down Expand Up @@ -72,6 +72,7 @@
) do |f| %>
<input type="hidden" name="format" value="turbo_stream"/>
<input type="hidden" name="select" value="on"/>
<input type="hidden" name="timestamp" value="<%=@timestamp%>"/>
<%= f.submit t(".select_all_button"),
class: "button button--state-default button--size-default" %>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/projects/samples/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
class:
"flex items-center px-4 py-2 bg-slate-100 text-slate-600 dark:bg-slate-600 dark:text-slate-300
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
) %>
<% else %>
<% dropdown.with_item(
Expand Down Expand Up @@ -126,6 +126,7 @@
) do |f| %>
<input type="hidden" name="format" value="turbo_stream"/>
<input type="hidden" name="select" value="on"/>
<input type="hidden" name="timestamp" value="<%=@timestamp%>"/>
<%= f.submit t(".select_all_button"),
class: "button button--state-default button--size-default" %>
<% end %>
Expand Down
8 changes: 6 additions & 2 deletions app/views/projects/samples/select.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<turbo-stream action="update" target="selected">
<template>
<div data-controller="table-selection" data-table-selection-ids-value="<%= @samples.map { |s| s.id.to_s } %>" data-table-selection-selection-outlet="#samples-table"></div>
<div
data-controller="table-selection"
data-table-selection-ids-value="<%= @samples.map { |s| s.id.to_s } %>"
data-table-selection-selection-outlet="#samples-table"
></div>
</template>
</turbo-stream>
</turbo-stream>
8 changes: 8 additions & 0 deletions test/fixtures/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ group_sixteen:
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABG

group_seventeen:
<<: *DEFAULTS
name: Group 17
path: group-17
description: Group 17 description
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_GRP_AAAAAAAABI

user30_group_one:
<<: *DEFAULTS
name: User 30 Group 1
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/members.yml
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ group_sixteen_member_ryan_doe:
namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_sixteen, :uuid) %>
access_level: <%= Member::AccessLevel::GUEST %>

group_seventeen_member_john_doe:
user_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
created_by_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:group_seventeen, :uuid) %>
access_level: <%= Member::AccessLevel::OWNER %>

group_one_member_user30:
user_id: <%= ActiveRecord::FixtureSet.identify(:user30, :uuid) %>
created_by_id: <%= ActiveRecord::FixtureSet.identify(:user30, :uuid) %>
Expand Down
13 changes: 11 additions & 2 deletions test/fixtures/namespaces/project_namespaces.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ project28_namespace:
description: Project 28 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:david_doe_group_four, :uuid) %>
owner_id: <%= ActiveRecord::FixtureSet.identify(:david_doe, :uuid) %>
metadata_summary: { "unique_metadata_field": 1}
metadata_summary: { "unique_metadata_field": 1 }
puid: INXT_PRJ_AAAAAAAABA

project29_namespace:
Expand Down Expand Up @@ -350,7 +350,7 @@ projectBravo_namespace:
description: Project Bravo description
type: Project
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_bravo, :uuid) %>
metadata_summary: {'metadatafield1': 1, 'metadatafield2': 1}
metadata_summary: { "metadatafield1": 1, "metadatafield2": 1 }
puid: INXT_PRJ_AAAAAAAABF

projectCharlie_namespace:
Expand Down Expand Up @@ -471,6 +471,15 @@ project37_namespace:
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_sixteen, :uuid) %>
puid: INXT_PRJ_AAAAAAACBC

project38_namespace:
<<: *DEFAULTS
name: Project 38
path: project-38
description: Project 38 description
parent_id: <%= ActiveRecord::FixtureSet.identify(:group_seventeen, :uuid) %>
owner_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
puid: INXT_PRJ_AAAAAAACBF

user29_project1_namespace:
<<: *DEFAULTS
name: User 29 Project 1
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ project37:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user21, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project37_namespace, :uuid) %>

project38:
creator_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project38_namespace, :uuid) %>

user29_project1:
creator_id: <%= ActiveRecord::FixtureSet.identify(:user29, :uuid) %>
namespace_id: <%= ActiveRecord::FixtureSet.identify(:user29_project1_namespace, :uuid) %>
Expand Down
11 changes: 10 additions & 1 deletion test/fixtures/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,16 @@ group_16_route:
path: group-16
source: group_sixteen (Namespace)

group_17_route:
name: Group 17
path: group-17
source: group_seventeen (Namespace)

project38_namespace_route:
name: Group 17 / Project 38
path: group-17/project-38
source: project38_namespace (Namespace)

user_29_namespace_route:
name: user.29@localhost
path: user.29_at_localhost
Expand All @@ -474,7 +484,6 @@ user29_project1_namespace_route:
path: user.29_at_localhost/project-1
source: user29_project1_namespace (Namespace)


user30_group_one_route:
name: User 30 Group 1
path: user-30-group-1
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,14 @@ sample_canceled_unclean_DELETE:
created_at: <%= 1.week.ago %>
updated_at: <%= 1.day.ago %>
attachments_updated_at: <%= 2.hours.ago %>


<% (1..200).each do |n| %>
bulk_sample<%= (n) %>:
name: <%= "Project 38 Sample #{n}" %>
description: <%= "Project 38 Sample #{n} description." %>
project_id: <%= ActiveRecord::FixtureSet.identify(:project38, :uuid) %>
puid: <%= "INXT_SAM_AAAAAAAAC#{n}" %>
created_at: <%= n.weeks.ago %>
updated_at: <%= n.days.ago %>
<% end %>
18 changes: 9 additions & 9 deletions test/graphql/groups_query_ransack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ def setup

data = result['data']['groups']['nodes']

assert_equal 6, data.count # Group 1, Group 10, Group 11, etc
assert_equal 7, data.count # Group 1, Group 10, Group 11, etc

assert_equal groups(:group_sixteen).name, data[0]['name']
assert_equal groups(:group_sixteen).puid, data[0]['puid']
assert_equal groups(:group_seventeen).name, data[0]['name']
assert_equal groups(:group_seventeen).puid, data[0]['puid']

assert_equal groups(:group_fifteen).name, data[1]['name']
assert_equal groups(:group_fifteen).puid, data[1]['puid']
assert_equal groups(:group_sixteen).name, data[1]['name']
assert_equal groups(:group_sixteen).puid, data[1]['puid']

assert_equal groups(:group_ten).name, data[4]['name']
assert_equal groups(:group_ten).puid, data[4]['puid']
assert_equal groups(:group_ten).name, data[5]['name']
assert_equal groups(:group_ten).puid, data[5]['puid']

assert_equal groups(:group_one).name, data[5]['name']
assert_equal groups(:group_one).puid, data[5]['puid']
assert_equal groups(:group_one).name, data[6]['name']
assert_equal groups(:group_one).puid, data[6]['puid']
end
end
6 changes: 3 additions & 3 deletions test/policies/group_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def setup
scoped_groups = @policy.apply_scope(Group, type: :relation)

# John Doe has access to 28 groups
assert_equal 32, scoped_groups.count
assert_equal 33, scoped_groups.count

user = users(:david_doe)
policy = GroupPolicy.new(user:)
Expand All @@ -117,7 +117,7 @@ def setup

scoped_groups = @policy.apply_scope(Group, type: :relation)

assert_equal 30, scoped_groups.count
assert_equal 31, scoped_groups.count
scoped_groups_names = scoped_groups.pluck(:name)
assert_not scoped_groups_names.include?(groups(:group_one).name)
assert_not scoped_groups_names.include?(groups(:david_doe_group_four).name)
Expand All @@ -128,7 +128,7 @@ def setup

scoped_groups = @policy.apply_scope(Group, type: :relation)

assert_equal 29, scoped_groups.count
assert_equal 30, scoped_groups.count
scoped_groups_names = scoped_groups.pluck(:name)
assert_not scoped_groups_names.include?(groups(:namespace_group_link_group_one).name)
end
Expand Down
4 changes: 2 additions & 2 deletions test/policies/namespace_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def setup

# John Doe has manageable access to 29 namespaces
# (1 user namespace and 27 group namespaces)
assert_equal 32, scoped_namespaces.count
assert_equal 33, scoped_namespaces.count

assert_not scoped_namespaces.include?(namespace_group_link.namespace)

Expand All @@ -87,7 +87,7 @@ def setup
# John Doe has manageable access to 30 namespaces (1 user namespace,
# 29 group namespaces, and 1 group namespace via a namespace
# group link)
assert_equal 33, scoped_namespaces.count
assert_equal 34, scoped_namespaces.count

assert scoped_namespaces.include?(namespace_group_link.namespace)
end
Expand Down
14 changes: 7 additions & 7 deletions test/policies/project_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def setup
# and projects under groups in which he is a member plus a project
# from David Doe's Group Four which is shared with subgroup 1 under
# John Doe's group Group 1
assert_equal 38, scoped_projects.count
assert_equal 39, scoped_projects.count

user = users(:david_doe)
policy = ProjectPolicy.new(user:)
Expand All @@ -118,7 +118,7 @@ def setup

scoped_projects = @policy.apply_scope(Project, type: :relation)

assert_equal 19, scoped_projects.count
assert_equal 20, scoped_projects.count
scoped_projects_names = Namespaces::ProjectNamespace.where(id: scoped_projects.select(:namespace_id)).pluck(:name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project5_namespace).name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project6_namespace).name)
Expand All @@ -145,7 +145,7 @@ def setup

scoped_projects = @policy.apply_scope(Project, type: :relation)

assert_equal 18, scoped_projects.count
assert_equal 19, scoped_projects.count
scoped_projects_names = Namespaces::ProjectNamespace.where(id: scoped_projects.select(:namespace_id)).pluck(:name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project1_namespace).name)

Expand All @@ -155,7 +155,7 @@ def setup

scoped_projects = @policy.apply_scope(Project, type: :relation)

assert_equal 17, scoped_projects.count
assert_equal 18, scoped_projects.count
scoped_projects_names = Namespaces::ProjectNamespace.where(id: scoped_projects.select(:namespace_id)).pluck(:name)
assert_not scoped_projects_names.include?(
namespaces_project_namespaces(:namespace_group_link_group_one_project1_namespace).name
Expand All @@ -167,7 +167,7 @@ def setup

# John Doe has manageable access to just projects under his namespace
# and projects under groups in which he is a member
assert_equal 37, scoped_projects.count
assert_equal 38, scoped_projects.count

user = users(:david_doe)
policy = ProjectPolicy.new(user:)
Expand All @@ -186,7 +186,7 @@ def setup

scoped_projects = @policy.apply_scope(Project, type: :relation, name: :manageable)

assert_equal 19, scoped_projects.count
assert_equal 20, scoped_projects.count
scoped_projects_names = Namespaces::ProjectNamespace.where(id: scoped_projects.select(:namespace_id)).pluck(:name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project5_namespace).name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project6_namespace).name)
Expand Down Expand Up @@ -214,7 +214,7 @@ def setup

scoped_projects = @policy.apply_scope(Project, type: :relation, name: :manageable)

assert_equal 18, scoped_projects.count
assert_equal 19, scoped_projects.count
scoped_projects_names = Namespaces::ProjectNamespace.where(id: scoped_projects.select(:namespace_id)).pluck(:name)
assert_not scoped_projects_names.include?(namespaces_project_namespaces(:project1_namespace).name)
end
Expand Down
Loading

0 comments on commit e8800ab

Please sign in to comment.