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

[NU-7164] Add basic parser for fragment input definitions #7167

Merged

Conversation

DeamonDev
Copy link
Contributor

@DeamonDev DeamonDev commented Nov 19, 2024

Describe your changes

Checklist before merge

  • Related issue ID is placed at the beginning of PR title in [brackets] (can be GH issue or Nu Jira issue)
  • Code is cleaned from temporary changes and commented out lines
  • Parts of the code that are not easy to understand are documented in the code
  • Changes are covered by automated tests
  • Showcase in dev-application.conf added to demonstrate the feature
  • Documentation added or updated
  • Added entry in Changelog.md describing the change from the perspective of a public distribution user
  • Added MigrationGuide.md entry in the appropriate subcategory if introducing a breaking change
  • Verify that PR will be squashed during merge

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced FragmentParameterTypingParser for enhanced parsing of class names into typing results.
    • Added useTableEditorTypeOptions for dynamic type management in the Table component.
  • Improvements

    • Enhanced validation logic for fragment parameters and outputs in the NodeCompiler.
    • Improved error handling and reporting in various components, including the ProcessValidator.
    • Updated the FragmentParametersDefinitionExtractor to utilize class definitions for more robust parameter validation.
    • Modified the Table component to integrate updated type options for better data management.
  • Bug Fixes

    • Refined handling of empty fragments in definitions and ensured correct output parameters in fragment definitions.
  • Tests

    • Expanded test coverage for parameter configurations, fragment handling, and component group management.
    • Enhanced tests for the DefinitionsService to validate scenario properties and component group management.

Copy link

coderabbitai bot commented Nov 19, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce modifications to various components, primarily enhancing the handling of class definitions and validation processes. Key updates include the renaming of the useTypeOptions function to useFragmentInputDefinitionTypeOptions and the adjustment of its logic to derive the value property from type.display. Additionally, the FragmentComponentDefinitionExtractor constructor is updated to include new parameters for class definitions, improving the extraction and validation of fragment parameters. Several tests are added or modified to enhance coverage, particularly around component group management and fragment handling. Overall, the changes refine error handling and validation logic across the system.

Changes

File Change Summary
designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx Renamed useTypeOptions to useFragmentInputDefinitionTypeOptions and updated its logic for deriving values.
designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala Updated constructor of FragmentComponentDefinitionExtractor to include additional class definitions parameter.
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala Enhanced test coverage with new tests for parameter configurations and fragment handling.
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala Modified FragmentComponentDefinitionExtractor instantiation to include an empty set for fragment definitions.
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala Updated tests for ComponentGroupsPreparer with new parameters for fragment handling.
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala Adjusted FragmentComponentDefinitionExtractor instantiation to accept an empty set for fragments.
engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala Modified definitions and adjustDefinitions methods to accept additional class definitions parameter.
engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala Updated adjustDefinitions method to include class definitions parameter.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala Enhanced FragmentParametersDefinitionExtractor instantiation with class definitions parameter.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala Updated FragmentParametersDefinitionExtractor constructor call with class definitions parameter.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala Introduced FragmentParameterValidator class and modified validation methods for improved type handling.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala Refactored to use fragmentParameterValidator instance for validation logic.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala Enhanced validation logic for fragment inputs and outputs, improving error handling.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala Updated constructor to accept class definitions, modifying parameter extraction logic.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala Introduced FragmentParameterTypingParser for parsing class names into typing results.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala Updated constructor to include class definitions and modified validation methods for enhanced type handling.
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala Modified constructor to include class definitions for fragment parameters.
scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala Changed test instantiation of FragmentParameterValidator to use an instance instead of static calls.
utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala Updated adjustDefinitions method to accept class definitions parameter.

Possibly related PRs

Suggested labels

docs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added client client main fe ui labels Nov 19, 2024
@DeamonDev DeamonDev linked an issue Nov 19, 2024 that may be closed by this pull request
@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch 3 times, most recently from 204fd64 to 360f0ab Compare November 19, 2024 11:04
Copy link
Contributor

github-actions bot commented Nov 19, 2024

created: #7197
⚠️ Be careful! Snapshot changes are not necessarily the cause of the error. Check the logs.

@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch 2 times, most recently from a2ea8eb to 455f826 Compare November 20, 2024 09:46
@DeamonDev DeamonDev marked this pull request as ready for review November 20, 2024 12:02
@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch from 455f826 to 9034882 Compare November 20, 2024 12:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (11)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (1)

Line range hint 18-25: Consider adding ScalaDoc for the class

Given that this class now handles class definitions as part of fragment component extraction, it would be helpful to add ScalaDoc documentation explaining:

  • The purpose of the classDefinitions parameter
  • How class definitions are used in fragment parameter validation
  • Any requirements or constraints for the provided class definitions
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1)

25-25: Consider adding test coverage for non-empty classDefinitions

Since FragmentComponentDefinitionExtractor now supports class definitions, it would be valuable to add test cases that verify the behavior with non-empty class definitions to ensure complete coverage of the new functionality.

designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (1)

38-64: Document the type option format change

Given this change modifies how type values are represented, please ensure:

  1. The change is documented in the changelog
  2. If this is a breaking change, update the migration guide
  3. Add code comments explaining why useTypeOptionsV2 uses display instead of refClazzName
scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (1)

Line range hint 1-89: Consider adding tests for ClassDefinition parameter.

