Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/remove empty rows from DB config pages #12819

Merged
merged 7 commits into from Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});
});