UI: allow reset on database json fields (#11708)

This commit is contained in:
Chelsea Shaw 2021-05-27 16:25:58 -05:00 committed by GitHub
parent 9ebb14bab3
commit cef14f0236
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 5 deletions

3
changelog/11708.txt Normal file
View file

@ -0,0 +1,3 @@
```release-note:improvement
ui: JSON fields on database can be cleared on edit
```

View file

@ -198,10 +198,10 @@ export default Model.extend({
port: attr('string', {}), port: attr('string', {}),
write_concern: attr('string', { write_concern: attr('string', {
subText: 'Optional. Must be in JSON. See our documentation for help.', subText: 'Optional. Must be in JSON. See our documentation for help.',
allowReset: true,
editType: 'json', editType: 'json',
theme: 'hashi short', theme: 'hashi short',
defaultShown: 'Default', defaultShown: 'Default',
// defaultValue: '# For example: { "wmode": "majority", "wtimeout": 5000 }',
}), }),
username_template: attr('string', { username_template: attr('string', {
editType: 'optionalText', editType: 'optionalText',

View file

@ -69,11 +69,13 @@ export default Model.extend({
}), }),
creation_statement: attr('string', { creation_statement: attr('string', {
editType: 'json', editType: 'json',
allowReset: true,
theme: 'hashi short', theme: 'hashi short',
defaultShown: 'Default', defaultShown: 'Default',
}), }),
revocation_statement: attr('string', { revocation_statement: attr('string', {
editType: 'json', editType: 'json',
allowReset: true,
theme: 'hashi short', theme: 'hashi short',
defaultShown: 'Default', defaultShown: 'Default',
}), }),

View file

@ -213,9 +213,6 @@
@spellcheck="false" /> @spellcheck="false" />
{{else if (eq attr.options.editType "json")}} {{else if (eq attr.options.editType "json")}}
{{!-- JSON Editor --}} {{!-- JSON Editor --}}
{{#if attr.options.subText}}
<p class="sub-text">{{attr.options.subText}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</p>
{{/if}}
<JsonEditor <JsonEditor
data-test-input={{attr.name}} data-test-input={{attr.name}}
@title={{labelString}} @title={{labelString}}
@ -229,7 +226,26 @@
theme=(or attr.options.theme 'hashi') theme=(or attr.options.theme 'hashi')
}} }}
@helpText={{attr.options.helpText}} @helpText={{attr.options.helpText}}
/> >
{{#if attr.options.allowReset}}
<button
type="button"
class="toolbar-link"
disabled={{not (get model valuePath)}}
onClick={{action
(action "setAndBroadcast" valuePath)
null
}}
data-test-json-clear-button
>
Clear
<Icon @glyph="refresh-default" aria-hidden="true" />
</button>
{{/if}}
</JsonEditor>
{{#if attr.options.subText}}
<p class="sub-text">{{attr.options.subText}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</p>
{{/if}}
{{else}} {{else}}
{{!-- Regular Text Input --}} {{!-- Regular Text Input --}}
<input data-test-input={{attr.name}} id={{attr.name}} autocomplete="off" spellcheck="false" <input data-test-input={{attr.name}} id={{attr.name}} autocomplete="off" spellcheck="false"

View file

@ -85,6 +85,13 @@ module('Integration | Component | form field', function(hooks) {
assert.ok(component.hasJSONEditor, 'renders the json editor'); assert.ok(component.hasJSONEditor, 'renders the json editor');
}); });
test('it renders: string as json with clear button', async function(assert) {
await setup.call(this, createAttr('foo', 'string', { editType: 'json', allowReset: true }));
assert.equal(component.fields.objectAt(0).labelText, 'Foo', 'renders a label');
assert.ok(component.hasJSONEditor, 'renders the json editor');
assert.ok(component.hasJSONClearButton, 'renders button that will clear the JSON value');
});
test('it renders: editType textarea', async function(assert) { test('it renders: editType textarea', async function(assert) {
let [model, spy] = await setup.call( let [model, spy] = await setup.call(
this, this,

View file

@ -16,6 +16,7 @@ export default {
hasTextFile: isPresent('[data-test-component=text-file]'), hasTextFile: isPresent('[data-test-component=text-file]'),
hasTTLPicker: isPresent('[data-test-toggle-input="Foo"]'), hasTTLPicker: isPresent('[data-test-toggle-input="Foo"]'),
hasJSONEditor: isPresent('[data-test-component=json-editor]'), hasJSONEditor: isPresent('[data-test-component=json-editor]'),
hasJSONClearButton: isPresent('[data-test-json-clear-button]'),
hasSelect: isPresent('select'), hasSelect: isPresent('select'),
hasInput: isPresent('input'), hasInput: isPresent('input'),
hasCheckbox: isPresent('input[type=checkbox]'), hasCheckbox: isPresent('input[type=checkbox]'),