From 44c05ecfe6725f374bfce00ba59777c0f4ae69fe Mon Sep 17 00:00:00 2001 From: Chris Huynh Date: Fri, 18 Oct 2024 14:41:26 -0500 Subject: [PATCH] add filter to workflow execution pages --- app/models/workflow_execution.rb | 4 + .../workflow_executions/index.html.erb | 13 ++- app/views/workflow_executions/index.html.erb | 54 +++++++----- config/locales/en.yml | 4 + db/seeds.rb | 4 +- test/fixtures/workflow_executions.yml | 4 + .../projects/workflow_executions_test.rb | 82 +++++++++++++++---- test/system/workflow_executions_test.rb | 77 +++++++++++++---- 8 files changed, 184 insertions(+), 58 deletions(-) diff --git a/app/models/workflow_execution.rb b/app/models/workflow_execution.rb index aeac6dc370..c3663fdcee 100644 --- a/app/models/workflow_execution.rb +++ b/app/models/workflow_execution.rb @@ -64,6 +64,10 @@ def as_wes_params }.compact end + ransacker :id do + Arel.sql('id::varchar') + end + def self.ransackable_attributes(_auth_object = nil) %w[id name run_id state created_at updated_at] end diff --git a/app/views/projects/workflow_executions/index.html.erb b/app/views/projects/workflow_executions/index.html.erb index db0a7ba638..435d741368 100644 --- a/app/views/projects/workflow_executions/index.html.erb +++ b/app/views/projects/workflow_executions/index.html.erb @@ -26,8 +26,9 @@ <% end %> <% end %>
+
<% if allowed_to?(:export_data?, @project.namespace) %> -
+
<%= search_form_for( @q, url: select_namespace_project_workflow_executions_url(**request.query_parameters), @@ -51,7 +52,17 @@ <% end %>
<% end %> +
+ <%= render SearchComponent.new( + query: @q, + url: namespace_project_workflow_executions_path(**request.query_parameters), + search_attribute: :name_or_id_cont, + placeholder: t('.search.placeholder') + ) %> +
+
+ <%= render partial: "table", locals: { workflow_executions: @workflow_executions, diff --git a/app/views/workflow_executions/index.html.erb b/app/views/workflow_executions/index.html.erb index d990ec69b5..9638580ea6 100644 --- a/app/views/workflow_executions/index.html.erb +++ b/app/views/workflow_executions/index.html.erb @@ -22,28 +22,38 @@ <% end %> <% end %>
-
- <%= search_form_for( - @q, - url: select_workflow_executions_url(**request.query_parameters), - html: { id: "select-all-form" }, - class: "filters align-middle" - ) do |f| %> - - - <%= f.submit t(".select_all_button"), - class: "button button--state-default button--size-default" %> - <% end %> - <%= search_form_for( - @q, - url: select_workflow_executions_url(**request.query_parameters), - html: { id: "deselect-all-form" }, - class: "filters align-middle" - ) do |f| %> - - <%= f.submit t(".deselect_all_button"), - class: "button button--state-default button--size-default" %> - <% end %> +
+
+ <%= search_form_for( + @q, + url: select_workflow_executions_url(**request.query_parameters), + html: { id: "select-all-form" }, + class: "filters align-middle" + ) do |f| %> + + + <%= f.submit t(".select_all_button"), + class: "button button--state-default button--size-default" %> + <% end %> + <%= search_form_for( + @q, + url: select_workflow_executions_url(**request.query_parameters), + html: { id: "deselect-all-form" }, + class: "filters align-middle" + ) do |f| %> + + <%= f.submit t(".deselect_all_button"), + class: "button button--state-default button--size-default" %> + <% end %> +
+
+ <%= render SearchComponent.new( + query: @q, + url: workflow_executions_path, + search_attribute: :name_or_id_cont, + placeholder: t('.search.placeholder') + ) %> +
<%= render partial: "table", diff --git a/config/locales/en.yml b/config/locales/en.yml index 53a208cd56..1a34b5141b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1482,6 +1482,8 @@ en: index: create_export_button: Create Export deselect_all_button: Deselect All + search: + placeholder: Filter by ID or name select_all_button: Select All subtitle: These are the workflow executions that have been automatically launched for this project title: Workflow Executions @@ -1686,6 +1688,8 @@ en: delete_confirm: Are you sure you want to delete this workflow execution? create_export_button: Create Export deselect_all_button: Deselect All + search: + placeholder: Filter by ID or name select_all_button: Select All title: Workflow Executions samples: diff --git a/db/seeds.rb b/db/seeds.rb index 31f3b38c30..91db4435a3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -796,7 +796,9 @@ def seed_exports # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metric # prevent workflow and workflow attachment broadcasts Attachment.suppressing_turbo_broadcasts do WorkflowExecution.suppressing_turbo_broadcasts do - seed_workflow_executions + 100.times do + seed_workflow_executions + end end end # prevent data export broadcasts diff --git a/test/fixtures/workflow_executions.yml b/test/fixtures/workflow_executions.yml index 8f627590af..8306e05441 100644 --- a/test/fixtures/workflow_executions.yml +++ b/test/fixtures/workflow_executions.yml @@ -144,6 +144,7 @@ irida_next_example_completed_2_files: run_id: "my_run_id_6" submitter_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %> + name: 'irida_next_example_completed_2_files' state: "completed" blob_run_directory: "not a run dir" cleaned: true @@ -479,6 +480,7 @@ irida_next_example_completed_with_output: run_id: "my_run_id_13" submitter_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectA_namespace, :uuid) %> + name: "irida_next_example_completed_with_output" state: "completed" blob_run_directory: "not a run dir" cleaned: false @@ -602,6 +604,7 @@ automated_example_completed: run_id: "my_run_id_6" submitter_id: <%= ActiveRecord::FixtureSet.identify(:project1_automation_bot, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %> + name: "autmoated_example_completed" state: "completed" blob_run_directory: "not a run dir" cleaned: true @@ -663,6 +666,7 @@ automated_example_canceled: run_id: "my_run_id_9" submitter_id: <%= ActiveRecord::FixtureSet.identify(:project1_automation_bot, :uuid) %> namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %> + name: "automated_example_canceled" state: "canceled" cleaned: true diff --git a/test/system/projects/workflow_executions_test.rb b/test/system/projects/workflow_executions_test.rb index 2678150990..6d247ba06f 100644 --- a/test/system/projects/workflow_executions_test.rb +++ b/test/system/projects/workflow_executions_test.rb @@ -9,6 +9,8 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase login_as @user @namespace = groups(:group_one) @project = projects(:project1) + @workflow_execution1 = workflow_executions(:automated_example_completed) + @workflow_execution2 = workflow_executions(:automated_example_canceled) @id_col = '1' @name_col = '2' @@ -30,8 +32,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase test 'should sort a list of workflow executions' do workflow_execution1 = workflow_executions(:automated_workflow_execution) - workflow_execution2 = workflow_executions(:automated_example_canceling) - workflow_execution3 = workflow_executions(:automated_example_canceled) + workflow_execution3 = workflow_executions(:automated_example_canceling) workflow_execution4 = workflow_executions(:automated_workflow_execution_existing) visit namespace_project_workflow_executions_path(@namespace, @project) @@ -46,7 +47,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase assert_selector 'tr', count: 10 assert_selector "tr:first-child td:nth-child(#{@run_id_col})", text: workflow_execution4.run_id assert_selector "tr:nth-child(#{@run_id_col}) td:nth-child(#{@run_id_col})", text: workflow_execution1.run_id - assert_selector "tr:last-child td:nth-child(#{@run_id_col})", text: workflow_execution3.run_id + assert_selector "tr:last-child td:nth-child(#{@run_id_col})", text: @workflow_execution2.run_id end click_on 'Run ID' @@ -54,8 +55,8 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within('#workflow-executions-table table tbody') do assert_selector 'tr', count: 10 - assert_selector "tr:first-child td:nth-child(#{@run_id_col})", text: workflow_execution3.run_id - assert_selector "tr:nth-child(2) td:nth-child(#{@run_id_col})", text: workflow_execution2.run_id + assert_selector "tr:first-child td:nth-child(#{@run_id_col})", text: @workflow_execution2.run_id + assert_selector "tr:nth-child(2) td:nth-child(#{@run_id_col})", text: workflow_execution3.run_id assert_selector "tr:last-child td:nth-child(#{@run_id_col})", text: workflow_execution4.run_id end @@ -65,9 +66,9 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within('#workflow-executions-table table tbody') do assert_selector 'tr', count: 10 assert_selector "tr:first-child td:nth-child(#{@workflow_name_col})", - text: workflow_execution3.metadata['workflow_name'] + text: @workflow_execution2.metadata['workflow_name'] assert_selector "tr:nth-child(2) td:nth-child(#{@workflow_name_col})", - text: workflow_execution2.metadata['workflow_name'] + text: workflow_execution3.metadata['workflow_name'] assert_selector "tr:last-child td:nth-child(#{@workflow_name_col})", text: workflow_execution4.metadata['workflow_name'] end @@ -82,7 +83,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase assert_selector "tr:nth-child(2) td:nth-child(#{@workflow_name_col})", text: workflow_execution1.metadata['workflow_name'] assert_selector "tr:last-child td:nth-child(#{@workflow_name_col})", - text: workflow_execution3.metadata['workflow_name'] + text: @workflow_execution2.metadata['workflow_name'] end end @@ -152,18 +153,16 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'should delete a completed workflow' do - workflow_execution = workflow_executions(:automated_example_completed) - visit namespace_project_workflow_executions_path(@namespace, @project) assert_selector 'h1', text: I18n.t(:'projects.workflow_executions.index.title') assert_selector 'p', text: I18n.t(:'projects.workflow_executions.index.subtitle') - tr = find('a', text: workflow_execution.id).ancestor('tr') + tr = find('a', text: @workflow_execution1.id).ancestor('tr') within tr do assert_selector "td:nth-child(#{@state_col})", - text: I18n.t(:"workflow_executions.state.#{workflow_execution.state}") + text: I18n.t(:"workflow_executions.state.#{@workflow_execution1.state}") assert_link 'Delete', count: 1 click_link 'Delete' end @@ -174,11 +173,11 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within %(div[data-controller='viral--flash']) do assert_text I18n.t( :'concerns.workflow_execution_actions.destroy.success', - workflow_name: workflow_execution.metadata['workflow_name'] + workflow_name: @workflow_execution1.metadata['workflow_name'] ) end - assert_no_text workflow_execution.id + assert_no_text @workflow_execution1.id end test 'should delete an errored workflow' do @@ -307,9 +306,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'can remove workflow execution from workflow execution page' do - workflow_execution = workflow_executions(:automated_example_completed) - - visit namespace_project_workflow_execution_path(@namespace, @project, workflow_execution) + visit namespace_project_workflow_execution_path(@namespace, @project, @workflow_execution1) click_link I18n.t(:'projects.workflow_executions.show.remove_button') @@ -319,7 +316,56 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within %(#workflow-executions-table table tbody) do assert_selector 'tr', count: 9 - assert_no_text workflow_execution.id + assert_no_text @workflow_execution1.id + end + end + + test 'can filter by ID and name on projects workflow execution index page' do + visit namespace_project_workflow_executions_path(@namespace, @project) + + assert_text 'Displaying 10 items' + assert_selector 'table tbody tr', count: 10 + + within('table tbody') do + assert_text @workflow_execution1.id + assert_text @workflow_execution1.name + assert_text @workflow_execution2.id + assert_text @workflow_execution2.name + end + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: @workflow_execution1.id + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 1 item' + assert_selector 'table tbody tr', count: 1 + + within('table tbody') do + assert_text @workflow_execution1.id + assert_text @workflow_execution1.name + assert_no_text @workflow_execution2.id + assert_no_text @workflow_execution2.name + end + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: '' + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 10 items' + assert_selector 'table tbody tr', count: 10 + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: @workflow_execution2.name + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 1 item' + assert_selector 'table tbody tr', count: 1 + + within('table tbody') do + assert_no_text @workflow_execution1.id + assert_no_text @workflow_execution1.name + assert_text @workflow_execution2.id + assert_text @workflow_execution2.name end end end diff --git a/test/system/workflow_executions_test.rb b/test/system/workflow_executions_test.rb index ff50c6f84e..8e080ec55c 100644 --- a/test/system/workflow_executions_test.rb +++ b/test/system/workflow_executions_test.rb @@ -9,6 +9,10 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase @user = users(:john_doe) login_as @user + @workflow_execution1 = workflow_executions(:irida_next_example_completed) + @workflow_execution2 = workflow_executions(:irida_next_example_completed_2_files) + @workflow_execution3 = workflow_executions(:irida_next_example_completed_with_output) + @id_col = '1' @name_col = '2' @state_col = '3' @@ -184,17 +188,15 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'should delete a completed workflow' do - workflow_execution = workflow_executions(:irida_next_example_completed) - visit workflow_executions_path assert_selector 'h1', text: I18n.t(:'workflow_executions.index.title') - tr = find('a', text: workflow_execution.id).ancestor('tr') + tr = find('a', text: @workflow_execution1.id).ancestor('tr') within tr do assert_selector "td:nth-child(#{@state_col})", - text: I18n.t(:"workflow_executions.state.#{workflow_execution.state}") + text: I18n.t(:"workflow_executions.state.#{@workflow_execution1.state}") assert_link 'Delete', count: 1 click_link 'Delete' end @@ -205,11 +207,11 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within %(div[data-controller='viral--flash']) do assert_text I18n.t( :'concerns.workflow_execution_actions.destroy.success', - workflow_name: workflow_execution.metadata['workflow_name'] + workflow_name: @workflow_execution1.metadata['workflow_name'] ) end - assert_no_text workflow_execution.id + assert_no_text @workflow_execution1.id end test 'should delete an errored workflow' do @@ -331,9 +333,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'can view workflow execution with samplesheet' do - workflow_execution = workflow_executions(:irida_next_example_completed) - - visit workflow_execution_path(workflow_execution) + visit workflow_execution_path(@workflow_execution1) click_on I18n.t('workflow_executions.show.tabs.samplesheet') @@ -344,9 +344,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'can view workflow execution with samplesheet with multiple files' do - workflow_execution = workflow_executions(:irida_next_example_completed_2_files) - - visit workflow_execution_path(workflow_execution) + visit workflow_execution_path(@workflow_execution2) click_on I18n.t('workflow_executions.show.tabs.samplesheet') @@ -359,9 +357,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase end test 'can remove workflow execution from workflow execution page' do - workflow_execution = workflow_executions(:irida_next_example_completed) - - visit workflow_execution_path(workflow_execution) + visit workflow_execution_path(@workflow_execution1) click_link I18n.t(:'workflow_executions.show.remove_button') @@ -371,7 +367,56 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase within %(#workflow-executions-table table tbody) do assert_selector 'tr', count: WORKFLOW_EXECUTION_COUNT - 1 - assert_no_text workflow_execution.id + assert_no_text @workflow_execution1.id + end + end + + test 'can filter by ID and name on workflow execution index page' do + visit workflow_executions_path + + assert_text 'Displaying 19 items' + assert_selector 'table tbody tr', count: 19 + + within('table tbody') do + assert_text @workflow_execution2.id + assert_text @workflow_execution2.name + assert_text @workflow_execution3.id + assert_text @workflow_execution3.name + end + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: @workflow_execution2.id + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 1 item' + assert_selector 'table tbody tr', count: 1 + + within('table tbody') do + assert_text @workflow_execution2.id + assert_text @workflow_execution2.name + assert_no_text @workflow_execution3.id + assert_no_text @workflow_execution3.name + end + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: '' + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 19 items' + assert_selector 'table tbody tr', count: 19 + + fill_in placeholder: I18n.t(:'workflow_executions.index.search.placeholder'), + with: @workflow_execution3.name + find('input.t-search-component').native.send_keys(:return) + + assert_text 'Displaying 1 item' + assert_selector 'table tbody tr', count: 1 + + within('table tbody') do + assert_no_text @workflow_execution2.id + assert_no_text @workflow_execution2.name + assert_text @workflow_execution3.id + assert_text @workflow_execution3.name end end end