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: reset database json fields #11708

Merged
merged 7 commits into from
May 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/11708.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: JSON fields on database can be cleared on edit
```
2 changes: 1 addition & 1 deletion ui/app/models/database/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ export default Model.extend({
port: attr('string', {}),
write_concern: attr('string', {
subText: 'Optional. Must be in JSON. See our documentation for help.',
allowReset: true,
editType: 'json',
theme: 'hashi short',
defaultShown: 'Default',
// defaultValue: '# For example: { "wmode": "majority", "wtimeout": 5000 }',
}),
username_template: attr('string', {
editType: 'optionalText',
Expand Down
2 changes: 2 additions & 0 deletions ui/app/models/database/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export default Model.extend({
}),
creation_statement: attr('string', {
editType: 'json',
allowReset: true,
theme: 'hashi short',
defaultShown: 'Default',
}),
revocation_statement: attr('string', {
editType: 'json',
allowReset: true,
theme: 'hashi short',
defaultShown: 'Default',
}),
Expand Down
24 changes: 20 additions & 4 deletions ui/lib/core/addon/templates/components/form-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@
@spellcheck="false" />
{{else if (eq attr.options.editType "json")}}
{{!-- 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
data-test-input={{attr.name}}
@title={{labelString}}
Expand All @@ -229,7 +226,26 @@
theme=(or attr.options.theme 'hashi')
}}
@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}}
{{!-- Regular Text Input --}}
<input data-test-input={{attr.name}} id={{attr.name}} autocomplete="off" spellcheck="false"
Expand Down
7 changes: 7 additions & 0 deletions ui/tests/integration/components/form-field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ module('Integration | Component | form field', function(hooks) {
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) {
let [model, spy] = await setup.call(
this,
Expand Down
1 change: 1 addition & 0 deletions ui/tests/pages/components/form-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
hasTextFile: isPresent('[data-test-component=text-file]'),
hasTTLPicker: isPresent('[data-test-toggle-input="Foo"]'),
hasJSONEditor: isPresent('[data-test-component=json-editor]'),
hasJSONClearButton: isPresent('[data-test-json-clear-button]'),
hasSelect: isPresent('select'),
hasInput: isPresent('input'),
hasCheckbox: isPresent('input[type=checkbox]'),
Expand Down