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: Support Kamelet Beans #757

Merged
merged 2 commits into from
Jan 30, 2024
Merged

feat: Support Kamelet Beans #757

merged 2 commits into from
Jan 30, 2024

Conversation

igarashitm
Copy link
Contributor

@igarashitm igarashitm commented Jan 30, 2024

Fixes: #540
Fixes: #642

);

return isSupported ? (
<>
<MetadataEditor name="Beans" schema={beansSchema} metadata={getBeansModel()} onChangeModel={onChangeModel} />
Copy link
Contributor Author

@igarashitm igarashitm Jan 30, 2024

Choose a reason for hiding this comment

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

There might be a reason I made it always getting the model from the entity at first, I'll get this back.

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

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.

Looks good 👌 , thanks @igarashitm

let model: any;
let beansHandler: BeansEntityHandler;
beforeEach(() => {
model = { ...routeStub.camelRouteJson };
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to clone the camelRouteJson object, just in case we're performing modifications on it. We could use cloneDeep from lodash or structuredClone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh right, Done 👍

Comment on lines 77 to 105
setBeansModel(model: BeansDeserializer | RouteTemplateBeanDefinition[]) {
switch (this.type) {
case 'beans': {
if (model?.length > 0) {
let entity = this.getBeansEntity() as BeansEntity;
if (!entity) {
entity = (this.beansAware as BeansAwareResource).createBeansEntity();
}
entity.parent.beans = model;
} else {
const entity = this.getBeansEntity();
entity && this.deleteBeansEntity(entity);
}
break;
}
case 'routeTemplateBean':
if (model?.length > 0) {
let entity = this.getBeansEntity() as RouteTemplateBeansEntity;
if (!entity) {
entity = this.createBeansEntity() as RouteTemplateBeansEntity;
}
entity.parent.beans = model;
} else {
const entity = this.getBeansEntity() as RouteTemplateBeansEntity;
entity && this.deleteBeansEntity(entity);
}
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct to assume that the main difference between both types is how the entity object is assigned?

For beans:

entity = (this.beansAware as BeansAwareResource).createBeansEntity();

For routeTemplateBean:

entity = this.createBeansEntity() as RouteTemplateBeansEntity;

Could something like this work?

  setBeansModel(model: BeansDeserializer | RouteTemplateBeanDefinition[]): void {
    if (!Array.isArray(model) || model.length === 0) {
      const entity = this.getBeansEntity();
      entity && this.deleteBeansEntity(entity);
      return;
    }

    let entity = this.getBeansEntity();

    if (!entity) {
      if (this.type === 'beans') {
        entity = (this.beansAware as BeansAwareResource).createBeansEntity();
      } else {
        entity = this.createBeansEntity() as RouteTemplateBeansEntity;
      }
    }

    entity.parent.beans = model;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes these were redundant, this.getBeansEntity() and this.createBeansEntity() already do the switch-case and this could rely on that - fixed 👍

@@ -0,0 +1,187 @@
import { BeansAwareResource, CamelResource, RouteTemplateBeansAwareResource } from '../../camel';
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a few tests for this class if possible?

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 tests for RouteTemplateBeansAwareResource methods into kamelet-resource.test.ts 👍 For BeansAwareResource we already have some tests in camel-route-resource.test.ts.

- Use lodash cloneDeep to duplicate the test stubs
- Clean up BeansEntityHandler.setBeansModel()
- Add tests for RouteTemplateBeansEntity handling in KameletResource
@igarashitm igarashitm merged commit 775f1bb into KaotoIO:main Jan 30, 2024
8 of 9 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.

Error when saving bean camelResource?.createBeansEntity is not a function Support Kamelet Beans
2 participants