Skip to content

Commit 0e77a13

Browse files
author
Piotr Rudnicki
committed
[Nu-7231] Resolve simple class name
1 parent 2127b3d commit 0e77a13

File tree

2 files changed

+38
-1
lines changed
  • designer/client/src/components/graph/node-modal/fragment-input-definition/item
  • scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile

2 files changed

+38
-1
lines changed

designer/client/src/components/graph/node-modal/fragment-input-definition/item/Item.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ interface ItemProps {
2626
errors: NodeValidationError[];
2727
}
2828

29+
//This projection is used for backward-compatibility reasons, since previously fragment input definition type options display part contained full class name
30+
function resolveSimpleClassName(className: string): string {
31+
const parts = className.split(".");
32+
return parts[parts.length - 1];
33+
}
34+
2935
export function Item(props: ItemProps): JSX.Element {
3036
const { index, item, namespace, variableTypes, readOnly, showValidation, onChange, options, errors } = props;
3137
const { getIsOpen, toggleIsOpen } = useFieldsContext();
@@ -36,7 +42,7 @@ export function Item(props: ItemProps): JSX.Element {
3642
const [isMarked] = useDiffMark();
3743
const getCurrentOption = useCallback(
3844
(typ: ReturnedType | undefined) => {
39-
const fallbackValue = { label: typ?.refClazzName, value: typ?.refClazzName };
45+
const fallbackValue = { label: resolveSimpleClassName(typ?.refClazzName), value: resolveSimpleClassName(typ?.refClazzName) };
4046
const foundValue = options.find((item) => isEqual(typ?.refClazzName, item.value));
4147
return foundValue || fallbackValue;
4248
},

scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/NodeDataValidatorSpec.scala

+31
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,37 @@ class NodeDataValidatorSpec extends AnyFunSuite with Matchers with Inside with T
11601160
}
11611161
}
11621162

1163+
test(
1164+
"should not allow usage of generic type in FragmentInputDefinition parameter when occurring type is not on classpath"
1165+
) {
1166+
val nodeId: String = "in"
1167+
val paramName = "param1"
1168+
1169+
inside(
1170+
validate(
1171+
FragmentInputDefinition(
1172+
nodeId,
1173+
List(
1174+
FragmentParameter(
1175+
ParameterName(paramName),
1176+
FragmentClazzRef("Map[String, Foo]"),
1177+
required = false,
1178+
initialValue = None,
1179+
hintText = None,
1180+
valueEditor = None,
1181+
valueCompileTimeValidation = None
1182+
)
1183+
),
1184+
),
1185+
ValidationContext.empty,
1186+
Map.empty,
1187+
outgoingEdges = List(OutgoingEdge("any", Some(FragmentOutput("out1"))))
1188+
)
1189+
) { case ValidationPerformed(errors, None, None) =>
1190+
errors shouldBe List(FragmentParamClassLoadError(ParameterName("param1"), "Map[String, Foo]", "in"))
1191+
}
1192+
}
1193+
11631194
test("shouldn't fail on valid validation expression") {
11641195
val nodeId: String = "in"
11651196
val paramName = "param1"

0 commit comments

Comments
 (0)