From 5a75a1c259ec8e1853d3d0c1b1dbdf997e8499e3 Mon Sep 17 00:00:00 2001 From: chinnamatli kusumalatha Date: Thu, 20 Feb 2025 17:06:40 +0530 Subject: [PATCH] handling empty decisiontable same as default decisiontable --- .../DecisionTableExpression.tsx | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx index 836b89e9767..1eba10a2ed5 100644 --- a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx @@ -416,6 +416,26 @@ export function DecisionTableExpression({ widths, ]); + const createDefaultRule = () => { + const defaultRowToAdd: Normalized = { + "@_id": generateUuid(), + inputEntry: [ + { + "@_id": generateUuid(), + text: { __$$text: DECISION_TABLE_INPUT_DEFAULT_VALUE }, + }, + ], + outputEntry: [ + { + "@_id": generateUuid(), + text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE }, + }, + ], + annotationEntry: [{ text: { __$$text: "// Your annotations here" } }], + }; + return defaultRowToAdd; + }; + const beeTableRows = useMemo(() => { const mapRuleToRow = (rule: Normalized) => { const ruleRow = [ @@ -437,43 +457,18 @@ export function DecisionTableExpression({ }; const prevRules = decisionTableExpression.rule ?? []; if (prevRules.length === 0) { - const defaultRowToAdd: Normalized = { - "@_id": generateUuid(), - inputEntry: decisionTableExpression.input?.map(() => ({ - "@_id": generateUuid(), - text: { __$$text: DECISION_TABLE_INPUT_DEFAULT_VALUE }, - })), - outputEntry: decisionTableExpression.output?.map(() => ({ - "@_id": generateUuid(), - text: { __$$text: DECISION_TABLE_OUTPUT_DEFAULT_VALUE }, - })), - annotationEntry: [{ text: { __$$text: "// Your annotations here" } }], - }; - return [mapRuleToRow(defaultRowToAdd)]; + return [mapRuleToRow(createDefaultRule())]; } return prevRules.map(mapRuleToRow); - }, [decisionTableExpression.rule, decisionTableExpression.output, decisionTableExpression.input, beeTableColumns]); + }, [decisionTableExpression.rule, decisionTableExpression.output.length, beeTableColumns]); const onCellUpdates = useCallback( (cellUpdates: BeeTableCellUpdate[]) => { setExpression({ setExpressionAction: (prev: Normalized) => { let previousExpression: Normalized = { ...prev }; - const isDisplayOnlyRowPresent = previousExpression.rule === undefined ? true : false; - if (isDisplayOnlyRowPresent) { - const defaultRowToAdd: Normalized = { - "@_id": generateUuid(), - inputEntry: Array.from(new Array(prev.input?.length ?? 0)).map(() => { - return createInputEntry(); - }), - outputEntry: Array.from(new Array(prev.output?.length ?? 0)).map(() => { - return createOutputEntry(); - }), - annotationEntry: Array.from(new Array(prev.annotation?.length ?? 0)).map(() => { - return { text: { __$$text: "// Your annotations here" } }; - }), - }; - previousExpression.rule = [defaultRowToAdd]; + if (!previousExpression.rule) { + previousExpression.rule = [createDefaultRule()]; } cellUpdates.forEach((cellUpdate) => { const newRules = [...(previousExpression.rule ?? [])]; @@ -749,9 +744,11 @@ export function DecisionTableExpression({ (args: { beforeIndex: number; rowsCount: number }) => { setExpression({ setExpressionAction: (prev: Normalized) => { + if (!prev.rule) { + prev.rule = [createDefaultRule()]; + } const newRules = [...(prev.rule ?? [])]; const newItems: Normalized[] = []; - for (let i = 0; i < args.rowsCount; i++) { newItems.push({ "@_id": generateUuid(),