Since the AI summary mentions that FragmentParameterValidator now accepts a set of ClassDefinition as a parameter, consider adding test cases that verify the validation behavior with different ClassDefinition scenarios.

engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (1)

140-151: Consider documenting the definition adjustment process

Given that this is core compilation infrastructure, consider:

  1. Adding code comments explaining the role of class definitions in the adjustment process
  2. Documenting any performance implications of passing the full class definition set
  3. Adding examples of typical adjustments in the documentation
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (1)

Line range hint 169-210: LGTM! Clean refactoring of validation calls.

The validation logic has been cleanly refactored to use the new fragmentParameterValidator instance while maintaining the same functionality. The error handling and validation context management remain robust.

Consider extracting the validation chain into a private method for improved readability:

+ private def validateFragmentInput(
+   fragmentInputDefinition: FragmentInputDefinition,
+   parameterDefinitions: Writer[List[PartSubGraphCompilationError], List[Parameter]],
+   validationContext: ValidationContext
+ )(implicit nodeId: NodeId) = {
+   val parameterNameValidation = fragmentParameterValidator.validateParameterNames(parameterDefinitions.value)
+   val fixedValuesErrors = fragmentInputDefinition.parameters
+     .map(fragmentParameterValidator.validateFixedExpressionValues(_, validationContext, expressionCompiler))
+     .sequence
+     .map(_ => ())
+   val dictValueEditorErrors = fragmentInputDefinition.parameters
+     .map(fragmentParameterValidator.validateValueInputWithDictEditor(_, expressionConfig.dictionaries, classLoader))
+     .sequence
+     .map(_ => ())
+   parameterNameValidation |+| fixedValuesErrors |+| dictValueEditorErrors
+ }
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1)

12-15: Offer assistance in implementing an AST-based parser for arbitrary depth expressions

The TODO comment indicates that the current parser using regexes is insufficient for handling arbitrary depth expressions in type parsing. I can assist in developing a recursive parser that constructs an Abstract Syntax Tree (AST) to accurately parse complex and nested type expressions.

Would you like me to help implement this parser or open a new GitHub issue to track this enhancement?

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (1)

39-44: Enhanced flexibility with classDefinitions parameter

Introducing classDefinitions as a constructor parameter with a default value allows the extractor to utilize provided class definitions, increasing flexibility and robustness. The initialization of fragmentParameterTypingParser with classLoader and classDefinitions ensures proper parsing capabilities.

Consider adding unit tests for new functionality

To ensure the robustness of the newly introduced classDefinitions parameter and fragmentParameterTypingParser, consider adding unit tests to cover these changes, especially to verify parsing logic and error handling.

Would you like assistance in creating the unit tests for these additions?

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (2)

Line range hint 23-23: Address the TODO comment to remove ValidationNotPerformed

The comment // TODO: Remove ValidationNotPerformed indicates an intention to refactor or eliminate the ValidationNotPerformed case object. Consider addressing this TODO by removing ValidationNotPerformed and updating the code to handle all validation scenarios appropriately without it.

Would you like assistance in refactoring the code to remove ValidationNotPerformed?


Line range hint 75-107: Consider refactoring the validateFragment method for improved readability

The validateFragment method contains nested validations and complex error handling, which can make it harder to read and maintain. Refactoring parts of this method into smaller, well-named helper functions could enhance readability and modularity.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (1)

160-164: Enhance error handling for type parsing failures

In the validateValueInputWithDictEditor method, when parsing the class name to a typing result, .getOrElse(Unknown) is used. While this prevents exceptions, it may conceal underlying issues if the class name is invalid or cannot be parsed. Consider handling parsing failures explicitly by logging an error or returning a validation error to make debugging easier and maintain strict type safety.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14a9a75 and 9034882.

📒 Files selected for processing (19)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (1 hunks)
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (3 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (5 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (4 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (2 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (6 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1 hunks)
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4 hunks)
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2 hunks)
🔇 Additional comments (34)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (3)

13-13: LGTM: Import addition is appropriate

The addition of ClassDefinition import is necessary to support the new class definitions parameter.


22-22: LGTM: Constructor parameter addition is well-designed

The new classDefinitions parameter is appropriately added with a specific type Set[ClassDefinition]. This aligns with the PR's objective of enhancing fragment input definition parsing.


27-27: LGTM: Parameters extractor initialization updated correctly

The parametersExtractor initialization properly passes both the classLoader and classDefinitions to the new constructor signature.

Please ensure that all callers of FragmentComponentDefinitionExtractor are updated to provide the required classDefinitions parameter.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1)

25-25: Verify if Set.empty is the appropriate default for classDefinitions

The change adapts to the new FragmentComponentDefinitionExtractor API by passing Set.empty. While this works for the current test case, please verify that not providing any class definitions is the intended behavior here.

designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (2)

62-62: LGTM: Class definitions parameter addition

The addition of class definitions to FragmentComponentDefinitionExtractor is a logical enhancement that will enable proper type handling for fragment input definitions.


Line range hint 44-45: Verify if nested fragments support is in scope

There's a TODO comment about fragment nesting support. Given that this PR introduces fragment input parsing capabilities, should nested fragment support be addressed as part of this work or tracked separately?

Would you like me to create a separate issue to track the nested fragments support?

designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (2)

44-44: Add validation for type.display property

The code assumes type.display always exists. Consider adding validation or a fallback value.

-                value: type.display,
+                value: type.display ?? type.refClazzName,

64-64: Verify compatibility with existing consumers

The switch from useTypeOptions to useTypeOptionsV2 changes the value format from refClazzName to display. Please ensure all consumers of these values (e.g., getDefaultFields, field processors) can handle the new format correctly.

scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4)

