thiagoelg commented on code in PR #3557:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3557#discussion_r3196795271


##########
packages/bpmn-editor-envelope/src/customTasks/MilestoneTask.tsx:
##########
@@ -86,13 +94,83 @@ export function getMilestoneTask(i18n: 
BpmnEditorEnvelopeI18n): CustomTask {
     iconSvgElement: MILESTONE_TASK_ICON,
     propertiesPanelComponent: MilestoneTaskProperties,
     matches: (task) => task["@_drools:taskName"] === "Milestone",
-    produce: () => ({
-      __$$element: "task",
-      "@_id": generateUuid(),
-      "@_drools:taskName": "Milestone",
-      "@_name": i18n.milestone,
-    }),
-    dataInputReservedNames: [],
+    produce: () => {
+      const conditionInputId = generateUuid();
+      const taskNameInputId = generateUuid();
+      return {
+        __$$element: "task",
+        "@_id": generateUuid(),
+        "@_drools:taskName": "Milestone",
+        "@_name": i18n.milestone,
+        ioSpecification: {
+          "@_id": generateUuid(),
+          dataInput: [
+            {
+              "@_id": conditionInputId,
+              "@_name": 
MILESTONE_TASK_IO_SPECIFICATION_DATA_INPUTS_CONSTANTS.CONDITION,
+              "@_drools:dtype": "String",
+            },
+            {
+              "@_id": taskNameInputId,
+              "@_name": 
MILESTONE_TASK_IO_SPECIFICATION_DATA_INPUTS_CONSTANTS.TASK_NAME,
+              "@_drools:dtype": "Object",
+            },
+          ],
+          inputSet: [
+            {
+              "@_id": generateUuid(),
+              dataInputRefs: [{ __$$text: conditionInputId }, { __$$text: 
taskNameInputId }],
+            },
+          ],
+          dataOutput: [],
+          outputSet: [
+            {
+              "@_id": generateUuid(),
+              dataOutputRefs: [],
+            },
+          ],
+        },
+        dataInputAssociation: [
+          {
+            "@_id": generateUuid(),
+            targetRef: { __$$text: taskNameInputId },
+            sourceRef: [],
+            assignment: [
+              {
+                "@_id": generateUuid(),
+                from: {
+                  "@_id": generateUuid(),
+                  "@_xsi:type": "tFormalExpression",
+                  __$$text: MILESTONE_TASK_VALUES.TASK_NAME_VALUE,
+                } as any,
+                to: { "@_id": generateUuid(), __$$text: taskNameInputId },
+              },
+            ],
+          },
+        ],
+        dataOutputAssociation: [],
+      };
+    },
+    onAdded: (state, task) => {
+      const { itemDefinition: stringItemDefinition } = 
addOrGetItemDefinitions({
+        definitions: state.bpmn.model.definitions,
+        dataType: DEFAULT_DATA_TYPES.STRING,
+      });
+
+      const { itemDefinition: objectItemDefinition } = 
addOrGetItemDefinitions({
+        definitions: state.bpmn.model.definitions,
+        dataType: DEFAULT_DATA_TYPES.OBJECT,
+      });
+
+      if (task.ioSpecification?.dataInput?.[0]) {
+        task.ioSpecification.dataInput[0]["@_itemSubjectRef"] = 
stringItemDefinition["@_id"];
+      }
+
+      if (task.ioSpecification?.dataInput?.[1]) {
+        task.ioSpecification.dataInput[1]["@_itemSubjectRef"] = 
objectItemDefinition["@_id"];
+      }

Review Comment:
   I feel like there's a better way to do this. 🤔 
   You can create the inputs in the `onAdded` callback and then call 
`setInputAndOutputDataMapping` to generate all of the `ioSpecification` 
automatically. This way will also work when morphing from other nodes.
   
   Also, we have constants for the data types (`DEFAULT_DATA_TYPES.STRING` and 
`DEFAULT_DATA_TYPES.OBJECT`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to