From 064b6305f4963d85eca7a30655e544935d38a34f Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 17 Oct 2024 11:41:18 -0400 Subject: [PATCH 1/5] greatly simplify snakeCaseWords --- .../dashboard/app/javascript/dynamic_forms.js | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/app/javascript/dynamic_forms.js b/apps/dashboard/app/javascript/dynamic_forms.js index bc4d4b5628..3a96160460 100644 --- a/apps/dashboard/app/javascript/dynamic_forms.js +++ b/apps/dashboard/app/javascript/dynamic_forms.js @@ -93,27 +93,10 @@ function mountainCaseWords(str) { function snakeCaseWords(str) { if(str === undefined) return undefined; - let snakeCase = ""; - - str.split('').forEach((c, index) => { - if(c === '-' || c === '_') { - snakeCase += '_'; - } else if (index == 0) { - snakeCase += c.toLowerCase(); - } else if(c == c.toUpperCase() && isNaN(c)) { - const nextIsUpper = (index + 1 !== str.length) ? str[index + 1] === str[index + 1].toUpperCase() : true; - const nextIsNum = !isNaN(str[index + 1]); - if ((str[index-1] === '_' || nextIsUpper) && !nextIsNum) { - snakeCase += c.toLowerCase(); - } else { - snakeCase += `_${c.toLowerCase()}`; - } - } else { - snakeCase += c; - } - }); + const rex = /([A-Z]{1}[a-z]*[0-9]*)/g; + const words = str.match(rex); - return snakeCase; + return words.map(word => word.toLowerCase()).join('_'); } /** From f326afcff7ea8f1c80a2f7b936ecd9e149bff01c Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 17 Oct 2024 11:55:36 -0400 Subject: [PATCH 2/5] cache bust tests --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fbfd1bfdc6..f417302bd0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,7 +45,7 @@ jobs: uses: actions/cache@v3 with: path: ~/vendor/bundle - key: ${{ runner.os }}-${{ matrix.ruby }}-unit-gems-${{ hashFiles('apps/*/Gemfile.lock', 'Gemfile.lock') }}-1 + key: ${{ runner.os }}-${{ matrix.ruby }}-unit-gems-${{ hashFiles('apps/*/Gemfile.lock', 'Gemfile.lock') }}-2 - name: Setup os dependencies run: | From 375b14d83d208414e0d18daddc199d5ecb02e277 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 17 Oct 2024 16:06:24 -0400 Subject: [PATCH 3/5] account for strings with no uppercase letters --- apps/dashboard/app/javascript/dynamic_forms.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/app/javascript/dynamic_forms.js b/apps/dashboard/app/javascript/dynamic_forms.js index 3a96160460..a088382ad7 100644 --- a/apps/dashboard/app/javascript/dynamic_forms.js +++ b/apps/dashboard/app/javascript/dynamic_forms.js @@ -93,10 +93,13 @@ function mountainCaseWords(str) { function snakeCaseWords(str) { if(str === undefined) return undefined; - const rex = /([A-Z]{1}[a-z]*[0-9]*)/g; + // find all the captial case words and if none are found, we'll just bascially + // return the same string. + const rex = /([A-Z]{1}[a-z]*[0-9]*)|.+/g; const words = str.match(rex); - return words.map(word => word.toLowerCase()).join('_'); + // filter out emtpy matches to avoid having a _ at the end. + return words.filter(word => word != '').map(word => word.toLowerCase()).join('_'); } /** From 20d49357e6f9a197eeb116ed33b8fd817ff7afe7 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Fri, 18 Oct 2024 13:41:16 -0400 Subject: [PATCH 4/5] add test case --- .../test/system/batch_connect_widgets_test.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/dashboard/test/system/batch_connect_widgets_test.rb b/apps/dashboard/test/system/batch_connect_widgets_test.rb index d7f73e55e1..d990fc25dc 100644 --- a/apps/dashboard/test/system/batch_connect_widgets_test.rb +++ b/apps/dashboard/test/system/batch_connect_widgets_test.rb @@ -214,4 +214,33 @@ def make_bc_app(dir, form) refute(find("##{bc_ele_id('eastern_city')}", visible: false).visible?) end end + + test 'weird ids like aa_b_cc work' do + Dir.mktmpdir do |dir| + form = <<~HEREDOC + form: + - aa + - aa_b_cc + attributes: + aa: + widget: select + options: + - [ "foo", "foo", data-hide-aa-b-cc: true] + - ['bar', 'bar'] + aa_b_cc: + widget: text_field + HEREDOC + + make_bc_app(dir, form) + visit new_batch_connect_session_context_url('sys/app') + + # foo is default, so aa_b_cc should be hidden + assert('foo', find("##{bc_ele_id('aa')}").value) + refute(find("##{bc_ele_id('aa_b_cc')}", visible: false).visible?) + + # select bar, and now aa_b_cc is available. + select('bar', from: bc_ele_id('aa')) + assert(find("##{bc_ele_id('aa_b_cc')}").visible?) + end + end end From 37f8439a9938a6d94e31f8ad578a8a8cbd3020f5 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Fri, 18 Oct 2024 13:41:45 -0400 Subject: [PATCH 5/5] reset this file --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f417302bd0..fbfd1bfdc6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,7 +45,7 @@ jobs: uses: actions/cache@v3 with: path: ~/vendor/bundle - key: ${{ runner.os }}-${{ matrix.ruby }}-unit-gems-${{ hashFiles('apps/*/Gemfile.lock', 'Gemfile.lock') }}-2 + key: ${{ runner.os }}-${{ matrix.ruby }}-unit-gems-${{ hashFiles('apps/*/Gemfile.lock', 'Gemfile.lock') }}-1 - name: Setup os dependencies run: |