From a9593a724c4583a60db1d4b09d7f3c07da25edae Mon Sep 17 00:00:00 2001 From: Claire Bontempo Date: Wed, 13 Oct 2021 11:31:31 -0700 Subject: [PATCH 1/7] adds helper so only rows with values display --- ui/app/templates/components/database-connection.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/app/templates/components/database-connection.hbs b/ui/app/templates/components/database-connection.hbs index 19aee380418fc..efcb435ca4eed 100644 --- a/ui/app/templates/components/database-connection.hbs +++ b/ui/app/templates/components/database-connection.hbs @@ -310,14 +310,14 @@ {{#let attr.options.defaultShown as |defaultDisplay|}} {{#if (eq attr.type "object")}} {{else if (eq attr.type "array")}} {{else}} Date: Wed, 13 Oct 2021 12:01:07 -0700 Subject: [PATCH 2/7] adds changelog --- changelog/12819.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/12819.txt diff --git a/changelog/12819.txt b/changelog/12819.txt new file mode 100644 index 0000000000000..80e772b4827bd --- /dev/null +++ b/changelog/12819.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Removes empty rows from DB config views +``` From 1fe28eb6a995f04855a639a98b44d8520c61e409 Mon Sep 17 00:00:00 2001 From: Claire Bontempo Date: Wed, 13 Oct 2021 12:39:58 -0700 Subject: [PATCH 3/7] fixes tests" --- ui/tests/acceptance/secrets/backend/database/secret-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/tests/acceptance/secrets/backend/database/secret-test.js b/ui/tests/acceptance/secrets/backend/database/secret-test.js index 8ab2744bae4c4..1d7950a133d44 100644 --- a/ui/tests/acceptance/secrets/backend/database/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/database/secret-test.js @@ -309,7 +309,7 @@ module('Acceptance | secrets/database/*', function(hooks) { { label: 'Connection URL', name: 'connection_url', value: 'mongodb://127.0.0.1:235/horses' }, { label: 'Username', name: 'username', value: 'user', hideOnShow: true }, { label: 'Password', name: 'password', password: 'so-secure', hideOnShow: true }, - { label: 'Write concern', name: 'write_concern' }, + { label: 'Write concern', name: 'write_concern', hideOnShow: true }, ], }; assert.equal( From a50e0d08f29c6a3774fa003e1aaff138c2e88cc5 Mon Sep 17 00:00:00 2001 From: Claire Bontempo Date: Wed, 13 Oct 2021 13:24:03 -0700 Subject: [PATCH 4/7] add argument to is-empty-value helper to check for default --- ui/app/helpers/is-empty-value.js | 7 +++++-- ui/app/templates/components/database-connection.hbs | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/app/helpers/is-empty-value.js b/ui/app/helpers/is-empty-value.js index 2c43bdd99bcb0..e6ba1f8169f26 100644 --- a/ui/app/helpers/is-empty-value.js +++ b/ui/app/helpers/is-empty-value.js @@ -1,7 +1,10 @@ import { helper } from '@ember/component/helper'; -export default helper(function isEmptyValue([value] /*, hash*/) { - if (typeof value === 'object' && value !== null) { +export default helper(function isEmptyValue([value], { hasDefault = false }) { + if (hasDefault) { + value = hasDefault; + } + if (typeof value === 'object' && value !== null && !hasDefault) { return Object.keys(value).length === 0; } return value == null || value === ''; diff --git a/ui/app/templates/components/database-connection.hbs b/ui/app/templates/components/database-connection.hbs index efcb435ca4eed..69b34a7c33f77 100644 --- a/ui/app/templates/components/database-connection.hbs +++ b/ui/app/templates/components/database-connection.hbs @@ -310,14 +310,14 @@ {{#let attr.options.defaultShown as |defaultDisplay|}} {{#if (eq attr.type "object")}} {{else if (eq attr.type "array")}} {{else}} Date: Wed, 13 Oct 2021 13:24:48 -0700 Subject: [PATCH 5/7] change back test --- ui/tests/acceptance/secrets/backend/database/secret-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/tests/acceptance/secrets/backend/database/secret-test.js b/ui/tests/acceptance/secrets/backend/database/secret-test.js index 1d7950a133d44..8ab2744bae4c4 100644 --- a/ui/tests/acceptance/secrets/backend/database/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/database/secret-test.js @@ -309,7 +309,7 @@ module('Acceptance | secrets/database/*', function(hooks) { { label: 'Connection URL', name: 'connection_url', value: 'mongodb://127.0.0.1:235/horses' }, { label: 'Username', name: 'username', value: 'user', hideOnShow: true }, { label: 'Password', name: 'password', password: 'so-secure', hideOnShow: true }, - { label: 'Write concern', name: 'write_concern', hideOnShow: true }, + { label: 'Write concern', name: 'write_concern' }, ], }; assert.equal( From 89a258120316cd2ad29d8988f16e0576f2220108 Mon Sep 17 00:00:00 2001 From: Claire Bontempo Date: Wed, 13 Oct 2021 13:57:04 -0700 Subject: [PATCH 6/7] remove second, unnecessary check for default --- ui/app/helpers/is-empty-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/helpers/is-empty-value.js b/ui/app/helpers/is-empty-value.js index e6ba1f8169f26..6f3de8abd1495 100644 --- a/ui/app/helpers/is-empty-value.js +++ b/ui/app/helpers/is-empty-value.js @@ -4,7 +4,7 @@ export default helper(function isEmptyValue([value], { hasDefault = false }) { if (hasDefault) { value = hasDefault; } - if (typeof value === 'object' && value !== null && !hasDefault) { + if (typeof value === 'object' && value !== null) { return Object.keys(value).length === 0; } return value == null || value === ''; From 6951146d744858040d24ff98e7c1d31207fe5b21 Mon Sep 17 00:00:00 2001 From: Claire Bontempo Date: Thu, 14 Oct 2021 12:20:45 -0700 Subject: [PATCH 7/7] adds test to helper for added named argument --- .../helpers/is-empty-value-test.js | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/ui/tests/integration/helpers/is-empty-value-test.js b/ui/tests/integration/helpers/is-empty-value-test.js index 16ab5eb2aaef9..6ad8e3f535f16 100644 --- a/ui/tests/integration/helpers/is-empty-value-test.js +++ b/ui/tests/integration/helpers/is-empty-value-test.js @@ -4,7 +4,7 @@ import { render } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; const template = hbs` -{{#if (is-empty-value inputValue)}} +{{#if (is-empty-value inputValue hasDefault=defaultValue)}} Empty {{else}} Full @@ -18,34 +18,55 @@ const nonEmptyObject = { thing: 0 }; module('Integration | Helper | is-empty-value', function(hooks) { setupRenderingTest(hooks); - test('it is truthy if the value evaluated is undefined', async function(assert) { + test('it is truthy if the value evaluated is undefined and no default', async function(assert) { this.set('inputValue', undefined); + this.set('defaultValue', false); await render(template); assert.dom(this.element).hasText('Empty'); }); - test('it is truthy if the value evaluated is an empty string', async function(assert) { + test('it is truthy if the value evaluated is an empty string and no default', async function(assert) { this.set('inputValue', ''); + this.set('defaultValue', false); await render(template); assert.dom(this.element).hasText('Empty'); }); - test('it is truthy if the value evaluated is an empty object', async function(assert) { + test('it is truthy if the value evaluated is an empty object and no default', async function(assert) { this.set('inputValue', emptyObject); + this.set('defaultValue', false); await render(template); assert.dom(this.element).hasText('Empty'); }); - test('it is falsy if the value evaluated is not an empty object', async function(assert) { + + test('it is falsy if the value evaluated is not an empty object and no default', async function(assert) { this.set('inputValue', nonEmptyObject); + this.set('defaultValue', false); await render(template); assert.dom(this.element).hasText('Full'); }); + + test('it is falsy if the value evaluated is empty but a default exists', async function(assert) { + this.set('defaultValue', 'Some default'); + this.set('inputValue', emptyObject); + + await render(template); + assert.dom(this.element).hasText('Full', 'shows default when value is empty object'); + + this.set('inputValue', ''); + await render(template); + assert.dom(this.element).hasText('Full', 'shows default when value is empty string'); + + this.set('inputValue', undefined); + await render(template); + assert.dom(this.element).hasText('Full', 'shows default when value is undefined'); + }); });