This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 86fcff67eda kie-issues#2548: Cannot add a new record within an empty 
Decision Table (#2912)
86fcff67eda is described below

commit 86fcff67eda70f0aa5dd918683da9a7fdbd91f50
Author: Kusuma04-dev <[email protected]>
AuthorDate: Thu Mar 13 23:07:04 2025 +0530

    kie-issues#2548: Cannot add a new record within an empty Decision Table 
(#2912)
    
    Co-authored-by: chinnamatli kusumalatha 
<[email protected]>
---
 .../DecisionTableExpression.tsx                    | 83 +++++++++++++++-------
 1 file changed, 57 insertions(+), 26 deletions(-)

diff --git 
a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
 
b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
index c7e652a4a8c..620b0a5798c 100644
--- 
a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
+++ 
b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
@@ -102,6 +102,26 @@ function createAnnotationEntry(): 
Unpacked<Normalized<DMN15__tDecisionRule["anno
   };
 }
 
+const createDefaultRule = (): Normalized<DMN15__tDecisionRule> => {
+  const defaultRowToAdd: Normalized<DMN15__tDecisionRule> = {
+    "@_id": generateUuid(),
+    inputEntry: [
+      {
+        "@_id": generateUuid(),
+        text: { __$$text: "-" },
+      },
+    ],
+    outputEntry: [
+      {
+        "@_id": generateUuid(),
+        text: { __$$text: "" },
+      },
+    ],
+    annotationEntry: [{ text: { __$$text: "// Your annotations here" } }],
+  };
+  return defaultRowToAdd;
+};
+
 export function DecisionTableExpression({
   isNested,
   expression: decisionTableExpression,
@@ -310,6 +330,10 @@ export function DecisionTableExpression({
     ]
   );
 
+  const rules = useMemo<DMN15__tDecisionRule[]>(() => {
+    return decisionTableExpression.rule ?? [];
+  }, [decisionTableExpression]);
+
   const beeTableRef = useRef<BeeTableRef>(null);
   const { onColumnResizingWidthChange, columnResizingWidths, isPivoting } = 
usePublishedBeeTableResizableColumns(
     decisionTableExpression["@_id"]!,
@@ -326,7 +350,7 @@ export function DecisionTableExpression({
     BEE_TABLE_ROW_INDEX_COLUMN_WIDTH,
     columns,
     columnResizingWidths,
-    decisionTableExpression.rule ?? []
+    rules
   );
 
   /// //////////////////////////////////////////////////////
@@ -417,35 +441,39 @@ export function DecisionTableExpression({
     widths,
   ]);
 
-  const beeTableRows = useMemo(
-    () =>
-      (decisionTableExpression.rule ?? []).map((rule) => {
-        const ruleRow = [
-          ...(rule.inputEntry ?? []),
-          ...(rule.outputEntry ?? new 
Array(decisionTableExpression.output.length)),
-          ...(rule.annotationEntry ?? []),
-        ];
-
-        return getColumnsAtLastLevel(beeTableColumns).reduce(
-          (tableRow: ROWTYPE, column, columnIndex) => {
-            tableRow[column.accessor] = {
-              id: (ruleRow[columnIndex] as DMN15__tUnaryTests & 
DMN15__tLiteralExpression)?.["@_id"] ?? "",
-              content: ruleRow[columnIndex]?.text?.__$$text ?? "",
-            };
-            return tableRow;
-          },
-          { id: rule["@_id"] }
-        );
-      }),
-    [beeTableColumns, decisionTableExpression.output.length, 
decisionTableExpression.rule]
-  );
+  const beeTableRows = useMemo(() => {
+    const mapRuleToRow = (rule: Normalized<DMN15__tDecisionRule>) => {
+      const ruleRow = [
+        ...(rule.inputEntry ?? []),
+        ...(rule.outputEntry ?? new 
Array(decisionTableExpression.output.length)),
+        ...(rule.annotationEntry ?? []),
+      ];
+
+      return getColumnsAtLastLevel(beeTableColumns).reduce(
+        (tableRow: ROWTYPE, column, columnIndex) => {
+          tableRow[column.accessor] = {
+            id: (ruleRow[columnIndex] as DMN15__tUnaryTests & 
DMN15__tLiteralExpression)?.["@_id"] ?? "",
+            content: ruleRow[columnIndex]?.text?.__$$text ?? "",
+          };
+          return tableRow;
+        },
+        { id: rule["@_id"] }
+      );
+    };
+    if (!decisionTableExpression.rule || decisionTableExpression.rule.length 
=== 0) {
+      return [mapRuleToRow(createDefaultRule())];
+    }
+    return decisionTableExpression.rule.map(mapRuleToRow);
+  }, [decisionTableExpression.rule, decisionTableExpression.output.length, 
beeTableColumns]);
 
   const onCellUpdates = useCallback(
     (cellUpdates: BeeTableCellUpdate<ROWTYPE>[]) => {
       setExpression({
         setExpressionAction: (prev: Normalized<BoxedDecisionTable>) => {
           let previousExpression: Normalized<BoxedDecisionTable> = { ...prev };
-
+          if (!previousExpression.rule || previousExpression.rule.length === 
0) {
+            previousExpression.rule = [createDefaultRule()];
+          }
           cellUpdates.forEach((cellUpdate) => {
             const newRules = [...(previousExpression.rule ?? [])];
             const groupType = cellUpdate.column.groupType as 
DecisionTableColumnType;
@@ -720,9 +748,12 @@ export function DecisionTableExpression({
     (args: { beforeIndex: number; rowsCount: number }) => {
       setExpression({
         setExpressionAction: (prev: Normalized<BoxedDecisionTable>) => {
-          const newRules = [...(prev.rule ?? [])];
-          const newItems: Normalized<DMN15__tDecisionRule>[] = [];
+          let newRules = [...(prev.rule ?? [])];
+          if (newRules.length === 0) {
+            newRules = [createDefaultRule()];
+          }
 
+          const newItems: Normalized<DMN15__tDecisionRule>[] = [];
           for (let i = 0; i < args.rowsCount; i++) {
             newItems.push({
               "@_id": generateUuid(),


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

Reply via email to