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

feat: Configure KameletBinding & Pipe properties #180

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

igarashitm
Copy link
Contributor

Fixes: #149

@igarashitm igarashitm requested a review from a team October 3, 2023 17:32
@igarashitm igarashitm force-pushed the 149 branch 2 times, most recently from 1a7c734 to 3a850e1 Compare October 4, 2023 11:13
Copy link
Member

@lordrip lordrip left a 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;
Copy link
Member

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);

Copy link
Contributor Author

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) {
Copy link
Member

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;
  }

Copy link
Contributor Author

@igarashitm igarashitm Oct 4, 2023

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 "?"

Copy link
Contributor Author

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> {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@igarashitm igarashitm merged commit 779d463 into KaotoIO:main Oct 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure KameletBinding & Pipe properties
2 participants