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 configuring expression in Canvas form #272

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

igarashitm
Copy link
Contributor

@igarashitm igarashitm commented Nov 2, 2023

Fixes: #270

Just a mockup for now, plumbing TBD

2023-11-01.20-51-47.mp4

@igarashitm
Copy link
Contributor Author

igarashitm commented Nov 8, 2023

Implementation is done including dialect parsing. I'll add tests and then should be ready to go.

2023-11-08.16-01-18.mp4

@igarashitm
Copy link
Contributor Author

igarashitm commented Nov 8, 2023

One known bug: the language xtokenize has an array property namespace, which breaks this expression editor ATM
we'd need to fix the catalog-schema converter for that
https://github.com/KaotoIO/kaoto-next/pull/272/files#diff-2d877e44faedc2698396d57993c8d9d9a404d30029b306414175166ecbd0f5e4R64

Issue: #311

@igarashitm igarashitm marked this pull request as ready for review November 10, 2023 03:15
@igarashitm igarashitm requested a review from a team November 10, 2023 03:15
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.

This is great @igarashitm, a huge step forward 💪 🙌

return schema?.schema === undefined ? null : (
<ErrorBoundary fallback={<p>This node cannot be configured yet</p>}>
<Title headingLevel="h1">{componentName}</Title>

{isExpressionAwareStep && <ExpressionEditor selectedNode={props.selectedNode} />}
Copy link
Member

Choose a reason for hiding this comment

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

[curious-question]

  1. Couldn't this be added in the CustomAutoField component instead?
  2. Could be possible for this expression property to collide with another one from another resource?
  3. If the latter is true, would be beneficial to have the isExpressionAwareStep logic inside of the camel-route-visual-entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Since this is done outside of the uniforms, CustomAutoField doesn't participate
  2. Can you ellaborate?
  3. I'd like to wait a bit to see how Integration and Kamelet kind is implemented, as this logic will be used for those as well

Copy link
Member

Choose a reason for hiding this comment

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

  1. Could it be incorporated into the CustomAutoField workflow? This is not a blocking issue in any case
  2. I meant what would happen if a Pipe for instance has an expression property? I guess we're gonna see the expression field anyway.
  3. That sounds fair 👍

@@ -1,7 +1,7 @@
import { PipeErrorHandlerEditor } from './PipeErrorHandlerEditor';
import { within } from '@testing-library/dom';
import { fireEvent, render, screen } from '@testing-library/react';
import { pipeErrorHandlerJson } from '../../stubs/PipeErrorHandler';
import * as pipeErrorHandlerSchema from '@kaoto-next/camel-catalog/PipeErrorHandler.json';
Copy link
Member

Choose a reason for hiding this comment

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

Great this is finally working 🎉

Comment on lines +25 to +35
useSchemasStore.setState({
schemas: {
camelYamlDsl: {
name: 'camelYamlDsl',
tags: ['camel'],
version: '1.0.0',
uri: '',
schema: yamlDslSchema as unknown as Record<string, unknown>,
},
},
});
Copy link
Member

Choose a reason for hiding this comment

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

[heads-up]: It's possible that in a future iteration, the useSchemasStore will be removed in favor of a react provider, to handle schemas easier in consumers, like the VSCode extension.

Comment on lines +6 to +55
/**
* Get the language catalog map from the Camel catalog. Since "language" language is not in the languages Camel
* catalog, it is extracted from the YAML DSL schema.
* @param yamlDslSchema
*/
static getLanguageMap(yamlDslSchema: Record<string, unknown>): Record<string, ICamelLanguageDefinition> {
const catalog = { ...CamelCatalogService.getLanguageMap() };

// "language" for custom language is not in the Camel catalog. Create from YAML DSL schema and Add here.
const customDefinition = ExpressionService.createCustomLanguageDefinition(yamlDslSchema);
if (customDefinition) {
catalog['language'] = customDefinition;
}

// "file" language is merged with "simple" language and it doesn't exist in YAML DSL schema. Remove it here.
delete catalog['file'];

return catalog;
}

private static createCustomLanguageDefinition(yamlDslSchema: Record<string, unknown>) {
const definitions = (yamlDslSchema.items as Record<string, unknown>)?.definitions as Record<string, unknown>;
const customLanguageSchema =
definitions && (definitions['org.apache.camel.model.language.LanguageExpression'] as Record<string, unknown>);
if (!customLanguageSchema) return;

const properties = Object.entries(customLanguageSchema.properties as Record<string, unknown>).reduce(
(acc, [key, value]) => {
acc[key] = {
index: Object.keys(acc).length,
required: (customLanguageSchema.required as string[]).includes(key),
...(value as Record<string, unknown>),
} as ICamelLanguageProperty;
return acc;
},
{} as Record<string, ICamelLanguageProperty>,
);
return {
language: {
kind: CatalogKind.Language,
name: 'language',
title: customLanguageSchema.title,
description: customLanguageSchema.description,
deprecated: false,
modelName: 'language',
} as ICamelLanguageModel,
properties: properties,
} as ICamelLanguageDefinition;
}

Copy link
Member

Choose a reason for hiding this comment

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

[curious-question]: Does this process mutate over time? If not, wouldn't be preferable to run it just once at boot time instead? Perhaps around when we build the catalogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a plan, filed an issue - #316

Comment on lines +120 to +128
/**
* Set the expression model to the parent step model object. This method uses the most verbose dialect, i.e.
* ```yaml
* - setBody:
* expression:
* simple:
* expression: ${body}
* trim: true
* ```
Copy link
Member

Choose a reason for hiding this comment

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

This is great, thanks for providing the example

Copy link
Member

Choose a reason for hiding this comment

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

mmm, could be possible to point also in the example, what the params represent based on the YAML example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean we want an explanation for e.g. trim parameter in this comment?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, no, I meant the function parameters.

@param parentModel
@param languageModelName
@param newExpressionModel

For instance, are those parameters related to the YAML example? do they correspond to a particular field? if that's the case, can we point out which ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh OK, that makes sense, I'll follow up

@lordrip
Copy link
Member

lordrip commented Nov 10, 2023

I would like to know your opinion about the following image:
image

  1. Is it necessary for the expression field to be expandable? It feels a bit different than the rest of the form.
  2. Given that we're offering the id field as well, should we also provide a default ID as well, as we do for other nodes?

@lordrip
Copy link
Member

lordrip commented Nov 10, 2023

Another thing that I noticed, if you start with the default route

- route:
    from:
      uri: timer:template
      parameters:
        period: "1000"
      steps:
        - log:
            message: template message
    id: route-1073

notice how the log processor doesn't have an expression property defined, then you open the log processor to configure it, there's no expression field either
image

but returning to the source code, it looks like an expression property gets added 🤔

have you seen that in the past?

@igarashitm
Copy link
Contributor Author

igarashitm commented Nov 10, 2023

I would like to know your opinion about the following image: image

  1. Is it necessary for the expression field to be expandable? It feels a bit different than the rest of the form.

I would think so, since some of the language have many parameters and push step parameters out of the screen.
I agree that the styling for this expression editor looks different from the rest of the form, it's better to align at some point

  1. Given that we're offering the id field as well, should we also provide a default ID as well, as we do for other nodes?

Filed an issue - #317

@igarashitm
Copy link
Contributor Author

notice how the log processor doesn't have an expression property defined, then you open the log processor to configure it, there's no expression field either image

but returning to the source code, it looks like an expression property gets added 🤔

have you seen that in the past?

Since log step doesn't have expression parameter, it shouldn't be added, can you file a bug issue and assign it to me?

@lordrip
Copy link
Member

lordrip commented Nov 10, 2023

I filed an issue for the expression field that sometimes is added unintentionally (at least I think unintentionally): #319, it doesn't happen always and I haven't found a reliable to reproduce it.

@lordrip
Copy link
Member

lordrip commented Nov 10, 2023

Considering that we have all the feedback in dedicated issues, I'm gonna merge this PR 🎉 , thanks once again Tomo

@lordrip lordrip merged commit 0711250 into KaotoIO:main Nov 10, 2023
10 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.

Support configuring expression in Canvas form
2 participants