From 3b2eec3a9a188dad3e2126db69d26858970a89f6 Mon Sep 17 00:00:00 2001 From: HazelGrant Date: Thu, 12 Dec 2024 12:10:07 -0500 Subject: [PATCH] Some refactoring & bug fixing --- .../path_selector/path_selector_data_table.js | 31 ++++++++------- .../test/system/batch_connect_widgets_test.rb | 39 +++++++++++++++++++ 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/apps/dashboard/app/javascript/path_selector/path_selector_data_table.js b/apps/dashboard/app/javascript/path_selector/path_selector_data_table.js index 90af8ca5f..ee52ab60e 100644 --- a/apps/dashboard/app/javascript/path_selector/path_selector_data_table.js +++ b/apps/dashboard/app/javascript/path_selector/path_selector_data_table.js @@ -209,6 +209,16 @@ export class PathSelectorTable { // filter the response from the files API to remove things like hidden files/directories filterFileResponse(data) { + let regex = undefined + + try { + if (this.filePattern !== undefined) { + regex = RegExp(this.filePattern); + } + } catch { + alert("The regular expression provided for this path selector did not compile"); + } + const filteredFiles = data.files.filter((file) => { const isHidden = file.name.startsWith('.'); const isFile = file.type == "f"; @@ -218,7 +228,7 @@ export class PathSelectorTable { } else if(isHidden) { return this.showHidden; } else if(isFile) { - return this.filteredByFilename(file); + return this.filteredByFilename(file, regex); } else { return true; } @@ -228,19 +238,12 @@ export class PathSelectorTable { return data; } - filteredByFilename(file) { - if (this.filePattern !== "") { - try { - const regex = RegExp(this.filePattern) - - if (file.name.match(regex)) { - return this.showFiles; - } else { - return false; - } - - } catch (e) { - alert("The regular expression provided for this path selector did not compile"); + filteredByFilename(file, regex) { + if (regex !== undefined) { + if (file.name.match(regex)) { + return this.showFiles; + } else { + return false; } } else { diff --git a/apps/dashboard/test/system/batch_connect_widgets_test.rb b/apps/dashboard/test/system/batch_connect_widgets_test.rb index 036704012..800c282d7 100644 --- a/apps/dashboard/test/system/batch_connect_widgets_test.rb +++ b/apps/dashboard/test/system/batch_connect_widgets_test.rb @@ -146,6 +146,45 @@ def make_bc_app(dir, form) end end + test 'path_selector handles no provided file pattern' do + Dir.mktmpdir do |dir| + "#{dir}/app".tap { |d| Dir.mkdir(d) } + SysRouter.stubs(:base_path).returns(Pathname.new(dir)) + stub_scontrol + stub_sacctmgr + stub_git("#{dir}/app") + + Tempfile.new("test.py", "#{Rails.root}/tmp") + Tempfile.new("test.rb", "#{Rails.root}/tmp") + + form = <<~HEREDOC + --- + cluster: + - owens + form: + - path + attributes: + path: + widget: 'path_selector' + directory: "#{Rails.root}/tmp" + show_files: true + HEREDOC + + Pathname.new("#{dir}/app/").join('form.yml').write(form) + base_id = 'batch_connect_session_context_path' + + visit new_batch_connect_session_context_url('sys/app') + + click_on 'Select Path' + + table_id = "batch_connect_session_context_path_path_selector_table" + shown_dirs_and_files = find_all("##{table_id} tr td").map { |td| td["innerHTML"] } + + assert shown_dirs_and_files.any? { |file| file.match("test.py") } + assert shown_dirs_and_files.any? { |file| file.match("test.rb") } + end + end + test 'data-label-* allows select options to dynamically change the label of another form element' do Dir.mktmpdir do |dir| "#{dir}/app".tap { |d| Dir.mkdir(d) }