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/tools partial #11672

Merged
merged 12 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 4 additions & 0 deletions changelog/11672.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
ui: Replace tool partials with components.
```

8 changes: 2 additions & 6 deletions ui/app/components/tool-actions-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export default Component.extend(DEFAULTS, {
if (action === 'random') {
return { bytes: this.bytes, format: this.format };
}

if (action === 'hash') {
return { input: this.input, format: this.format, algorithm: this.algorithm };
}
Expand Down Expand Up @@ -135,14 +134,11 @@ export default Component.extend(DEFAULTS, {
this.reset();
},

updateTtl(evt) {
const ttl = evt.enabled ? `${evt.seconds}s` : '30m';
Copy link
Contributor Author

@Monkeychip Monkeychip May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ttl is determined in the tool-wrap component.

updateTtl(ttl) {
set(this, 'wrapTTL', ttl);
},

codemirrorUpdated(val, codemirror) {
codemirror.performLint();
Copy link
Contributor Author

@Monkeychip Monkeychip May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codemirror things need to happen inside the component where codemirror is being used, thus the property codemirror is used in the tool-wrap component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, can codemirror be undefined or null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, it's always an object that's returned.

const hasErrors = codemirror.state.lint.marked.length > 0;
codemirrorUpdated(val, hasErrors) {
setProperties(this, {
buttonDisabled: hasErrors,
data: val,
Expand Down
28 changes: 28 additions & 0 deletions ui/app/components/tool-hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

/**
* @module ToolHash
* ToolHash components are components that sys/wrapping/hash functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties.
*
* @example
* ```js
* <ToolHash
* @onClear={{action "onClear"}}
* @sum={{sum}}
* @algorithm={{algorithm}}
* @format={{format}}
* @errors={{errors}}/>
* ```
* @param onClear {Function} - parent action that is passed through. Must be passed as {{action "onClear"}}
* @param sum=null {String} - property passed from parent to child and then passed back up to parent
* @param algorithm {String} - property returned from parent.
* @param format {String} - property returned from parent.
* @param error=null {Object} - errors passed from parent as default then from child back to parent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job with js doc, I should add it as well 😄

*/
export default class ToolHash extends Component {
@action
onClear() {
this.args.onClear();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all new components the onClear() action is passed through to the child as a property and then called again via an action.

}
}
34 changes: 34 additions & 0 deletions ui/app/components/tool-lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

/**
* @module ToolLookup
* ToolLookup components are components that sys/wrapping/lookup functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties.
*
* @example
* ```js
* <ToolLookup
* @creation_time={{creation_time}}
* @creation_ttl={{creation_ttl}}
* @creation_path={{creation_path}}
* @expirationDate={{expirationDate}}
* @selectedAction={{selectedAction}}
* @token={{token}}
* @onClear={{action "onClear"}}
* @errors={{errors}}/>
* ```
* @param creation_time {Function} - parent action that is passed through.
* @param creation_ttl {Function} - parent action that is passed through.
* @param creation_path {Function} - parent action that is passed through.
* @param expirationDate='' {String} - value returned from lookup.
* @param selectedAction="wrap" - passed in from parent. This is the wrap action, others include hash, etc.
* @param token=null {String} - property passed from parent to child and then passed back up to parent
* @param onClear {Function} - parent action that is passed through. Must be passed as {{action "onClear"}}
* @param error=null {Object} - errors passed from parent as default then from child back to parent.
*/
export default class ToolLookup extends Component {
@action
onClear() {
this.args.onClear();
}
}
29 changes: 29 additions & 0 deletions ui/app/components/tool-random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

/**
* @module ToolRandom
* ToolRandom components are components that sys/wrapping/random functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties.
*
* @example
* ```js
* <ToolRandom
* @onClear={{action "onClear"}}
* @format={{format}}
* @bytes={{bytes}}
* @random_bytes={{random_bytes}}
* @errors={{errors}}/>
* ```
* @param onClear {Function} - parent action that is passed through. Must be passed as {{action "onClear"}}
* @param format {String} - property returned from parent.
* @param bytes {String} - property returned from parent.
* @param random_bytes {String} - property returned from parent.
* @param error=null {Object} - errors passed from parent as default then from child back to parent.
*/

export default class ToolRandom extends Component {
@action
onClear() {
this.args.onClear();
}
}
31 changes: 31 additions & 0 deletions ui/app/components/tool-rewrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

/**
* @module ToolRewrap
* ToolRewrap components are components that sys/wrapping/rewrap functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties.
*
* @example
* ```js
* <ToolRewrap
* @onClear={{action "onClear"}}
* @token={{token}}
* @rewrap_token={{rewrap_token}}
* @selectedAction={{selectedAction}}
* @bytes={{bytes}}
* @errors={{errors}}/>
* ```
* @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 rewrap_token {String} - property returned from parent.
* @param selectedAction {String} - property returned from parent.
* @param bytes {String} - property returned from parent.
* @param error=null {Object} - errors passed from parent as default then from child back to parent.
*/

export default class ToolRewrap extends Component {
@action
onClear() {
this.args.onClear();
}
}
31 changes: 31 additions & 0 deletions ui/app/components/tool-unwrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

/**
* @module ToolUnwrap
* ToolUnwrap components are components that sys/wrapping/unwrap functionality. Most of the functionality is passed through as actions from the tool-actions-form and then called back with properties.
*
* @example
* ```js
* <ToolUnwrap
* @onClear={{action "onClear"}}
* @token={{token}}
* @unwrap_data={{unwrap_data}}
* @unwrapActiveTab={{unwrapActiveTab}}
* @details={{details}}
* @errors={{errors}}/>
* ```
* @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 unwrap_data {String} - property returned from parent.
* @param unwrapActiveTab {String} - property returned from parent.
* @param details {String} - property returned from parent.
* @param error=null {Object} - errors passed from parent as default then from child back to parent.
*/

export default class ToolUnwrap extends Component {
@action
onClear() {
this.args.onClear();
}
}
51 changes: 51 additions & 0 deletions ui/app/components/tool-wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

/**
* @module ToolWrap
* 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
* <ToolWrap
* @onClear={{action "onClear"}}
* @token={{token}}
* @selectedAction="wrap"
* @codemirrorUpdated={{action "codemirrorUpdated"}}
* @updateTtl={{action "updateTtl"}}
* @buttonDisabled={{buttonDisabled}}
* @errors={{errors}}/>
* ```
* @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.
*/

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);
}
@action
codemirrorUpdated(val, codemirror) {
codemirror.performLint();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can codemirror be undefined or null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also how we handle it in other parts of the app.

const hasErrors = codemirror?.state.lint.marked?.length > 0;
this.data = val;
this.buttonDisabled = hasErrors;
this.args.codemirrorUpdated(val, hasErrors);
Copy link
Contributor Author

@Monkeychip Monkeychip May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we call the parent's codemirrorUpdated function and instead of passing in val, codemirror we pass in val, hasErrors. Again, the codemirror property is only available inside the instance of the component it is used, it cannot be passed through as a property.

}
}
62 changes: 61 additions & 1 deletion ui/app/templates/components/tool-actions-form.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
<form onsubmit={{action "doSubmit"}}>
{{partial (concat "partials/tools/" selectedAction)}}
{{#if (eq selectedAction 'hash')}}
<ToolHash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@onClear={{action "onClear"}}
@sum={{sum}}
@algorithm={{algorithm}}
@errors={{errors}}
@format={{format}}
@input={{input}}
/>
{{else if (eq selectedAction 'random')}}
<ToolRandom
@onClear={{action "onClear"}}
@random_bytes={{random_bytes}}
@errors={{errors}}
@format={{format}}
@bytes={{bytes}}
/>
{{else if (eq selectedAction 'rewrap')}}
<ToolRewrap
@onClear={{action "onClear"}}
@rewrap_token={{rewrap_token}}
@selectedAction={{selectedAction}}
@errors={{errors}}
@token={{token}}
@bytes={{bytes}}
/>
{{else if (eq selectedAction 'unwrap')}}
<ToolUnwrap
@onClear={{action "onClear"}}
@unwrap_data={{unwrap_data}}
@unwrapActiveTab={{unwrapActiveTab}}
@details={{details}}
@errors={{errors}}
@token={{token}}
/>
{{else if (eq selectedAction 'lookup')}}
<ToolLookup
@creation_time={{creation_time}}
@creation_ttl={{creation_ttl}}
@creation_path={{creation_path}}
@expirationDate={{expirationDate}}
@selectedAction={{selectedAction}}
@token={{token}}
@onClear={{action "onClear"}}
@errors={{errors}}
/>
{{else if (eq selectedAction 'wrap')}}
Copy link
Contributor Author

@Monkeychip Monkeychip May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice these are all else ifs, there is no fallback component. Technically there doesn't need to be, but curious if folks take issue with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right call, unless we want to add an empty state (which would most likely be viewed by a developer updating this space)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea with the empty state. It feels strange to have no else so I'll go ahead and add it.

<ToolWrap
@token={{token}}
@selectedAction={{selectedAction}}
@onClear={{action "onClear"}}
@codemirrorUpdated={{action "codemirrorUpdated"}}
@updateTtl={{action "updateTtl"}}
@buttonDisabled={{buttonDisabled}}
@errors={{errors}}
/>
{{else}}
<EmptyState
@title="Tool not available"
/>
{{/if}}
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@
</p.levelLeft>
</PageHeader>

{{#if sum}}
{{#if @sum}}
<div class="box is-sideless is-fullwidth is-marginless">
<div class="field">
<label for="sum" class="is-input">Sum</label>
<div class="control">
<textarea readonly class="textarea" id="sum" data-test-tools-input="sum">{{sum}}</textarea>
<textarea readonly class="textarea" id="sum" data-test-tools-input="sum">{{@sum}}</textarea>
</div>
</div>
</div>
<div class="field is-grouped box is-fullwidth is-bottomless">
<div class="control">
<CopyButton @clipboardText={{sum}} @class="button is-primary" @buttonType="button" @success={{action (set-flash-message "Hashed data copied!")}}>
<CopyButton @clipboardText={{@sum}} @class="button is-primary" @buttonType="button" @success={{action (set-flash-message "Hashed data copied!")}}>
Copy
</CopyButton>
</div>
<div class="control">
<button {{action 'onClear'}} type="button" class="button" data-test-tools-back=true>
<button {{on "click" this.onClear}} type="button" class="button" data-test-tools-back=true>
Back
</button>
</div>
</div>
{{else}}
<div class="box is-sideless is-fullwidth is-marginless">
<MessageError @errors={{errors}} />
<MessageError @errors={{@errors}} />
<div class="field">
<label for="input" class="is-label">
Input
</label>
<div class="control">
<Textarea @id="input" @name="input" @value={{input}} class="textarea" data-test-tools-input="hash-input" />
<B64Toggle @value={{input}} @isInput={{false}} @data-test-tools-b64-toggle="input" />
<Textarea @id="input-hash" @name="input" @value={{@input}} class="textarea" data-test-tools-input="hash-input" />
<B64Toggle @value={{@input}} @isInput={{false}} @data-test-tools-b64-toggle="input" />
</div>
</div>
<div class="field is-horizontal">
Expand All @@ -48,10 +48,10 @@
<select
name="algorithm"
id="algorithm"
onchange={{action (mut algorithm) value="target.value"}}
onchange={{action (mut @algorithm) value="target.value"}}
>
{{#each (sha2-digest-sizes) as |algo|}}
<option selected={{if algorithm (eq algorithm algo)}} value={{algo}}>
<option selected={{if @algorithm (eq @algorithm algo)}} value={{algo}}>
{{algo}}
</option>
{{/each}}
Expand All @@ -66,10 +66,10 @@
<select
name="format"
id="format"
onchange={{action (mut format) value="target.value"}}
onchange={{action (mut @format) value="target.value"}}
>
{{#each (array 'base64' 'hex') as |formatOption|}}
<option selected={{if format (eq format formatOption)}} value={{formatOption}}>
<option selected={{if @format (eq @format formatOption)}} value={{formatOption}}>
{{formatOption}}
</option>
{{/each}}
Expand Down
Loading