Line range hint 26-33: LGTM! Verify test coverage remains unchanged.

The change from static to instance method call is implemented correctly. The test logic remains intact, maintaining the same validation behavior.


Line range hint 42-49: LGTM! Consistent with the pattern.

The instantiation follows the same pattern as other test cases, maintaining consistency throughout the test suite.


Line range hint 58-65: LGTM! Error case handling preserved.

The change maintains the same error validation logic while adopting the new instantiation pattern.


Line range hint 74-84: LGTM! Fixed values validation preserved.

The modification correctly implements the instance-based approach while preserving the fixed values validation logic.

utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2)

11-11: LGTM: Import addition aligns with new functionality

The addition of ClassDefinition import is consistent with the PR's objective of implementing fragment input definition parsing.


65-66: Verify integration with test scenarios

The addition of classDefinitions parameter to adjustDefinitions looks correct. However, since this is in a test utility class, please ensure that:

  1. All test scenarios are updated to provide appropriate ClassDefinition sets
  2. Edge cases (empty set, null) are properly handled
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1)

56-56: LGTM! Verify integration with fragment validation.

The addition of definitionWithTypes.classDefinitions.all to FragmentParametersDefinitionExtractor aligns with the PR's objective of enhancing fragment input definitions parsing.

Please ensure that:

  • The fragment validation logic correctly utilizes these class definitions
  • The changes are covered by integration tests that verify the complete fragment parameter validation flow
engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2)

12-12: LGTM: Import addition is consistent with usage

The addition of ClassDefinition import alongside ClassDefinitionSet aligns with the new parameter requirements.


140-144: Verify impact on definition adjustment logic

The addition of class definitions to adjustDefinitions expands its context. While the change is structurally sound, please ensure:

  1. All subclasses properly handle the new parameter
  2. The default implementation in this class (returning originalModelDefinition) remains valid with the additional parameter
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1)

27-30: LGTM! Verify test data generation with class definitions.

The addition of class definitions to FragmentParametersDefinitionExtractor aligns well with the PR's objective of enhancing fragment input definition parsing. The implementation maintains type safety and follows Scala best practices.

Please ensure that test data generation works correctly with various class definitions, particularly for complex fragment input scenarios.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

193-193: Consider adding test cases for non-empty class definitions.

While passing Set.empty works, it might not thoroughly test the new class definitions functionality for fragment components. Consider:

  1. Adding test cases with non-empty class definitions to validate the complete feature.
  2. Adding a comment explaining why an empty set is acceptable here if this is intentional.
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1)

299-299: LGTM! Consider adding edge cases for class definitions.

The addition of model.modelDefinitionWithClasses.classDefinitions.all aligns with the broader changes to enhance fragment handling with class definitions. Consider adding test cases that verify behavior with:

  • Empty class definitions
  • Complex nested class hierarchies
  • Invalid/malformed class definitions
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1)

355-357: Verify fragment parameter handling with invalid class definitions.

The addition of classDefinitions to FragmentParametersDefinitionExtractor enhances type handling for fragment parameters. However, since this is in the critical validation path, please ensure:

  1. The extractor properly handles cases where class definitions are invalid or incomplete
  2. Error messages are clear and helpful when class resolution fails
  3. Existing fragment parameters continue to work as expected with this change

Consider adding validation tests that cover edge cases such as:

  • Missing class definitions
  • Invalid class definitions
  • Complex nested class hierarchies
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1)

179-179: LGTM! Consider adding test cases for non-empty classDefinitions.

The change correctly adapts to the new FragmentComponentDefinitionExtractor constructor signature. However, the current test only covers the empty set case for classDefinitions. Consider adding test cases with non-empty class definitions to ensure complete coverage of the new functionality.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (1)

102-103: LGTM! Clean initialization of the validator.

The initialization of fragmentParameterValidator with class definitions from the extractor is well-structured and follows good practices.

engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (2)

13-13: Import statement added correctly

The import of ClassDefinition is necessary for the added classDefinitions parameter and is appropriately included.


66-67: Verify constructor argument order for FragmentParametersDefinitionExtractor

Confirm that the parameters definitionContext.userCodeClassLoader and classDefinitions are passed in the correct order as per the constructor's definition to ensure proper initialization.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (5)

8-8: Added necessary import for ClassUtils

The addition of org.apache.commons.lang3.ClassUtils import is appropriate for class manipulation utilities.


17-17: Imported ClassDefinition and ClassDefinitionSet

Including ClassDefinition and ClassDefinitionSet is necessary for handling class definitions within the extractor.


33-34: Included Try import

Adding scala.util.Try prepares the codebase for potential exception handling where parsing or class loading might fail.


Line range hint 85-92: Improved validation using classDefinitions in FragmentParameterValidator

Passing classDefinitions to FragmentParameterValidator enhances parameter validation by allowing checks against provided class definitions, ensuring that parameters conform to expected class structures.


Line range hint 145-156: Verify the handling of unknown class names

When parseClassNameToTypingResult fails, returning an Unknown typing result and logging an error may impact downstream type checking. Please verify that this behavior appropriately handles cases where class names cannot be resolved, and consider if more specific error handling or user feedback is warranted to prevent silent failures.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (2)

