Hide fields that are empty in secrets configuration (#11230)

Updated the existing helper to check for empty object, string,
null or undefined
This commit is contained in:
Arnav Palnitkar 2021-03-31 15:34:20 -07:00 committed by GitHub
parent 03af94760b
commit 7a67f973ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 49 deletions

View File

@ -1,5 +0,0 @@
import { helper } from '@ember/component/helper';
export default helper(function isEmptyObject([object] /*, hash*/) {
return Object.keys(object).length === 0;
});

View File

@ -0,0 +1,8 @@
import { helper } from '@ember/component/helper';
export default helper(function isEmptyValue([value] /*, hash*/) {
if (typeof value === 'object' && value !== null) {
return Object.keys(value).length === 0;
}
return value == null || value === '';
});

View File

@ -1,9 +1,9 @@
<div class="box is-fullwidth is-sideless is-paddingless is-marginless">
{{#each @model.attrs as |attr|}}
{{#if (eq attr.type "object")}}
<InfoTableRow @alwaysRender={{true}} @label={{or attr.options.label (to-label attr.name)}} @value={{stringify (get @model attr.name)}} />
<InfoTableRow @alwaysRender={{not (is-empty-value (get @model attr.name))}} @label={{or attr.options.label (to-label attr.name)}} @value={{stringify (get @model attr.name)}} />
{{else}}
<InfoTableRow @alwaysRender={{true}} @label={{or attr.options.label (to-label attr.name)}} @value={{get @model attr.name}} />
<InfoTableRow @alwaysRender={{not (is-empty-value (get @model attr.name))}} @label={{or attr.options.label (to-label attr.name)}} @value={{get @model attr.name}} />
{{/if}}
{{/each}}
</div>

View File

@ -101,7 +101,7 @@
<div class="field is-grouped is-grouped-split is-fullwidth box is-bottomless">
<div class="field is-grouped">
<div class="control">
{{#if (is-empty-object this.warningMessages)}}
{{#if (is-empty-value this.warningMessages)}}
<button
data-test-secret-save
type="submit"

View File

@ -20,9 +20,9 @@
<div class="box is-fullwidth is-sideless is-paddingless is-marginless">
{{#each model.attrs as |attr|}}
{{#if (eq attr.type "object")}}
<InfoTableRow @alwaysRender={{true}} @label={{or attr.options.label (to-label attr.name)}} @value={{stringify (get model attr.name)}} />
<InfoTableRow @alwaysRender={{not (is-empty-value (get model attr.name))}} @label={{or attr.options.label (to-label attr.name)}} @value={{stringify (get model attr.name)}} />
{{else}}
<InfoTableRow @alwaysRender={{not-eq attr.name "options.version"}} @label={{or attr.options.label (to-label attr.name)}} @value={{get model attr.name}} />
<InfoTableRow @alwaysRender={{and (not (is-empty-value (get model attr.name))) (not-eq attr.name "options.version")}} @label={{or attr.options.label (to-label attr.name)}} @value={{get model attr.name}} />
{{/if}}
{{/each}}
</div>

View File

@ -1,39 +0,0 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
const emptyObject = {};
const nonEmptyObject = { thing: 0 };
module('Integration | Helper | is-empty-object', function(hooks) {
setupRenderingTest(hooks);
test('it is truthy if the object evaluated is an empty object', async function(assert) {
this.set('inputValue', emptyObject);
await render(hbs`
{{#if (is-empty-object inputValue)}}
Empty
{{else}}
Full
{{/if}}
`);
assert.equal(this.element.textContent.trim(), 'Empty');
});
test('it is falsy if the object evaluated is not an empty object', async function(assert) {
this.set('inputValue', nonEmptyObject);
await render(hbs`
{{#if (is-empty-object inputValue)}}
Empty
{{else}}
Full
{{/if}}
`);
assert.equal(this.element.textContent.trim(), 'Full');
});
});

View File

@ -0,0 +1,51 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
const template = hbs`
{{#if (is-empty-value inputValue)}}
Empty
{{else}}
Full
{{/if}}
`;
const emptyObject = {};
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) {
this.set('inputValue', undefined);
await render(template);
assert.equal(this.element.textContent.trim(), 'Empty');
});
test('it is truthy if the value evaluated is an empty string', async function(assert) {
this.set('inputValue', '');
await render(template);
assert.equal(this.element.textContent.trim(), 'Empty');
});
test('it is truthy if the value evaluated is an empty object', async function(assert) {
this.set('inputValue', emptyObject);
await render(template);
assert.equal(this.element.textContent.trim(), 'Empty');
});
test('it is falsy if the value evaluated is not an empty object', async function(assert) {
this.set('inputValue', nonEmptyObject);
await render(template);
assert.equal(this.element.textContent.trim(), 'Full');
});
});