From 1f64e6e9ca9cba5bbe98539925f3baa0cae03dec Mon Sep 17 00:00:00 2001 From: claire bontempo <68122737+hellobontempo@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:20:09 -0700 Subject: [PATCH] UI: Allow repeat data wrapping for wrap tool (#27289) * update selectors * add tests * add tests * add explanations to true only args * allow token wrap to wrap again * update test wording * add wrap specific modules to tools acceptance test * add changelog * remove selectedAction * trim args and update tests --- changelog/27289.txt | 3 + ui/app/components/tool-actions-form.js | 23 +-- ui/app/components/tool-wrap.js | 37 ++--- .../components/tool-actions-form.hbs | 7 +- ui/app/templates/components/tool-hash.hbs | 4 +- ui/app/templates/components/tool-lookup.hbs | 12 +- ui/app/templates/components/tool-random.hbs | 2 +- ui/app/templates/components/tool-rewrap.hbs | 2 +- ui/app/templates/components/tool-unwrap.hbs | 6 +- ui/app/templates/components/tool-wrap.hbs | 37 ++--- ui/tests/acceptance/tools-test.js | 155 +++++++++++------- ui/tests/helpers/tools-selectors.ts | 11 ++ .../components/tools/tool-wrap-test.js | 81 +++++++++ 13 files changed, 253 insertions(+), 127 deletions(-) create mode 100644 changelog/27289.txt create mode 100644 ui/tests/helpers/tools-selectors.ts create mode 100644 ui/tests/integration/components/tools/tool-wrap-test.js diff --git a/changelog/27289.txt b/changelog/27289.txt new file mode 100644 index 000000000000..3e10cf0a02f6 --- /dev/null +++ b/changelog/27289.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Allow users to wrap inputted data again instead of resetting form +``` diff --git a/ui/app/components/tool-actions-form.js b/ui/app/components/tool-actions-form.js index 306bfb7c4e5b..b6407255b6b4 100644 --- a/ui/app/components/tool-actions-form.js +++ b/ui/app/components/tool-actions-form.js @@ -32,12 +32,12 @@ export default Component.extend(DEFAULTS, { flashMessages: service(), store: service(), // putting these attrs here so they don't get reset when you click back - //random + // random bytes: 32, - //hash + // hash format: 'base64', algorithm: 'sha2-256', - + data: '{\n}', tagName: '', didReceiveAttrs() { @@ -139,15 +139,18 @@ export default Component.extend(DEFAULTS, { this.reset(); }, - updateTtl(ttl) { - set(this, 'wrapTTL', ttl); + onBack(properties) { + // only reset specific properties so user can reuse input data and repeat the action + if (this.isDestroyed || this.isDestroying) { + return; + } + properties.forEach((prop) => { + set(this, prop, DEFAULTS[prop]); + }); }, - codemirrorUpdated(val, hasErrors) { - setProperties(this, { - buttonDisabled: hasErrors, - data: val, - }); + onChange(param, value) { + set(this, param, value); }, }, }); diff --git a/ui/app/components/tool-wrap.js b/ui/app/components/tool-wrap.js index 02eb0d6acfde..2435b14b247d 100644 --- a/ui/app/components/tool-wrap.js +++ b/ui/app/components/tool-wrap.js @@ -12,45 +12,36 @@ import { tracked } from '@glimmer/tracking'; * ToolWrap components are components that sys/wrapping/wrap functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties. * * @example - * ```js * - * ``` - * @param onClear {Function} - parent action that is passed through. Must be passed as {{action "onClear"}} - * @param token=null {String} - property passed from parent to child and then passed back up to parent - * @param selectedAction="wrap" - passed in from parent. This is the wrap action, others include hash, etc. - * @param codemirrorUpdated {Function} - parent action that is passed through. Must be passed as {{action "codemirrorUpdated"}}. - * @param updateTtl {Function} - parent action that is passed through. Must be passed as {{action "updateTtl"}} - * @param buttonDisabled=false {Boolean} - false default and if there is an error on codemirror it turns to true. - * @param error=null {Object} - errors passed from parent as default then from child back to parent. + * @token={{@token}} + * /> + * + * @param {object} errors=null - errors returned if wrap fails + * @param {function} onBack - callback that only clears specific values so the action can be repeated. Must be passed as `{{action "onBack"}}` + * @param {function} onChange - callback that fires when inputs change and passes value and param name back to the parent + * @param {function} onClear - callback that resets all of values to defaults. Must be passed as `{{action "onClear"}}` + * @param {string} token=null - returned after user clicks "Wrap data", if there is a token value it displays instead of the JsonEditor */ export default class ToolWrap extends Component { - @tracked data = '{\n}'; @tracked buttonDisabled = false; - @action - onClear() { - this.args.onClear(); - } @action updateTtl(evt) { if (!evt) return; const ttl = evt.enabled ? `${evt.seconds}s` : '30m'; - this.args.updateTtl(ttl); + this.args.onChange('wrapTTL', ttl); } + @action codemirrorUpdated(val, codemirror) { codemirror.performLint(); const hasErrors = codemirror?.state.lint.marked?.length > 0; - this.data = val; this.buttonDisabled = hasErrors; - this.args.codemirrorUpdated(val, hasErrors); + this.args.onChange('data', val); } } diff --git a/ui/app/templates/components/tool-actions-form.hbs b/ui/app/templates/components/tool-actions-form.hbs index 53ae308392fc..fb88239f6ab8 100644 --- a/ui/app/templates/components/tool-actions-form.hbs +++ b/ui/app/templates/components/tool-actions-form.hbs @@ -54,12 +54,11 @@ {{else if (eq this.selectedAction "wrap")}} {{else}} diff --git a/ui/app/templates/components/tool-hash.hbs b/ui/app/templates/components/tool-hash.hbs index b1eed813cfae..cc244f3c42dd 100644 --- a/ui/app/templates/components/tool-hash.hbs +++ b/ui/app/templates/components/tool-hash.hbs @@ -30,7 +30,7 @@ />
- +
{{else}} @@ -80,7 +80,7 @@
- +
{{/if}} \ No newline at end of file diff --git a/ui/app/templates/components/tool-lookup.hbs b/ui/app/templates/components/tool-lookup.hbs index d01e071d8b8e..682ab7bf7fda 100644 --- a/ui/app/templates/components/tool-lookup.hbs +++ b/ui/app/templates/components/tool-lookup.hbs @@ -13,12 +13,12 @@ {{#if (or @creation_time @creation_ttl)}}
- - - + + + {{#if @expirationDate}} - - + + {{/if}}
@@ -42,7 +42,7 @@
- +
{{/if}} \ No newline at end of file diff --git a/ui/app/templates/components/tool-random.hbs b/ui/app/templates/components/tool-random.hbs index ac0556a06ab1..36f71ea16e8a 100644 --- a/ui/app/templates/components/tool-random.hbs +++ b/ui/app/templates/components/tool-random.hbs @@ -63,7 +63,7 @@
- +
{{/if}} \ No newline at end of file diff --git a/ui/app/templates/components/tool-rewrap.hbs b/ui/app/templates/components/tool-rewrap.hbs index 223a60a429e2..07fd050e40c8 100644 --- a/ui/app/templates/components/tool-rewrap.hbs +++ b/ui/app/templates/components/tool-rewrap.hbs @@ -56,7 +56,7 @@
- +
{{/if}} \ No newline at end of file diff --git a/ui/app/templates/components/tool-unwrap.hbs b/ui/app/templates/components/tool-unwrap.hbs index 0aa14feae2d3..3716ced3e415 100644 --- a/ui/app/templates/components/tool-unwrap.hbs +++ b/ui/app/templates/components/tool-unwrap.hbs @@ -13,8 +13,8 @@ {{#if @unwrap_data}} - Data - Wrap Details + Data + Wrap Details
- +
{{/if}} \ No newline at end of file diff --git a/ui/app/templates/components/tool-wrap.hbs b/ui/app/templates/components/tool-wrap.hbs index ef28aa91bac1..04fd967782ec 100644 --- a/ui/app/templates/components/tool-wrap.hbs +++ b/ui/app/templates/components/tool-wrap.hbs @@ -16,48 +16,41 @@
-