jomarko commented on code in PR #2942:
URL: 
https://github.com/apache/incubator-kie-tools/pull/2942#discussion_r1977431740


##########
packages/online-editor/src/dmnRunner/DmnRunnerContextProvider.tsx:
##########
@@ -119,6 +126,81 @@ function dmnRunnerResultsReducer(dmnRunnerResults: 
DmnRunnerResults, action: Dmn
   }
 }
 
+/**
+ * This transformation is needed for these reasons:
+ * ### -1- ###
+ * DMN Runner backend return upper case constants: "SUCCEEDED", "FAILED", 
"SKIPPED"
+ * DMN Editor code base uses lover case constants: "succeeded", "failed", 
"skipped"
+ *
+ * ### -2- ###
+ * DMN Runner backend return evaluationHitIds as Object:
+ * {
+ *   _F0DC8923-5FC7-4200-8BD1-461D5F3715CF: 1,
+ *   _F0DC8923-5FC7-4200-8BD1-461D5F3713AD: 2
+ * }
+ * DMN Editor code base uses evaluationHitIds as Map<string, number>
+ * [
+ *   {
+ *     key: "_F0DC8923-5FC7-4200-8BD1-461D5F3715CF,
+ *     value: 1
+ *   },
+ *   {
+ *     key: "_F0DC8923-5FC7-4200-8BD1-461D5F3713AD",
+ *     value: 2
+ *   }
+ * ]
+ *
+ * ### -3- ###
+ * DMN Runner backend return data spilt into junks corresponding to table row 
or collection item
+ * DMN Editor want to show aggregated data for everything together
+ *
+ * @param result - DMN Runner backend data
+ * @param evaluationResultsPerNode - transformed data for DMN Editor
+ */
+function transformExtendedServicesDmnResult(
+  result: ExtendedServicesDmnResult,
+  evaluationResultsPerNode: Map<
+    string,
+    { evaluationResult: "succeeded" | "failed" | "skipped"; 
evaluationHitsCount: Map<string, number> }
+  >
+) {
+  result.decisionResults?.forEach((dr) => {
+    const evaluationHitsCount = new Map<string, number>();
+    // ### -2- ###
+    for (const [key, value] of Object.entries(dr.evaluationHitIds)) {
+      evaluationHitsCount.set(`${key}`, value as number);
+    }
+    // We want to merge evaluation results that belongs to the same Decision
+    // So we need to check if the Decision wasn't already partially processed
+    if (!evaluationResultsPerNode.has(dr.decisionId)) {
+      evaluationResultsPerNode.set(dr.decisionId, {
+        // ### -1- ###
+        evaluationResult: dr.evaluationStatus.toLowerCase() as "succeeded" | 
"failed" | "skipped",
+        evaluationHitsCount: evaluationHitsCount,
+      });
+    } else {
+      const existingEvaluationHitsCount = 
evaluationResultsPerNode.get(dr.decisionId)?.evaluationHitsCount;
+      evaluationHitsCount.forEach((value, key) => {
+        // ### -3- ###
+        if (existingEvaluationHitsCount?.has(key)) {
+          existingEvaluationHitsCount.set(key, 
(existingEvaluationHitsCount?.get(key) ?? 0) + value);
+        } else {
+          existingEvaluationHitsCount?.set(key, value);
+        }
+      });
+      // TODO - Question
+      // Here is an issue of merging evaluation results that belongs to the 
same Decision
+      // For example, what to do if first time evaluation was 'succeeded' and 
second time 'skipped'?
+      evaluationResultsPerNode.set(dr.decisionId, {
+        evaluationResult: dr.evaluationStatus.toLowerCase() as "succeeded" | 
"failed" | "skipped",
+        evaluationHitsCount: existingEvaluationHitsCount ?? new Map(),
+      });

Review Comment:
   Thank you for suggestions. 
   
   ### new badge
   Would you go for a completely new icon in such badge, or we would just put 
into badge an icon for each result that we had for given node. So lets say, in 
this conversation we would have badge that has 'succeeded' and 'skipped' icon, 
maximun amount of icons in such badge would be three.
   
   ### worst status
   What I miss how would we inform user ok, ok it is skipped, but also 
something else, would we use the worst staus icon, but we would change the 
background color of such bage?



-- 
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