Skip to content

Commit

Permalink
handling empty decisiontable same as default decisiontable
Browse files Browse the repository at this point in the history
  • Loading branch information
chinnamatli kusumalatha authored and chinnamatli kusumalatha committed Feb 20, 2025
1 parent 8dbb4a1 commit 5a75a1c
Showing 1 changed file with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,26 @@ export function DecisionTableExpression({
widths,
]);

const createDefaultRule = () => {
const defaultRowToAdd: Normalized<DMN15__tDecisionRule> = {
"@_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<DMN15__tDecisionRule>) => {
const ruleRow = [
Expand All @@ -437,43 +457,18 @@ export function DecisionTableExpression({
};
const prevRules = decisionTableExpression.rule ?? [];
if (prevRules.length === 0) {
const defaultRowToAdd: Normalized<DMN15__tDecisionRule> = {
"@_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<ROWTYPE>[]) => {
setExpression({
setExpressionAction: (prev: Normalized<BoxedDecisionTable>) => {
let previousExpression: Normalized<BoxedDecisionTable> = { ...prev };
const isDisplayOnlyRowPresent = previousExpression.rule === undefined ? true : false;
if (isDisplayOnlyRowPresent) {
const defaultRowToAdd: Normalized<DMN15__tDecisionRule> = {
"@_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 ?? [])];
Expand Down Expand Up @@ -749,9 +744,11 @@ export function DecisionTableExpression({
(args: { beforeIndex: number; rowsCount: number }) => {
setExpression({
setExpressionAction: (prev: Normalized<BoxedDecisionTable>) => {
if (!prev.rule) {
prev.rule = [createDefaultRule()];
}
const newRules = [...(prev.rule ?? [])];
const newItems: Normalized<DMN15__tDecisionRule>[] = [];

for (let i = 0; i < args.rowsCount; i++) {
newItems.push({
"@_id": generateUuid(),
Expand Down

0 comments on commit 5a75a1c

Please sign in to comment.