Improve Secret Empty States (#12084)

* adds conditional to render 'minus plain' icon when key doesn't exist

* shows a hyphen when KV secret doesn't have a key and/or value

* fixes tests
This commit is contained in:
claire bontempo
2021-07-21 12:47:52 -07:00
committed by GitHub
parent c1374b1bf6
commit 7171e89cc6
5 changed files with 72 additions and 13 deletions

3
changelog/12084.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
ui: Render dashes for secret empty states
```

View File

@@ -18,7 +18,7 @@
.column { .column {
align-self: center; align-self: center;
padding-left: 0px;
&.info-table-row-edit { &.info-table-row-edit {
padding-bottom: 0.3rem; padding-bottom: 0.3rem;
padding-top: 0.3rem; padding-top: 0.3rem;

View File

@@ -49,10 +49,21 @@
</div> </div>
</div> </div>
</div> </div>
{{#if @modelForData.secretKeyAndValue}}
{{#each @modelForData.secretKeyAndValue as |secret|}} {{#each @modelForData.secretKeyAndValue as |secret|}}
<InfoTableRow @label={{secret.key}} @value={{secret.value}} @alwaysRender={{true}}> <InfoTableRow @label={{secret.key}} @value={{secret.value}} @alwaysRender={{true}}>
{{#if secret.value}}
<MaskedInput @value={{secret.value}} @displayOnly={{true}} @allowCopy={{true}}/> <MaskedInput @value={{secret.value}} @displayOnly={{true}} @allowCopy={{true}}/>
{{else}}
<Icon @size="s" @glyph="minus-plain"/>
{{/if}}
</InfoTableRow> </InfoTableRow>
{{/each}} {{/each}}
{{else}}
{{!-- In the case of no key or value <InfoTableRow> will still render --}}
<InfoTableRow @label="" @value="" @alwaysRender={{true}}>
<Icon @size="s" @glyph="minus-plain"/>
</InfoTableRow>
{{/if}}
{{/if}} {{/if}}
{{/if}} {{/if}}

View File

@@ -1,15 +1,17 @@
{{#if (or alwaysRender value)}} {{#if (or alwaysRender value)}}
<div class="column is-one-quarter" data-test-label-div>
{{#if label}} {{#if label}}
<div class="column is-one-quarter">
<span class="is-label has-text-grey-dark" data-test-row-label="{{label}}">{{label}}</span> <span class="is-label has-text-grey-dark" data-test-row-label="{{label}}">{{label}}</span>
{{#if helperText}} {{#if helperText}}
<div> <div>
<span class="is-label helper-text has-text-grey">{{helperText}}</span> <span class="is-label helper-text has-text-grey">{{helperText}}</span>
</div> </div>
{{/if}} {{/if}}
</div> {{else}}
<Icon @size="s" @glyph="minus-plain"/>
{{/if}} {{/if}}
<div class="column is-flex"> </div>
<div class="column is-flex" data-test-value-div>
{{#if (has-block)}} {{#if (has-block)}}
{{yield}} {{yield}}
{{else if valueIsBoolean}} {{else if valueIsBoolean}}
@@ -28,8 +30,11 @@
@glyph="cancel-square-outline" @glyph="cancel-square-outline"
/> No /> No
{{/if}} {{/if}}
{{else if (and (not value) (and alwaysRender defaultShown))}} {{!-- alwaysRender is still true --}}
{{else if (and (not value) defaultShown)}}
<span data-test-row-value="{{label}}">{{defaultShown}}</span> <span data-test-row-value="{{label}}">{{defaultShown}}</span>
{{else if (eq value "")}}
<Icon @size="s" @glyph="minus-plain"/>
{{else}} {{else}}
{{#if (eq type 'array')}} {{#if (eq type 'array')}}
<InfoTableItemArray <InfoTableItemArray

View File

@@ -38,6 +38,8 @@ module('Integration | Component | InfoTableItem', function(hooks) {
}); });
test('it renders', async function(assert) { test('it renders', async function(assert) {
this.set('alwaysRender', true);
await render(hbs`<InfoTableRow await render(hbs`<InfoTableRow
@value={{value}} @value={{value}}
@label={{label}} @label={{label}}
@@ -46,10 +48,13 @@ module('Integration | Component | InfoTableItem', function(hooks) {
assert.dom('[data-test-component="info-table-row"]').exists(); assert.dom('[data-test-component="info-table-row"]').exists();
let string = document.querySelector('code').textContent; let string = document.querySelector('code').textContent;
assert.equal(string, VALUE, 'renders value as passed through'); assert.equal(string, VALUE, 'renders value as passed through');
this.set('value', '');
assert.dom('[data-test-label-div]').doesNotExist('does not render if no value and alwaysRender is false');
}); });
test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) { test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) {
// This could be changed in the component so that it adds a link for any item type, but right it should only add a link if item type is an array. // This could be changed in the component so that it adds a link for any item type, but right now it should only add a link if item type is an array.
await render(hbs`<InfoTableRow await render(hbs`<InfoTableRow
@value={{value}} @value={{value}}
@label={{label}} @label={{label}}
@@ -70,4 +75,39 @@ module('Integration | Component | InfoTableItem', function(hooks) {
assert.dom('[data-test-item="array"]').hasText('valueArray', 'Confirm link with item value exist'); assert.dom('[data-test-item="array"]').hasText('valueArray', 'Confirm link with item value exist');
}); });
test('it renders a dash (-) if a label and/or value do not exist', async function(assert) {
this.set('value', VALUE);
this.set('label', '');
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@alwaysRender={{true}}
/>`);
assert.dom('[data-test-label-div]').exists('renders label div');
assert.dom('[data-test-value-div]').exists('renders value div');
assert.dom('div.column span').hasClass('hs-icon-s', 'Renders a dash (-) for the label');
this.set('value', '');
this.set('label', LABEL);
assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for the value');
this.set('value', '');
this.set('label', '');
let dashCount = document.querySelectorAll('.hs-icon-s').length;
assert.equal(dashCount, 2, 'Renders dash (-) when both label and value do not exist');
});
test('block content overrides any passed in value content', async function(assert) {
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@alwaysRender={{true}}>
Block content is here
</InfoTableRow>`);
let block = document.querySelector('[data-test-value-div]').textContent.trim();
assert.equal(block, 'Block content is here', 'renders block passed through');
});
}); });