mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 12:26:34 +02:00
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:
parent
03af94760b
commit
7a67f973ba
@ -1,5 +0,0 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export default helper(function isEmptyObject([object] /*, hash*/) {
|
||||
return Object.keys(object).length === 0;
|
||||
});
|
||||
8
ui/app/helpers/is-empty-value.js
Normal file
8
ui/app/helpers/is-empty-value.js
Normal 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 === '';
|
||||
});
|
||||
@ -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>
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
51
ui/tests/integration/helpers/is-empty-value-test.js
Normal file
51
ui/tests/integration/helpers/is-empty-value-test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user