48-51: Verify the impact of the new parameter in FragmentParametersDefinitionExtractor

The constructor of FragmentParametersDefinitionExtractor now includes classDefinitions.all as an additional parameter. Please ensure that:

  • All instances where FragmentParametersDefinitionExtractor is instantiated are updated with this new parameter.
  • Dependent components or classes correctly handle the updated constructor.
  • There are no unintended side effects due to this change, especially in serialization or reflective operations.

Line range hint 75-107: Ensure unit tests cover the updated validation logic in validateFragment

With the changes to the validateFragment method, please verify that unit tests are updated or added to cover the new validation logic, especially concerning fragment outputs and parameter handling. This will help ensure that the method behaves as expected under various scenarios.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (2)

48-49: Verify the default initialization of classDefinitions

The FragmentParameterValidator is now a case class with classDefinitions defaulting to an empty set. Ensure that when an instance is created, especially outside of tests, classDefinitions is populated appropriately. An empty set might lead to incomplete type parsing in methods like validateValueInputWithDictEditor, potentially causing validation issues.


Line range hint 6-23: Approved: Necessary imports added

The additional import statements for ClassUtils, TypingResult, ClassDefinition, and FragmentParameterTypingParser are appropriate and required for the new functionality introduced. They integrate well with the existing codebase.

@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch from 9034882 to fe7d67c Compare November 20, 2024 12:24
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (1)

48-49: Consider adding ScalaDoc for better documentation.

The case class design is good, encapsulating validation logic with backward compatibility. Consider adding ScalaDoc to document the purpose and usage of the class.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

193-193: Document the purpose of the empty set parameter.

The addition of Set.empty as a parameter to FragmentComponentDefinitionExtractor aligns with the PR objectives for fragment input definitions handling. However, consider adding a brief comment explaining what this parameter represents and why an empty set is appropriate in the test context.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1)

Line range hint 1-350: Add test coverage for fragment input definition parsing

Given that this PR introduces a basic parser for fragment input definitions, consider adding the following test cases:

  1. Basic fragment input definition parsing
  2. Complex input definition scenarios
  3. Error cases for malformed input definitions
  4. Edge cases (empty inputs, special characters, etc.)

This would ensure the new parser functionality is thoroughly tested.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9034882 and fe7d67c.

📒 Files selected for processing (19)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (2 hunks)
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (3 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (5 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (4 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (2 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (6 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1 hunks)
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4 hunks)
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (15)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala
🧰 Additional context used
📓 Learnings (1)
engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (1)
Learnt from: DeamonDev
PR: TouK/nussknacker#7167
File: engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala:150-151
Timestamp: 2024-11-20T12:19:55.759Z
Learning: In the Nussknacker project, the method `adjustDefinitions` in `FlinkProcessCompilerDataFactory.scala` has only one usage, allowing its signature to be changed without affecting backward compatibility.
🔇 Additional comments (8)
engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (3)

12-12: LGTM: Import addition is appropriate

The added import for ClassDefinition types is necessary for the new parameter types and follows Scala conventions.


140-144: LGTM: Proper passing of class definitions

The addition of classDefinitions.all as an argument to adjustDefinitions is consistent with the signature change and provides the complete set of class definitions needed for adjustment.


150-151: LGTM: Method signature enhancement

The addition of the classDefinitions parameter enhances the method's capability to work with class definitions during the adjustment process.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (4)

6-6: LGTM! Well-organized imports and clear type constraints.

The new imports are logically grouped and the permittedTypesForEditors constant provides a clear contract for supported editor types.

Also applies to: 18-18, 21-23


Line range hint 71-84: LGTM! Clear validation logic with descriptive error messages.

The type validation is well-implemented with clear error messages and effective pattern matching.


160-164: Consider enhancing error handling for typing parser.

While the typing parser implementation is good, consider handling parsing failures more explicitly instead of falling back to Unknown. This could help catch configuration issues earlier in the development cycle.

-              val fragmentParameterTypingResult = fragmentParameterTypingParser
-                .parseClassNameToTypingResult(
-                  fragmentParameter.typ.refClazzName
-                )
-                .getOrElse(Unknown)
+              val fragmentParameterTypingResult = fragmentParameterTypingParser
+                .parseClassNameToTypingResult(fragmentParameter.typ.refClazzName) match {
+                  case Some(result) => result
+                  case None =>
+                    return invalidNel(InvalidFragmentParameterType(
+                      fragmentParameter.typ.refClazzName,
+                      nodeId.id,
+                      fragmentParameter.name
+                    ))
+                }

Line range hint 48-164: Verify test coverage for new validation logic.

The changes introduce significant enhancements to type validation. Please ensure comprehensive test coverage for:

  • Different class definition scenarios
  • Edge cases in type parsing
  • Dictionary value type validation
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1)

299-299: Consider adding tests for class definition validation scenarios

The addition of class definitions to FragmentComponentDefinitionExtractor suggests that fragment validation now depends on these definitions. Consider adding test cases to verify:

  • Fragment validation with empty class definitions
  • Fragment validation with invalid class definitions
  • Fragment validation with complex class hierarchies

@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch from fe7d67c to d70db87 Compare November 20, 2024 12:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (3)

48-49: Consider making classDefinitions parameter required.

While providing a default empty Set maintains backward compatibility, it might mask potential issues where class definitions should be provided. Consider making this parameter required to ensure proper validation context is always provided.


Line range hint 166-176: Consider enhancing error messages for better debugging.

While the type compatibility check is correct, consider enhancing the error message in DictIsOfInvalidType to include:

  • Expected vs actual type format examples
  • Suggestion for how to fix the type mismatch

160-164: Consider caching parsed typing results.

The FragmentParameterTypingParser is created and used for each validation. Consider caching the parsed results for frequently used class names to improve performance, especially when dealing with multiple validations.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

193-193: Consider adding test cases for non-empty class definitions.

The addition of Set.empty as the classDefinitions parameter aligns with the broader changes for fragment handling. However, since this test file focuses on component group preparation, it would be valuable to add test cases that verify behavior with non-empty class definitions to ensure comprehensive coverage.

designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (1)

Line range hint 516-516: Implement the TODO for isSwitchableTo method

The isSwitchableTo method currently returns true without any implementation. This could lead to incorrect switching behavior in the editor.

Would you like me to help implement proper switching logic based on the expression schema validation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fe7d67c and d70db87.

📒 Files selected for processing (20)
  • designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (1 hunks)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (2 hunks)
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (3 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (5 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (4 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (2 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (6 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1 hunks)
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4 hunks)
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala
🔇 Additional comments (5)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (2)

6-6: LGTM! Well-structured imports and constants.

The new imports and the permittedTypesForEditors constant are well-organized and provide a clear contract for supported types.

Also applies to: 18-18, 21-23


160-164: LGTM! Robust type parsing implementation.

The introduction of FragmentParameterTypingParser improves type safety and validation. The parsing logic is well-structured and handles the type resolution appropriately.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1)

355-355: Breaking change: FragmentParametersDefinitionExtractor constructor modification

The addition of classDefinitions.all parameter to FragmentParametersDefinitionExtractor looks good and aligns with the PR objective of enhancing fragment input definitions parsing. However, this is a breaking change that modifies a constructor signature.

Please ensure that:

  1. All existing instantiations of FragmentParametersDefinitionExtractor are updated
  2. The breaking change is documented in _MigrationGuide.md as mentioned in the PR checklist
  3. Test coverage exists for the new parameter validation functionality
designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (2)

100-101: Verify type options behavior with new parameter

The addition of false parameter to useTypeOptions hook affects how type options are filtered and displayed in the table editor. This change is part of a broader standardization of type options handling across components.

Please ensure that:

  1. The table editor correctly displays and filters type options with the new parameter
  2. The behavior aligns with the fragment input definition component where useTypeOptions(true) is used

The type filtering logic in the following line looks correct, properly integrating with the modified hook:

const supportedTypes = useMemo(() => orderedTypeOptions.filter(({ value }) => SUPPORTED_TYPES.includes(value)), [orderedTypeOptions]);

Line range hint 513-515: LGTM: Robust error handling implementation

The error handling and validation implementation is well-structured:

  • Proper integration of validation labels
  • Conditional rendering based on showValidation prop
  • Clear error messages using i18next for internationalization

Also applies to: 468-469

@DeamonDev DeamonDev self-assigned this Nov 20, 2024
@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch from d70db87 to 50c1207 Compare November 21, 2024 11:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (2)

Line range hint 39-46: Consider expanding permitted types and adding documentation.

While the current set of permitted types covers basic scenarios, consider:

  1. Adding documentation explaining why these specific types are permitted
  2. Including other common types like Integer, Float, Double if they should be supported
  3. Adding scaladoc to explain the purpose and usage of this constant
 object FragmentParameterValidator {
 
+  /** List of permitted types that can be used with editors in fragment parameters.
+   * These types are validated during fragment parameter compilation.
+   */
   val permittedTypesForEditors: List[FragmentClazzRef] = List(
     FragmentClazzRef[java.lang.Boolean],
     FragmentClazzRef[String],
-    FragmentClazzRef[java.lang.Long]
+    FragmentClazzRef[java.lang.Long],
+    FragmentClazzRef[java.lang.Integer],
+    FragmentClazzRef[java.lang.Float],
+    FragmentClazzRef[java.lang.Double]
   )

48-49: Consider making classDefinitions required or documenting the implications.

The empty Set default for classDefinitions might silently ignore validation in some cases. Consider:

  1. Making it a required parameter to ensure explicit handling
  2. Adding documentation about the implications of an empty Set
  3. Adding runtime validation when the Set is empty but required for validation
-case class FragmentParameterValidator(classDefinitions: Set[ClassDefinition] = Set.empty) {
+/** Validates fragment parameters against their type definitions and constraints.
+ * @param classDefinitions Set of class definitions used for type validation.
+ *                        An empty set will limit type validation capabilities.
+ */
+case class FragmentParameterValidator(classDefinitions: Set[ClassDefinition]) {
+  require(classDefinitions.nonEmpty, "ClassDefinitions are required for proper type validation")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d70db87 and 50c1207.

📒 Files selected for processing (20)
  • designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (3 hunks)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (2 hunks)
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (3 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (5 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (4 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (2 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (6 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1 hunks)
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4 hunks)
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (17)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala
🔇 Additional comments (5)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (2)

6-6: LGTM: New imports are properly organized.

The added imports support the new functionality for class definition handling and typing.

Also applies to: 18-18, 21-23


Line range hint 1-214: Verify usage patterns of FragmentParameterValidator.

Let's verify how this validator is used across the codebase to ensure proper initialization with class definitions.

✅ Verification successful

Let me gather more context about the actual usage of the validator in production code.


Based on the gathered information, I can now generate the final response:

FragmentParameterValidator is properly initialized with class definitions.

The validator is correctly used across the codebase:

  • In NodeCompiler, it's initialized with class definitions from FragmentDefinitionExtractor: fragmentParameterValidator = FragmentParameterValidator(fragmentDefinitionExtractor.classDefinitions)
  • The validator is used for validating fragment parameters, dictionary editors, and fixed expression values in a consistent way
  • All validation methods are invoked with proper context and required dependencies
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for FragmentParameterValidator instantiations
rg "new FragmentParameterValidator" -A 2

# Search for potential validation calls
rg "validateValueInputWithDictEditor|validateAgainstClazzRefAndGetEditor" -A 2

Length of output: 4898


Script:

#!/bin/bash
# Search for FragmentParameterValidator instantiations in non-test code
rg "new FragmentParameterValidator" --type scala --glob '!**/test/**'

# Search for where classDefinitions are used/passed
rg "classDefinitions.*FragmentParameterValidator" --type scala

# Look for NodeCompiler initialization to see how fragmentParameterValidator is created
ast-grep --pattern 'class NodeCompiler($$$) {
  $$$
}'

Length of output: 95900

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

193-193: Consider enhancing test coverage for fragment input definitions with class definitions.

While using Set.empty works for the current test cases that verify basic fragment component behavior, it might not provide sufficient coverage for the new fragment input definition parsing feature. Consider:

  1. Adding test cases that verify fragment input definitions with various class definitions
  2. Adding a comment explaining why an empty set is sufficient for the existing test cases

Let's verify if there are any existing tests for fragment input definitions with class definitions:

✅ Verification successful

Empty class definitions set is appropriate for these tests

The empty set for classDefinitions in ComponentGroupsPreparerSpec.scala is appropriate because:

  1. The test file focuses on verifying component group preparation and alignment, not fragment parameter validation
  2. The actual fragment parameter validation and class definition handling is tested in dedicated test files:
    • FragmentParameterValidatorTest.scala
    • FragmentParametersDefinitionExtractor.scala

No changes are needed as the current test coverage for fragment class definitions is properly handled in the appropriate test files, and this specific test file's scope is limited to component group behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests related to fragment input definitions and class definitions
rg -l "FragmentInputDefinition.*ClassDefinition" --type scala

Length of output: 63


Script:

#!/bin/bash
# Let's first find files related to fragment input definitions
rg -l "FragmentInputDefinition" --type scala

# Then search for test files containing "fragment" and "class"
rg -l "class.*fragment|fragment.*class" --type scala --glob "*Test*.scala" --glob "*Spec*.scala"

# Also search for the FragmentComponentDefinitionExtractor usage
rg "FragmentComponentDefinitionExtractor" --type scala -C 3

Length of output: 18712


Script:

#!/bin/bash
# Let's check the FragmentParameterValidatorTest for insights on class definitions
rg -A 10 "class FragmentParameterValidatorTest" scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala

# Also check the actual implementation of FragmentComponentDefinitionExtractor
rg -A 10 "class FragmentComponentDefinitionExtractor" scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala

# And look for any tests using classDefinitions with fragments
rg "classDefinitions.*fragment|fragment.*classDefinitions" --type scala

Length of output: 2147

designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (2)

34-37: LGTM: Imports are well-organized and necessary.

The new imports are properly structured and essential for the new hook implementation.


125-126: 🛠️ Refactor suggestion

Add defensive programming for defaultTypeOption.

The code should handle the case when defaultTypeOption is null, which could happen if the process definition data is not available.

Let's verify the usage of defaultTypeOption in the codebase:

Consider adding null checks:

-    const { defaultTypeOption, orderedTypeOptions } = useTableEditorTypeOptions();
-    const supportedTypes = useMemo(() => orderedTypeOptions.filter(({ value }) => SUPPORTED_TYPES.includes(value)), [orderedTypeOptions]);
+    const { defaultTypeOption, orderedTypeOptions } = useTableEditorTypeOptions();
+    if (!defaultTypeOption) {
+        // Handle the case when no type options are available
+        return <div>Loading type options...</div>;
+    }
+    const supportedTypes = useMemo(() => orderedTypeOptions.filter(({ value }) => SUPPORTED_TYPES.includes(value)), [orderedTypeOptions]);

@DeamonDev DeamonDev force-pushed the nu-7164-validate-fragment-input-params-on-backend branch from 50c1207 to 3c31755 Compare November 21, 2024 11:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (2)

84-86: Consider enhancing error logging for validation failures.

While the validation logic is solid, consider adding debug-level logging when validation fails to help with troubleshooting in production environments.

 FragmentParameterValidator(classDefinitions).validateAgainstClazzRefAndGetEditor(
   valueEditor = editor,
   initialValue = fragmentParameter.initialValue,
   refClazz = fragmentParameter.typ,
   paramName = fragmentParameter.name,
   nodeIds = Set(nodeId.id)
 ) match {
   case Valid(editor) => (Some(editor), List.empty)
-  case Invalid(e)    => (None, e.toList)
+  case Invalid(e)    =>
+    logger.debug(s"Validation failed for parameter ${fragmentParameter.name}: ${e.toList.mkString(", ")}")
+    (None, e.toList)
 }

41-41: Consider making classDefinitions a required parameter.

While providing a default empty Set for classDefinitions maintains backward compatibility, it might mask configuration errors where class definitions should have been provided but weren't. Consider making this a required parameter in a future major version update.

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (2)

Line range hint 40-44: Document the rationale for permitted types.

Consider adding documentation explaining why only these specific types are permitted for editors. This will help future maintainers understand the constraints and make informed decisions when modifying the list.

 object FragmentParameterValidator {
 
+  /**
+   * List of types that are supported by parameter editors.
+   * These types are chosen because:
+   * - They represent common primitive types
+   * - They have well-defined string representations
+   * - They are commonly used in fragment parameters
+   */
   val permittedTypesForEditors: List[FragmentClazzRef] = List(
     FragmentClazzRef[java.lang.Boolean],
     FragmentClazzRef[String],
     FragmentClazzRef[java.lang.Long]
   )

48-49: Add class documentation.

The case class would benefit from documentation explaining its purpose and the role of classDefinitions. This helps users understand when and how to use this validator.

+/**
+ * Validates fragment parameters against their type definitions and editor constraints.
+ *
+ * @param classDefinitions Set of class definitions used for type resolution and validation.
+ *                        These definitions are used to parse and validate parameter types
+ *                        when working with dictionary editors and custom types.
+ */
 case class FragmentParameterValidator(classDefinitions: Set[ClassDefinition] = Set.empty) {
designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

Line range hint 141-175: Enhance fragment-related test coverage.

The existing fragment-related tests only verify basic functionality. Consider adding test cases that:

  1. Verify fragment input definition parsing with various class definitions
  2. Test error cases (invalid class definitions, malformed inputs)
  3. Test edge cases (empty class definitions, complex nested types)

Here's a suggested test structure:

test("validate fragment input definition with class definitions") {
  val classDefinitions = Set(
    // Add sample class definitions here
  )
  val model = getAlignedComponentsWithStaticDefinition(
    ModelDefinitionBuilder.empty.build,
    Map.empty,
    forFragment = true,
    classDefinitions = classDefinitions
  )
  val groups = ComponentGroupsPreparer.prepareComponentGroups(model)
  
  // Add assertions to verify:
  // 1. Fragment input definition components have correct parameters based on class definitions
  // 2. Type validation works correctly
  // 3. Error cases are handled properly
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 50c1207 and 3c31755.

📒 Files selected for processing (20)
  • designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (3 hunks)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx (2 hunks)
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1 hunks)
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala (1 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala (2 hunks)
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala (3 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (5 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala (4 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala (2 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala (1 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (6 hunks)
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala (1 hunks)
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala (4 hunks)
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (16)
  • designer/client/src/components/graph/node-modal/fragment-input-definition/FragmentInputDefinition.tsx
  • designer/server/src/main/scala/pl/touk/nussknacker/ui/definition/AlignedComponentsDefinitionProvider.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/DefinitionsServiceSpec.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/EdgeTypesPreparerTest.scala
  • designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentsUsageHelperTest.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/FlinkProcessCompilerDataFactory.scala
  • engine/flink/executor/src/main/scala/pl/touk/nussknacker/engine/process/compiler/StubbedFlinkProcessCompilerDataFactory.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/ProcessCompilerData.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeCompiler.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/NodeDataValidator.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentComponentDefinitionExtractor.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala
  • scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/test/ModelDataTestInfoProvider.scala
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidatorTest.scala
  • utils/flink-components-testkit/src/main/scala/pl/touk/nussknacker/engine/flink/util/test/FlinkProcessCompilerDataFactoryWithTestComponents.scala
🔇 Additional comments (7)
scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParametersDefinitionExtractor.scala (2)

39-44: LGTM! Well-structured constructor enhancement.

The addition of the optional classDefinitions parameter with a default empty Set maintains backward compatibility while enabling enhanced typing capabilities. The immediate initialization of fragmentParameterTypingParser ensures proper setup for parsing operations.


Line range hint 145-156: LGTM! Robust error handling in type parsing.

The refactored implementation properly handles parsing failures and provides clear error messages. The use of Writer monad for error accumulation is particularly elegant.

Let's verify that all fragment parameter types used in the codebase are properly handled:

✅ Verification successful

Based on the search results, I can now verify the implementation. The codebase shows that:

  1. The fragment parameter types are properly handled through FragmentParameterTypingParser which is used in the refactored code.
  2. The supported types are defined in FragmentParameterValidator.permittedTypesForEditors which includes Boolean, String, and Long.
  3. The error handling in the reviewed code correctly handles parsing failures by returning Unknown type with descriptive error messages.
  4. The implementation is used consistently across the codebase in fragment parameter validation and compilation.

LGTM! The type parsing implementation is robust and handles all supported fragment parameter types.

The error handling for unsupported types is particularly well done, providing clear error messages through FragmentParamClassLoadError.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all fragment parameter type definitions to ensure they're supported
ast-grep --pattern 'class $_ extends FragmentParameter {
  $$$
  val typ: $_ = $_
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Let's try a different approach to find fragment parameter type usages
rg -A 5 "FragmentParameter" --type scala

Length of output: 101782

scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/FragmentParameterValidator.scala (1)

160-164: Improve error handling in type resolution.

The current implementation silently falls back to Unknown when type parsing fails, which could mask potential issues. Consider:

  1. Adding logging when falling back to Unknown type
  2. Propagating parsing errors instead of using getOrElse(Unknown)
  3. Adding validation for the parsed typing result

This issue was previously raised in a past review. The suggestion remains valid and should be addressed.

designer/server/src/test/scala/pl/touk/nussknacker/ui/definition/component/ComponentGroupsPreparerSpec.scala (1)

193-193: ⚠️ Potential issue

Add test coverage for fragment input definitions with class definitions.

The empty set passed to FragmentComponentDefinitionExtractor doesn't test the new fragment input definition parsing functionality mentioned in the PR objectives. Consider adding test cases that:

  1. Pass non-empty class definitions to verify the parser's behavior
  2. Cover various scenarios of fragment input definitions

Let's verify if there are any existing tests for fragment input definitions:

designer/client/src/components/graph/node-modal/editors/expression/Table/TableEditor.tsx (3)

33-36: LGTM: Imports are well-organized and necessary.

The new imports support the implementation of the useTableEditorTypeOptions hook with Redux state management and utility functions.


93-112: 🛠️ Refactor suggestion

Enhance hook robustness and type safety.

The hook implementation could benefit from the following improvements:

-export function useTableEditorTypeOptions() {
+interface TypeOption {
+    value: SupportedType;
+    label: string;
+}
+
+interface TableEditorTypeOptions {
+    orderedTypeOptions: TypeOption[];
+    defaultTypeOption: TypeOption | null;
+}
+
+export function useTableEditorTypeOptions(): TableEditorTypeOptions {
     const definitionData = useSelector(getProcessDefinitionData);
+    
+    if (!definitionData?.classes) {
+        return {
+            orderedTypeOptions: [],
+            defaultTypeOption: null,
+        };
+    }
 
     const typeOptions = useMemo(
         () =>
-            definitionData?.classes?.map((type) => ({
+            definitionData.classes.map((type) => ({
                 value: type.refClazzName as SupportedType,
                 label: ProcessUtils.humanReadableType(type),
             })),
         [definitionData?.classes],
     );
 
     const orderedTypeOptions = useMemo(() => orderBy(typeOptions, (item) => [item.label, item.value], ["asc"]), [typeOptions]);
 
-    const defaultTypeOption = useMemo(() => find(typeOptions, { label: "String" }) || head(typeOptions), [typeOptions]);
+    const defaultTypeOption = useMemo(() => {
+        if (!typeOptions?.length) return null;
+        return find(typeOptions, { label: "String" }) || head(typeOptions);
+    }, [typeOptions]);
+
     return {
         orderedTypeOptions,
         defaultTypeOption,
     };
 }

Likely invalid or redundant comment.


Line range hint 93-124: Verify all usages of useTableEditorTypeOptions.

Please ensure that all other places where defaultTypeOption is used (e.g., onColumnAppend, pasteWithExpand) also handle the null case appropriately.

✅ Verification successful

defaultTypeOption is safely handled in all usages

The search results show that defaultTypeOption is used in two components:

  1. In TableEditor.tsx:

    • All usages access defaultTypeOption.value within callbacks that are dependent on defaultTypeOption in their dependency arrays
    • The value is guaranteed to be non-null as it's defined with a fallback: find(typeOptions, { label: "String" }) || head(typeOptions)
  2. In FragmentInputDefinition.tsx:

    • Similar safe implementation with the same fallback pattern
    • Used safely within the addField callback with proper dependency tracking
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of defaultTypeOption to ensure proper null checking
rg -A 5 "defaultTypeOption" --type ts --type tsx

Length of output: 76


Script:

#!/bin/bash
# Search for all usages of defaultTypeOption with proper file extension
rg "defaultTypeOption" -t typescript -t tsx -C 5

Length of output: 83


Script:

#!/bin/bash
# Search for all usages of defaultTypeOption without file type restrictions
rg "defaultTypeOption" -C 5

Length of output: 12825

Copy link
Contributor

@Dzuming Dzuming left a comment

Choose a reason for hiding this comment

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

FE part LGTM

@DeamonDev DeamonDev merged commit d5154a3 into staging Nov 21, 2024
16 of 18 checks passed
@DeamonDev DeamonDev deleted the nu-7164-validate-fragment-input-params-on-backend branch November 21, 2024 13:16
mslabek added a commit that referenced this pull request Nov 21, 2024
mslabek added a commit that referenced this pull request Nov 21, 2024
DeamonDev pushed a commit that referenced this pull request Nov 24, 2024
DeamonDev added a commit that referenced this pull request Nov 25, 2024
* Revert "Revert "[NU-7164] Add basic parser for fragment input definitions (#7167)" (#7202)"

This reverts commit 383b4d5.

* [NU-7164] Adjust fields parameter list

* Revert "[NU-7164] Adjust fields parameter list"

This reverts commit d4a7ccc.

* add dicts bugfix

* adjust type

* correct validation rules

---------

Co-authored-by: Piotr Rudnicki <[email protected]>
lciolecki pushed a commit that referenced this pull request Nov 29, 2024
lciolecki pushed a commit that referenced this pull request Nov 29, 2024
* Revert "Revert "[NU-7164] Add basic parser for fragment input definitions (#7167)" (#7202)"

This reverts commit 383b4d5.

* [NU-7164] Adjust fields parameter list

* Revert "[NU-7164] Adjust fields parameter list"

This reverts commit d4a7ccc.

* add dicts bugfix

* adjust type

* correct validation rules

---------

Co-authored-by: Piotr Rudnicki <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client main fe ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate and process fragment input parameters on backend
2 participants