Skip to content

Commit

Permalink
Some refactoring & bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
HazelGrant committed Dec 12, 2024
1 parent bc24860 commit 3b2eec3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions apps/dashboard/test/system/batch_connect_widgets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 3b2eec3

Please sign in to comment.