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

UI/tools partial #11672

merged 12 commits into from
May 24, 2021

Conversation

Monkeychip
Copy link
Contributor

@Monkeychip Monkeychip commented May 19, 2021

In an effort to get ahead of future Ember upgrade depreciations we are trying to replace our use of partials with components. This tackles the Tools area.

In the end there is slightly more code, but it is much easier to read.

@@ -135,14 +135,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.

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.

export default class HashTool 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.

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.

@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.

import Component from '@glimmer/component';
import { action } from '@ember/object';

export default class HashTool extends Component {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to add JSDocs here and include onClear as a required attr, as well as anything else used on the template

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea.

@Monkeychip Monkeychip added the ui label May 20, 2021
@Monkeychip Monkeychip added this to the 1.8 milestone May 20, 2021
@action
codemirrorUpdated(val, codemirror) {
codemirror.performLint();
const hasErrors = codemirror.state.lint.marked.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should use optional chaining here in case marked or anything upstream comes back undefined?

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 point.

@@ -1,3 +1,59 @@
<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.

😍

}
@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.

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

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.

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.

* @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 😄

@Monkeychip Monkeychip merged commit 331f594 into master May 24, 2021
@Monkeychip Monkeychip deleted the ui/tools-partial branch May 24, 2021 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants