Currently, there is a problem with nodes that utilize presets as sometimes labels are not present and are presented as null.
This happens when we want to use a component or fragment with presets, select some values for them and save the scenario.
If there were any errors during compilation of that node presets will have null labels.
This happens because ProcessDictSubstituor dynamically adds and removes presets' labels.
if (expr.language == Expression.Language.DictKeyWithLabel && !expr.expression.isBlank) {
if (isReverse)
addLabelToDictKeyExpression(process, expr, optionalExpressionTypingInfo, nodeExpressionId)
else
removeLabelFromDictKeyExpression(process, expr, nodeExpressionId) // no need to keep label in BE
To add labels at that level we need parameters' types which are assigned during compilation. Unfortunately when there is any custom validators error during node compilation we lose typing information.
in ExperssionCompiler.compileNodeParameters()
allCompiledParams contain the typing info and is of ValidatedNel type. When Validations.validateWithCustomValidators(allParams, paramValidatorsMap) is Invalid we get these errors without previous typing.
To solve this issue I introduced a change which will still pass typing info further even when there are some custom validator errors. Instead of using Validated which can represent two states: Valid and Invalid, I used Ior which lets us have 3 states: Left, Right and Both. First two are self-explanatory and Both can hold both failure and a success. This way we can preserve the typing info while also preserving errors from custom validation. After testing these changes locally, we preserve the typing info and have correct preset labels even when there were errors during compilation.
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
Describe your changes
Currently, there is a problem with nodes that utilize presets as sometimes labels are not present and are presented as
null
. This happens when we want to use a component or fragment with presets, select some values for them and save the scenario. If there were any errors during compilation of that node presets will have null labels.This happens because
ProcessDictSubstituor
dynamically adds and removes presets' labels.To add labels at that level we need parameters' types which are assigned during compilation. Unfortunately when there is any custom validators error during node compilation we lose typing information. in
ExperssionCompiler.compileNodeParameters()
allCompiledParams contain the typing info and is of
ValidatedNel
type. WhenValidations.validateWithCustomValidators(allParams, paramValidatorsMap)
isInvalid
we get these errors without previous typing.To solve this issue I introduced a change which will still pass typing info further even when there are some custom validator errors. Instead of using
Validated
which can represent two states:Valid
andInvalid
, I usedIor
which lets us have 3 states:Left
,Right
andBoth
. First two are self-explanatory andBoth
can hold both failure and a success. This way we can preserve the typing info while also preserving errors from custom validation. After testing these changes locally, we preserve the typing info and have correct preset labels even when there were errors during compilation.Checklist before merge