-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: Configure KameletBinding & Pipe properties #180
Conversation
1a7c734
to
3a850e1
Compare
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.
LGTM, just a very minor details around the code
getComponentSchema(path?: string): VisualComponentSchema | undefined { | ||
if (!path) return undefined; | ||
const stepModel = get(this.route.spec, path) as KameletBindingStep; | ||
return stepModel ? KameletSchemaService.getVisualComponentSchema(stepModel) : undefined; |
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 result of get()
will be undefined
if not found. In addition to that, you have a validation in KameletSchemaService.getVisualComponentSchema(stepModel)
, so I think that it's safe to do something like:
const stepModel = get(this.route.spec, path) as KameletBindingStep;
return KameletSchemaService.getVisualComponentSchema(stepModel);
// or
return KameletSchemaService.getVisualComponentSchema(get(this.route.spec, path) as KameletBindingStep);
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.
done!
if (firstVizNode !== undefined) { | ||
rootNode.setNextNode(firstVizNode); | ||
firstVizNode.setPreviousNode(rootNode); | ||
if (stepNodes !== undefined) { |
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 getVizNodesFromSteps
method is indirectly checking whether this.route.spec?.steps
is an array or not, by using the optional chaining ?
syntax.
With that in mind, would it make sense to simply call?
const stepNodes = this.getVizNodesFromSteps(this.route.spec?.steps);
If we want to be extra safe (I think we should), we could add a validation within the getVizNodesFromSteps
method to prevent the error when the user provides something different than an array to that property, let's say a string
or a number
.
private getVizNodesFromSteps(steps: Array<KameletBindingStep>): VisualizationNode[] {
if (!Array.isArray(steps)) {
return undefined;
}
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.
WebStorm complains with that, saying the argument of getVizNodesFromSteps()
is incompatible if it's undefined
, so I think in that case the argument steps
needs to be marked as optional with "?"
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.
added the array check anyway
}; | ||
} | ||
|
||
static getSchemaFromKameletDefinition(definition: IKameletDefinition | undefined): JSONSchemaType<unknown> { |
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.
[very-minor] Could we please make these methods private if they are not intended to be used outside of this class?
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.
done!
Fixes: #149