jomarko commented on code in PR #2942:
URL:
https://github.com/apache/incubator-kie-tools/pull/2942#discussion_r1981795691
##########
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:
done in a separate commit
https://github.com/apache/incubator-kie-tools/pull/2942/commits/9ed75f0a6edddcf54b65985aad69c93416d01251
--
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]