Skip to content

Commit

Permalink
UI/remove empty rows from DB config pages (#12819)
Browse files Browse the repository at this point in the history
* adds helper so only rows with values display

* adds changelog

* add argument to is-empty-value helper to check for default

* adds test to helper for added named argument
  • Loading branch information
hellobontempo committed Oct 14, 2021
1 parent f1f4001 commit 28ecc17
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelog/12819.txt
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Removes empty rows from DB config views
```
5 changes: 4 additions & 1 deletion ui/app/helpers/is-empty-value.js
@@ -1,6 +1,9 @@
import { helper } from '@ember/component/helper';

export default helper(function isEmptyValue([value] /*, hash*/) {
export default helper(function isEmptyValue([value], { hasDefault = false }) {
if (hasDefault) {
value = hasDefault;
}
if (typeof value === 'object' && value !== null) {
return Object.keys(value).length === 0;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/app/templates/components/database-connection.hbs
Expand Up @@ -310,14 +310,14 @@
{{#let attr.options.defaultShown as |defaultDisplay|}}
{{#if (eq attr.type "object")}}
<InfoTableRow
@alwaysRender={{true}}
@alwaysRender={{not (is-empty-value (get @model attr.name) hasDefault=defaultDisplay)}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{stringify (get @model attr.name)}}
/>
{{else if (eq attr.type "array")}}
<InfoTableRow
@alwaysRender={{true}}
@alwaysRender={{not (is-empty-value (get @model attr.name) hasDefault=defaultDisplay)}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{get @model attr.name}}
Expand All @@ -327,7 +327,7 @@
/>
{{else}}
<InfoTableRow
@alwaysRender={{true}}
@alwaysRender={{not (is-empty-value (get @model attr.name) hasDefault=defaultDisplay)}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{get @model attr.name}}
Expand Down
31 changes: 26 additions & 5 deletions ui/tests/integration/helpers/is-empty-value-test.js
Expand Up @@ -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
Expand All @@ -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');
});
});

0 comments on commit 28ecc17

Please sign in to comment.