-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
UI/tools partial #11672
Changes from 10 commits
dd12ed7
5b86597
ee124b0
acebebe
c907bd1
9127434
a2f7206
012e3ec
13b2b14
481c571
627342f
6db9dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
```release-note:improvement | ||
ui: Replace tool partials with components. | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }; | ||
} | ||
|
@@ -135,14 +134,11 @@ export default Component.extend(DEFAULTS, { | |
this.reset(); | ||
}, | ||
|
||
updateTtl(evt) { | ||
const ttl = evt.enabled ? `${evt.seconds}s` : '30m'; | ||
updateTtl(ttl) { | ||
set(this, 'wrapTTL', ttl); | ||
}, | ||
|
||
codemirrorUpdated(val, codemirror) { | ||
codemirror.performLint(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, can codemirror be undefined or null? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for all new components the |
||
} | ||
} |
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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can codemirror be undefined or null? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notice these are all There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
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.