From 2413cc28af299ea50650d91249366da67c5ca3d0 Mon Sep 17 00:00:00 2001 From: gskrobisz Date: Fri, 20 Dec 2024 19:34:09 +0100 Subject: [PATCH] fix tests --- .../GenericAction/useActivityCapabilities.tsx | 14 +++ .../buttons/RunOffScheduleButton.tsx | 4 +- designer/client/src/http/HttpService.ts | 2 +- .../sample/DevProcessConfigCreator.scala | 13 +- .../sample/source/BoundedSource.scala | 114 +++++++++--------- 5 files changed, 79 insertions(+), 68 deletions(-) create mode 100644 designer/client/src/components/modals/GenericAction/useActivityCapabilities.tsx diff --git a/designer/client/src/components/modals/GenericAction/useActivityCapabilities.tsx b/designer/client/src/components/modals/GenericAction/useActivityCapabilities.tsx new file mode 100644 index 00000000000..d632d31dbe2 --- /dev/null +++ b/designer/client/src/components/modals/GenericAction/useActivityCapabilities.tsx @@ -0,0 +1,14 @@ +import { useDispatch, useSelector } from "react-redux"; +import { getProcessName, getScenarioGraph } from "../../../reducers/selectors/graph"; +import { useEffect } from "react"; +import { fetchActivityParameters } from "../../../actions/nk"; +export function useActivityCapabilities() { + const dispatch = useDispatch(); + + const scenarioName = useSelector(getProcessName); + const scenarioGraph = useSelector(getScenarioGraph); + + useEffect(() => { + dispatch(fetchActivityParameters(scenarioName, scenarioGraph)); + }, [dispatch, scenarioName, scenarioGraph]); +} diff --git a/designer/client/src/components/toolbars/scenarioActions/buttons/RunOffScheduleButton.tsx b/designer/client/src/components/toolbars/scenarioActions/buttons/RunOffScheduleButton.tsx index 2dec4aaa1a1..f59d012d84f 100644 --- a/designer/client/src/components/toolbars/scenarioActions/buttons/RunOffScheduleButton.tsx +++ b/designer/client/src/components/toolbars/scenarioActions/buttons/RunOffScheduleButton.tsx @@ -34,7 +34,7 @@ export default function RunOffScheduleButton(props: ToolbarButtonProps) { const available = !disabled && isPossible && capabilities.deploy; const { open } = useWindows(); - const action = (p, c) => HttpService.runOffSchedule(p, c).finally(() => dispatch(loadProcessState(processName, processVersionId))); + const action = (p, c, d) => HttpService.runOffSchedule(p, c).finally(() => dispatch(loadProcessState(processName, processVersionId))); const message = t("panels.actions.run-of-out-schedule.dialog", "Perform single execution", { name: processName }); const defaultTooltip = t("panels.actions.run-off-schedule.tooltip", "run now"); @@ -52,7 +52,7 @@ export default function RunOffScheduleButton(props: ToolbarButtonProps) { title: message, kind: WindowKind.deployProcess, width: ACTION_DIALOG_WIDTH, - meta: { action }, + meta: { action, activityName: "RUN_OFF_SCHEDULE" }, // fixme: activityName, do we need this? }) } type={type} diff --git a/designer/client/src/http/HttpService.ts b/designer/client/src/http/HttpService.ts index 00266d7c887..06d11a7ef69 100644 --- a/designer/client/src/http/HttpService.ts +++ b/designer/client/src/http/HttpService.ts @@ -33,7 +33,7 @@ import { EventTrackingSelectorType, EventTrackingType } from "../containers/even import { BackendNotification } from "../containers/Notifications"; import { ProcessCounts } from "../reducers/graph"; import { AuthenticationSettings } from "../reducers/settings"; -import { Expression, NodeType, ProcessAdditionalFields, ProcessDefinitionData, ScenarioGraph, VariableTypes } from "../types"; +import { Expression, NodeId, NodeType, ProcessAdditionalFields, ProcessDefinitionData, ScenarioGraph, VariableTypes } from "../types"; import { Instant, WithId } from "../types/common"; import { fixAggregateParameters, fixBranchParametersTemplate } from "./parametersUtils"; diff --git a/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/DevProcessConfigCreator.scala b/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/DevProcessConfigCreator.scala index 1f5c97c5f0e..fd4a06e5108 100644 --- a/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/DevProcessConfigCreator.scala +++ b/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/DevProcessConfigCreator.scala @@ -91,13 +91,12 @@ class DevProcessConfigCreator extends ProcessConfigCreator { )(TypeInformation.of(classOf[SampleProduct])) ) ), - "kafka-transaction" -> all(SourceFactory.noParamUnboundedStreamFactory[String](new NoEndingSource)), - "boundedSource" -> all(BoundedSource), - "boundedSourceWithOffset" -> all(BoundedSourceWithOffset), - "boundedSourceWithOtherParam" -> all(DummyBoundedSourceToDelete), - "oneSource" -> categories(SourceFactory.noParamUnboundedStreamFactory[String](new OneSource)), - "communicationSource" -> categories(DynamicParametersSource), - "csv-source" -> categories(SourceFactory.noParamUnboundedStreamFactory[CsvRecord](new CsvSource)), + "kafka-transaction" -> all(SourceFactory.noParamUnboundedStreamFactory[String](new NoEndingSource)), + "boundedSource" -> all(BoundedSource), + "boundedSourceWithOffset" -> all(BoundedSourceWithOffset), + "oneSource" -> categories(SourceFactory.noParamUnboundedStreamFactory[String](new OneSource)), + "communicationSource" -> categories(DynamicParametersSource), + "csv-source" -> categories(SourceFactory.noParamUnboundedStreamFactory[CsvRecord](new CsvSource)), "csv-source-lite" -> categories(SourceFactory.noParamUnboundedStreamFactory[CsvRecord](new LiteCsvSource(_))), "genericSourceWithCustomVariables" -> categories(GenericSourceWithCustomVariablesSample), "sql-source" -> categories(SqlSource), diff --git a/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/source/BoundedSource.scala b/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/source/BoundedSource.scala index b225fd2be75..570e77b505f 100644 --- a/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/source/BoundedSource.scala +++ b/engine/flink/management/dev-model/src/main/scala/pl/touk/nussknacker/engine/management/sample/source/BoundedSource.scala @@ -3,12 +3,7 @@ package pl.touk.nussknacker.engine.management.sample.source import org.apache.flink.streaming.api.datastream.DataStreamSource import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment import pl.touk.nussknacker.engine.api.component.{ParameterConfig, UnboundedStreamComponent} -import pl.touk.nussknacker.engine.api.definition.{ - BoolParameterEditor, - FixedExpressionValue, - FixedValuesParameterEditor, - RawParameterEditor -} +import pl.touk.nussknacker.engine.api.definition.{FixedExpressionValue, FixedValuesParameterEditor, RawParameterEditor} import pl.touk.nussknacker.engine.api.deployment.ScenarioActionName import pl.touk.nussknacker.engine.api.editor.FixedValuesEditorMode import pl.touk.nussknacker.engine.api.process.{SourceFactory, WithActivityParameters} @@ -18,6 +13,7 @@ import pl.touk.nussknacker.engine.flink.api.process.FlinkCustomNodeContext import pl.touk.nussknacker.engine.flink.util.source.CollectionSource import scala.jdk.CollectionConverters._ +import scala.util.Try object BoundedSource extends SourceFactory with UnboundedStreamComponent { @@ -29,41 +25,15 @@ object BoundedSource extends SourceFactory with UnboundedStreamComponent { object BoundedSourceWithOffset extends SourceFactory with UnboundedStreamComponent { + val OFFSET_PARAMETER_NAME = "offset" + @MethodToInvoke def source(@ParamName("elements") elements: java.util.List[Any]) = new CollectionSource[Any](elements.asScala.toList, None, Unknown) with WithActivityParameters { override def activityParametersDefinition: Map[String, Map[String, ParameterConfig]] = { - val fixedValuesEditor = Some( - FixedValuesParameterEditor( - List( - FixedExpressionValue("Continue", "Continue", Some("Resumes reading data where it previously stopped.")), - FixedExpressionValue("Reset", "Reset", Some("Starts reading new events only.")), - FixedExpressionValue("Restart", "Restart", Some("Rewinds reading from the earliest event.")), - ), - FixedValuesEditorMode.RADIO - ) - ) Map( - ScenarioActionName.Deploy.value -> Map( - "offset" -> ParameterConfig( - defaultValue = None, - editor = Some(RawParameterEditor), - validators = None, - label = Some("Offset"), - hintText = Some( - "Set offset to setup source to emit elements from specified start point in input collection. Empty field resets collection to the beginning." - ) - ), - // TODO: remove offsetResetStrategy - "offsetResetStrategy" -> ParameterConfig( - defaultValue = Some("Restart"), - editor = fixedValuesEditor, - validators = None, - label = Some("Starting point strategy"), - hintText = Some("Example of parameter with fixed values") - ), - ) + ScenarioActionName.Deploy.value -> deployActivityParameters ) } @@ -72,9 +42,12 @@ object BoundedSourceWithOffset extends SourceFactory with UnboundedStreamCompone env: StreamExecutionEnvironment, flinkNodeContext: FlinkCustomNodeContext ): DataStreamSource[T] = { - val offsetOpt = flinkNodeContext.nodeDeploymentData.flatMap(_.get("offset")) + val offsetOpt = + flinkNodeContext.nodeDeploymentData + .flatMap(_.get(OFFSET_PARAMETER_NAME)) + .flatMap(s => Try(s.toInt).toOption) val elementsWithOffset = offsetOpt match { - case Some(offset) => list.drop(offset.toInt) + case Some(offset) => list.drop(offset) case _ => list } super.createSourceStream(elementsWithOffset, env, flinkNodeContext) @@ -82,27 +55,52 @@ object BoundedSourceWithOffset extends SourceFactory with UnboundedStreamCompone } -} - -object DummyBoundedSourceToDelete extends SourceFactory with UnboundedStreamComponent { - - @MethodToInvoke - def source(@ParamName("elements") elements: java.util.List[Any]) = - new CollectionSource[Any](elements.asScala.toList, None, Unknown) with WithActivityParameters { - - override def activityParametersDefinition: Map[String, Map[String, ParameterConfig]] = - Map( - ScenarioActionName.Deploy.value -> Map( - "otherParameter" -> ParameterConfig( - defaultValue = None, - editor = Some(BoolParameterEditor), - validators = None, - label = Some("Other parameter"), - hintText = Some("this is hint") - ) - ) + private def deployActivityParameters: Map[String, ParameterConfig] = { + Map( + OFFSET_PARAMETER_NAME -> ParameterConfig( + defaultValue = None, + editor = Some(RawParameterEditor), + validators = None, + label = Some("Offset"), + hintText = Some( + "Set offset to setup source to emit elements from specified start point in input collection. Empty field resets collection to the beginning." ) - - } + ), + "exampleFixedRadio" -> ParameterConfig( + defaultValue = Some("Restart"), + editor = Some( + FixedValuesParameterEditor( + List( + FixedExpressionValue( + "Continue", + "Continue", + Some("Resumes reading data where it previously stopped.") + ), + FixedExpressionValue("Reset", "Reset", Some("Starts reading new events only.")), + FixedExpressionValue("Restart", "Restart", Some("Rewinds reading from the earliest event.")), + ), + FixedValuesEditorMode.RADIO + ) + ), + validators = None, + label = Some("Example fixed radio"), + hintText = Some("Hint text for example fixed radio") + ), + "exampleFixedList" -> ParameterConfig( + defaultValue = None, + editor = Some( + FixedValuesParameterEditor( + List( + FixedExpressionValue("Item 1", "First item", Some("Hint text for item 1")), + FixedExpressionValue("Item 2", "Second item", Some("Hint text for item 2")), + ), + ) + ), + validators = None, + label = Some("Example fixed list"), + hintText = Some("Hint text for example fixed list") + ), + ) + } }