Skip to content

Commit

Permalink
[NU-1862] SpelTemplateParameterEditor for text (#7614)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-bigorajski authored Mar 6, 2025
1 parent 2435d04 commit 4f40272
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import scala.util.Try

case object RawParameterEditor extends ParameterEditor

case object SpelParameterEditor extends ParameterEditor

@ConfiguredJsonCodec sealed trait SimpleParameterEditor extends ParameterEditor

case object BoolParameterEditor extends SimpleParameterEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ package object definition {
name: String,
typ: TypingResult,
editor: ParameterEditor,
editors: List[ParameterEditor],
// It is used for node parameter adjustment on FE side (see ParametersUtils.ts -> adjustParameters)
defaultValue: Expression,
// additionalVariables and variablesToHide are served to FE because suggestions API requires full set of variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pl.touk.nussknacker.engine.ModelData
import pl.touk.nussknacker.engine.api.TemplateEvaluationResult
import pl.touk.nussknacker.engine.api.component._
import pl.touk.nussknacker.engine.api.definition._
import pl.touk.nussknacker.engine.api.editor.DualEditorMode
import pl.touk.nussknacker.engine.api.process.ProcessingType
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypedClass, TypingResult}
import pl.touk.nussknacker.engine.definition.component.FragmentSpecificData
Expand Down Expand Up @@ -169,6 +170,21 @@ object DefinitionsService {
name = parameter.name.value,
typ = toUIType(parameter.typ),
editor = parameter.finalEditor,
editors = parameter.editor match {
case Some(RawParameterEditor) => List(SpelParameterEditor)
case Some(StringParameterEditor) => List(SpelTemplateParameterEditor, SpelParameterEditor)
case Some(DualParameterEditor(simpleEditor, defaultMode)) =>
val mappedSimpleEditor = simpleEditor match {
case StringParameterEditor => SpelTemplateParameterEditor
case e => e
}
defaultMode match {
case DualEditorMode.RAW => List(SpelParameterEditor, mappedSimpleEditor)
case DualEditorMode.SIMPLE => List(mappedSimpleEditor, SpelParameterEditor)
}
case Some(editor) => List(editor)
case None => List(SpelParameterEditor)
},
defaultValue = parameter.finalDefaultValue,
additionalVariables = parameter.additionalVariables.mapValuesNow(_.typingResult),
variablesToHide = parameter.variablesToHide,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ class NodesApiHttpServiceBusinessSpec
| "defaultMode": "RAW",
| "type": "DualParameterEditor"
| },
| "editors": [
| {
| "type": "SpelParameterEditor"
| },
| {
| "type": "SpelTemplateParameterEditor"
| }
| ],
| "defaultValue": {
| "language": "spel",
| "expression": "''"
Expand All @@ -358,6 +366,9 @@ class NodesApiHttpServiceBusinessSpec
| "editor": {
| "type": "RawParameterEditor"
| },
| "editors": [{
| "type": "SpelParameterEditor"
| }],
| "defaultValue": {
| "language": "spel",
| "expression": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class TestingApiHttpServiceSpec
| "editor": {
| "type": "RawParameterEditor"
| },
| "editors": [{
| "type": "SpelParameterEditor"
| }],
| "defaultValue": {
| "language": "spel",
| "expression": ""
Expand Down Expand Up @@ -252,6 +255,23 @@ class TestingApiHttpServiceSpec
| ],
| "type": "FixedValuesParameterEditor"
| },
| "editors": [{
| "possibleValues": [
| {
| "expression": "",
| "label": ""
| },
| {
| "expression": "'uno'",
| "label": "uno"
| },
| {
| "expression": "'due'",
| "label": "due"
| }
| ],
| "type": "FixedValuesParameterEditor"
| }],
| "defaultValue": {
| "language": "spel",
| "expression": "'uno'"
Expand Down Expand Up @@ -303,6 +323,14 @@ class TestingApiHttpServiceSpec
| "editor": {
| "type": "StringParameterEditor"
| },
| "editors": [
| {
| "type": "SpelParameterEditor"
| },
| {
| "type": "SpelTemplateParameterEditor"
| }
| ],
| "defaultValue": {
| "language": "spel",
| "expression": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.ui.integration

import io.circe.{Decoder, Json, JsonObject}
import io.circe.Json.{arr, fromBoolean, fromFields, fromString, obj, Null}
import io.circe.Json.{arr, fromBoolean, fromFields, fromString, fromValues, obj, Null}
import io.circe.syntax.EncoderOps
import org.apache.commons.io.FileUtils
import org.scalatest.OptionValues
Expand Down Expand Up @@ -117,10 +117,16 @@ class BaseFlowTest
"service-enricher" -> obj(
"parameters" -> arr(
obj(
"name" -> fromString("param"),
"label" -> fromString("param"),
"defaultValue" -> Expression.spel("'default-from-additional-ui-config-provider'").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"name" -> fromString("param"),
"label" -> fromString("param"),
"defaultValue" -> Expression.spel("'default-from-additional-ui-config-provider'").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"editors" -> fromValues(
List(
encodeEditor(SpelParameterEditor),
encodeEditor(SpelTemplateParameterEditor),
)
),
"hintText" -> fromString("hint-text-from-additional-ui-config-provider"),
"requiredParam" -> fromBoolean(true),
),
Expand All @@ -141,6 +147,22 @@ class BaseFlowTest
DualEditorMode.SIMPLE
)
),
"editors" -> fromValues(
List(
encodeEditor(
FixedValuesParameterEditor(
List(
FixedExpressionValue(
"T(pl.touk.nussknacker.engine.management.sample.TariffType).NORMAL",
"normal"
),
FixedExpressionValue("T(pl.touk.nussknacker.engine.management.sample.TariffType).GOLD", "gold")
)
)
),
encodeEditor(SpelParameterEditor),
)
),
"hintText" -> Null,
"requiredParam" -> fromBoolean(true),
),
Expand All @@ -151,18 +173,29 @@ class BaseFlowTest
"service-multipleParamsService" -> obj(
"parameters" -> arr(
obj(
"name" -> fromString("foo"),
"label" -> fromString("foo"),
"defaultValue" -> Expression.spel("'test'").asJson,
"editor" -> encodeEditor(FixedValuesParameterEditor(List(FixedExpressionValue("'test'", "test")))),
"name" -> fromString("foo"),
"label" -> fromString("foo"),
"defaultValue" -> Expression.spel("'test'").asJson,
"editor" -> encodeEditor(FixedValuesParameterEditor(List(FixedExpressionValue("'test'", "test")))),
"editors" -> fromValues(
List(
encodeEditor(FixedValuesParameterEditor(List(FixedExpressionValue("'test'", "test"))))
)
),
"hintText" -> Null,
"requiredParam" -> fromBoolean(true),
),
obj(
"name" -> fromString("bar"),
"label" -> fromString("bar"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(StringParameterEditor),
"name" -> fromString("bar"),
"label" -> fromString("bar"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(StringParameterEditor),
"editors" -> fromValues(
List(
encodeEditor(SpelTemplateParameterEditor),
encodeEditor(SpelParameterEditor)
)
),
"hintText" -> Null,
"requiredParam" -> fromBoolean(true),
),
Expand All @@ -173,14 +206,27 @@ class BaseFlowTest
"editor" -> encodeEditor(
FixedValuesParameterEditor(List(FixedExpressionValue("1", "1"), FixedExpressionValue("2", "2")))
),
"editors" -> fromValues(
List(
encodeEditor(
FixedValuesParameterEditor(List(FixedExpressionValue("1", "1"), FixedExpressionValue("2", "2")))
)
)
),
"hintText" -> fromString("some hint text"),
"requiredParam" -> fromBoolean(true),
),
obj(
"name" -> fromString("quax"),
"label" -> fromString("quax"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"name" -> fromString("quax"),
"label" -> fromString("quax"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"editors" -> fromValues(
List(
encodeEditor(SpelParameterEditor),
encodeEditor(SpelTemplateParameterEditor),
)
),
"hintText" -> Null,
"requiredParam" -> fromBoolean(true),
),
Expand All @@ -196,10 +242,16 @@ class BaseFlowTest
"service-providedComponent-component-v1" -> obj(
"parameters" -> arr(
obj(
"name" -> fromString("fromConfig-v1"),
"label" -> fromString("fromConfig-v1"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"name" -> fromString("fromConfig-v1"),
"label" -> fromString("fromConfig-v1"),
"defaultValue" -> Expression.spel("''").asJson,
"editor" -> encodeEditor(DualParameterEditor(StringParameterEditor, DualEditorMode.RAW)),
"editors" -> fromValues(
List(
encodeEditor(SpelParameterEditor),
encodeEditor(SpelTemplateParameterEditor),
)
),
"hintText" -> Null,
"requiredParam" -> fromBoolean(true),
)
Expand Down
10 changes: 10 additions & 0 deletions docs-internal/api/nu-designer-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,8 @@ paths:
params: []
editor:
type: RawParameterEditor
editors:
- type: SpelParameterEditor
defaultValue:
language: spel
expression: ''
Expand Down Expand Up @@ -6797,6 +6799,7 @@ components:
- $ref: '#/components/schemas/JsonParameterEditor'
- $ref: '#/components/schemas/PeriodParameterEditor'
- $ref: '#/components/schemas/RawParameterEditor'
- $ref: '#/components/schemas/SpelParameterEditor'
- $ref: '#/components/schemas/SpelTemplateParameterEditor'
- $ref: '#/components/schemas/SqlParameterEditor'
- $ref: '#/components/schemas/StringParameterEditor'
Expand Down Expand Up @@ -7247,6 +7250,9 @@ components:
type: array
items:
$ref: '#/components/schemas/Parameter'
SpelParameterEditor:
title: SpelParameterEditor
type: object
SpelTemplateParameterEditor:
title: SpelTemplateParameterEditor
type: object
Expand Down Expand Up @@ -7692,6 +7698,10 @@ components:
- $ref: '#/components/schemas/Unknown'
editor:
$ref: '#/components/schemas/ParameterEditor'
editors:
type: array
items:
$ref: '#/components/schemas/ParameterEditor'
defaultValue:
$ref: '#/components/schemas/Expression'
additionalVariables:
Expand Down
3 changes: 3 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
* Nussknacker provides some limited set of services that can be invoked from inside the `CustomHttpServiceProvider` implementation
* the service is created and started alongside Nu Designer, endpoints are exposed on path `/api/custom/*`
* [#7578](https://github.com/TouK/nussknacker/pull/7578) Component labels are now independent of component Id. Labels can be set during the component defining or can be set in ui configuration in application config
* [#7614](https://github.com/TouK/nussknacker/pull/7614) SpelTemplate as a main text editor
* Added a new parameter editor type: SpelParameterEditor which works the same as RawParameterEditor.
* Added a list of editors to the UIParameter.

## 1.18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object EditorBasedLanguageDeterminer {

def determineLanguageOf(editor: Option[ParameterEditor]): Expression.Language = editor match {
case Some(RawParameterEditor) => Expression.Language.Spel
case Some(SpelParameterEditor) => Expression.Language.Spel
case Some(simpleEditor: SimpleParameterEditor) => determineLanguageOf(simpleEditor)
case Some(DualParameterEditor(simpleEditor, _)) => determineLanguageOf(simpleEditor)
case None => Expression.Language.Spel
Expand Down

0 comments on commit 4f40272

Please sign in to comment.