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 1d4a4608e26 kie-issues#235: Implement DMN 1.4 Boxed conditional
expression + fix isNested leaking to DMN model (#2234)
1d4a4608e26 is described below
commit 1d4a4608e260f583ab19d5e67828384fd823cb0d
Author: Daniel José dos Santos <[email protected]>
AuthorDate: Thu Apr 11 18:14:56 2024 -0300
kie-issues#235: Implement DMN 1.4 Boxed conditional expression + fix
isNested leaking to DMN model (#2234)
Co-authored-by: Tiago Bento <[email protected]>
---
.../src/BoxedExpressionEditor.tsx | 4 +
.../src/BoxedExpressionEditorContext.tsx | 3 +
.../ConditionalExpression.tsx | 241 +++++++++++++++++++++
.../ConditionalExpressionCell.tsx | 73 +++++++
.../ContextExpression/ContextExpression.tsx | 53 +++--
.../DecisionTableExpression.tsx | 18 +-
.../ExpressionContainer.tsx | 5 +-
.../ExpressionDefinitionLogicTypeSelector.tsx | 37 +++-
.../FunctionExpression/FeelFunctionExpression.tsx | 8 +-
.../FunctionExpression/FunctionExpression.tsx | 5 +-
.../FunctionExpression/JavaFunctionExpression.tsx | 9 +-
.../InvocationExpression/InvocationExpression.tsx | 49 ++---
.../expressions/ListExpression/ListExpression.tsx | 27 ++-
.../LiteralExpression/LiteralExpression.tsx | 32 ++-
.../RelationExpression/RelationExpression.tsx | 21 +-
.../src/resizing/WidthConstants.ts | 10 +-
.../src/resizing/WidthMaths.ts | 148 +++++++++----
.../src/table/BeeTable/BeeTableReadOnlyCell.tsx | 53 +++++
.../dev/getDefaultBoxedExpressionForDevWebapp.ts | 75 +++++++
.../boxedExpressions/getDefaultBoxedExpression.tsx | 75 +++++++
packages/stunner-editors-dmn-loader/src/index.tsx | 5 +
21 files changed, 791 insertions(+), 160 deletions(-)
diff --git a/packages/boxed-expression-component/src/BoxedExpressionEditor.tsx
b/packages/boxed-expression-component/src/BoxedExpressionEditor.tsx
index 58cae119d24..30e4a095b4a 100644
--- a/packages/boxed-expression-component/src/BoxedExpressionEditor.tsx
+++ b/packages/boxed-expression-component/src/BoxedExpressionEditor.tsx
@@ -61,6 +61,8 @@ export interface BoxedExpressionEditorProps {
scrollableParentRef: React.RefObject<HTMLElement>;
/** Parsed variables used for syntax coloring and auto-complete */
onRequestFeelVariables?: OnRequestFeelVariables;
+ /** Hide DMN 1.4 boxed expressions */
+ hideDmn14BoxedExpressions?: boolean;
}
export function BoxedExpressionEditor({
@@ -77,6 +79,7 @@ export function BoxedExpressionEditor({
onRequestFeelVariables,
widthsById,
onWidthsChange,
+ hideDmn14BoxedExpressions,
}: BoxedExpressionEditorProps) {
return (
<I18nDictionariesProvider
@@ -98,6 +101,7 @@ export function BoxedExpressionEditor({
pmmlDocuments={pmmlDocuments}
onRequestFeelVariables={onRequestFeelVariables}
widthsById={widthsById}
+ hideDmn14BoxedExpressions={hideDmn14BoxedExpressions}
>
<ExpressionDefinitionRoot
expressionHolderId={expressionHolderId}
diff --git
a/packages/boxed-expression-component/src/BoxedExpressionEditorContext.tsx
b/packages/boxed-expression-component/src/BoxedExpressionEditorContext.tsx
index 4617d69b961..f7ad8ac3ead 100644
--- a/packages/boxed-expression-component/src/BoxedExpressionEditorContext.tsx
+++ b/packages/boxed-expression-component/src/BoxedExpressionEditorContext.tsx
@@ -41,6 +41,7 @@ export interface BoxedExpressionEditorContextType {
onRequestFeelVariables?: OnRequestFeelVariables;
widthsById: Map<string, number[]>;
+ hideDmn14BoxedExpressions?: boolean;
}
export interface BoxedExpressionEditorDispatchContextType {
@@ -75,6 +76,7 @@ export function BoxedExpressionEditorContextProvider({
scrollableParentRef,
onRequestFeelVariables,
widthsById,
+ hideDmn14BoxedExpressions,
}: React.PropsWithChildren<BoxedExpressionEditorProps>) {
const [currentlyOpenContextMenu, setCurrentlyOpenContextMenu] =
useState<string | undefined>(undefined);
@@ -116,6 +118,7 @@ export function BoxedExpressionEditorContextProvider({
setCurrentlyOpenContextMenu,
onRequestFeelVariables,
widthsById,
+ hideDmn14BoxedExpressions,
}}
>
<BoxedExpressionEditorDispatchContext.Provider value={dispatch}>
diff --git
a/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpression.tsx
b/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpression.tsx
new file mode 100644
index 00000000000..30651a27289
--- /dev/null
+++
b/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpression.tsx
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {
+ BeeTableHeaderVisibility,
+ BeeTableOperation,
+ BeeTableOperationConfig,
+ BeeTableProps,
+ BoxedConditional,
+ DmnBuiltInDataType,
+} from "../../api";
+import { BeeTable, BeeTableColumnUpdate } from "../../table/BeeTable";
+import { ResizerStopBehavior } from "../../resizing/ResizingWidthsContext";
+import React, { useCallback, useMemo } from "react";
+import { DMN15__tChildExpression } from
"@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types";
+import * as ReactTable from "react-table";
+import { useBoxedExpressionEditorI18n } from "../../i18n";
+import { BeeTableReadOnlyCell } from
"../../table/BeeTable/BeeTableReadOnlyCell";
+import { ConditionalExpressionCell } from "./ConditionalExpressionCell";
+import { DEFAULT_EXPRESSION_VARIABLE_NAME } from
"../../expressionVariable/ExpressionVariableMenu";
+import { useBoxedExpressionEditor, useBoxedExpressionEditorDispatch } from
"../../BoxedExpressionEditorContext";
+import { NestedExpressionContainerContext } from
"../../resizing/NestedExpressionContainerContext";
+import { useNestedExpressionContainerWithNestedExpressions } from
"../../resizing/Hooks";
+import {
+ CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ CONDITIONAL_EXPRESSION_EXTRA_WIDTH,
+ CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
+} from "../../resizing/WidthConstants";
+
+export type ROWTYPE = ConditionalClause;
+
+export type ConditionalClause = {
+ part: DMN15__tChildExpression;
+ label: string;
+};
+
+export function ConditionalExpression({
+ isNested,
+ parentElementId,
+ expression: conditionalExpression,
+}: {
+ expression: BoxedConditional;
+ isNested: boolean;
+ parentElementId: string;
+}) {
+ const { i18n } = useBoxedExpressionEditorI18n();
+ const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
+ const { setExpression } = useBoxedExpressionEditorDispatch();
+
+ const tableRows = useMemo<ROWTYPE[]>(() => {
+ return [
+ { label: "if", part: conditionalExpression.if },
+ { label: "then", part: conditionalExpression.then },
+ { label: "else", part: conditionalExpression.else },
+ ];
+ }, [conditionalExpression.else, conditionalExpression.if,
conditionalExpression.then]);
+
+ const cellComponentByColumnAccessor:
BeeTableProps<ROWTYPE>["cellComponentByColumnAccessor"] = useMemo(() => {
+ return {
+ label: (props) => {
+ return <BeeTableReadOnlyCell value={props.data[props.rowIndex].label}
/>;
+ },
+ part: (props) => {
+ return <ConditionalExpressionCell {...props}
parentElementId={parentElementId} />;
+ },
+ };
+ }, [parentElementId]);
+ const id = conditionalExpression["@_id"]!;
+
+ const tableColumns = useMemo<ReactTable.Column<ROWTYPE>[]>(() => {
+ return [
+ {
+ accessor: expressionHolderId as any, // FIXME:
https://github.com/kiegroup/kie-issues/issues/169
+ label: conditionalExpression["@_label"] ??
DEFAULT_EXPRESSION_VARIABLE_NAME,
+ isRowIndexColumn: false,
+ dataType: conditionalExpression["@_typeRef"] ??
DmnBuiltInDataType.Undefined,
+ width: undefined,
+ columns: [
+ {
+ accessor: "label",
+ label: "label",
+ width: CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
+ minWidth: CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
+ isInlineEditable: false,
+ isRowIndexColumn: false,
+ isWidthPinned: true,
+ isWidthConstant: true,
+ dataType: undefined as any,
+ },
+ {
+ accessor: "part",
+ label: "part",
+ width: undefined,
+ minWidth: CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ isInlineEditable: false,
+ isRowIndexColumn: false,
+ dataType: undefined as any,
+ },
+ ],
+ },
+ ];
+ }, [conditionalExpression, expressionHolderId]);
+
+ const headerVisibility = useMemo(() => {
+ return isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.SecondToLastLevel;
+ }, [isNested]);
+
+ /// //////////////////////////////////////////////////////
+ /// ///////////// RESIZING WIDTHS ////////////////////////
+ /// //////////////////////////////////////////////////////
+
+ const { nestedExpressionContainerValue, onColumnResizingWidthChange:
onColumnResizingWidthChange } =
+ useNestedExpressionContainerWithNestedExpressions(
+ useMemo(() => {
+ const nestedExpressions = [
+ conditionalExpression.if.expression,
+ conditionalExpression.then.expression,
+ conditionalExpression.else.expression,
+ ];
+
+ return {
+ nestedExpressions: nestedExpressions,
+ fixedColumnActualWidth: CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
+ fixedColumnResizingWidth: { value:
CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH, isPivoting: false },
+ fixedColumnMinWidth: CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
+ nestedExpressionMinWidth:
CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ extraWidth: CONDITIONAL_EXPRESSION_EXTRA_WIDTH,
+ expression: conditionalExpression,
+ flexibleColumnIndex: 2,
+ widthsById: widthsById,
+ };
+ }, [conditionalExpression, widthsById])
+ );
+
+ /// //////////////////////////////////////////////////////
+
+ const allowedOperations = useCallback(() => {
+ return [BeeTableOperation.SelectionCopy, BeeTableOperation.RowReset];
+ }, []);
+
+ const beeTableOperationConfig = useMemo<BeeTableOperationConfig>(() => {
+ return [
+ {
+ group: i18n.contextEntry,
+ items: [{ name: i18n.rowOperations.reset, type:
BeeTableOperation.RowReset }],
+ },
+ {
+ group: i18n.terms.selection.toUpperCase(),
+ items: [{ name: i18n.terms.copy, type: BeeTableOperation.SelectionCopy
}],
+ },
+ ];
+ }, [i18n]);
+
+ const onRowReset = useCallback(
+ (args: { rowIndex: number }) => {
+ setExpression((prev: BoxedConditional) => {
+ if (args.rowIndex === 0) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ if: { expression: undefined! }, // SPEC DISCREPANCY
+ };
+ return ret;
+ } else if (args.rowIndex === 1) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ then: { expression: undefined! }, // SPEC DISCREPANCY
+ };
+ return ret;
+ } else if (args.rowIndex === 2) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ else: { expression: undefined! }, // SPEC DISCREPANCY
+ };
+ return ret;
+ } else {
+ throw new Error("ConditionalExpression shouldn't have more than 3
rows.");
+ }
+ });
+ },
+ [setExpression]
+ );
+
+ const onColumnUpdates = useCallback(
+ ([{ name, typeRef }]: BeeTableColumnUpdate<ROWTYPE>[]) => {
+ setExpression((prev: BoxedConditional) => {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ "@_label": name,
+ "@_typeRef": typeRef,
+ };
+
+ return ret;
+ });
+ },
+ [setExpression]
+ );
+
+ return (
+ <NestedExpressionContainerContext.Provider
value={nestedExpressionContainerValue}>
+ <div>
+ <BeeTable<ROWTYPE>
+ resizerStopBehavior={ResizerStopBehavior.SET_WIDTH_WHEN_SMALLER}
+ tableId={id}
+ headerLevelCountForAppendingRowIndexColumn={1}
+ headerVisibility={headerVisibility}
+ cellComponentByColumnAccessor={cellComponentByColumnAccessor}
+ columns={tableColumns}
+ rows={tableRows}
+ operationConfig={beeTableOperationConfig}
+ allowedOperations={allowedOperations}
+ onColumnUpdates={onColumnUpdates}
+ onRowReset={onRowReset}
+ onColumnResizingWidthChange={onColumnResizingWidthChange}
+ shouldRenderRowIndexColumn={false}
+ shouldShowRowsInlineControls={false}
+ shouldShowColumnsInlineControls={false}
+ />
+ </div>
+ </NestedExpressionContainerContext.Provider>
+ );
+}
diff --git
a/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpressionCell.tsx
b/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpressionCell.tsx
new file mode 100644
index 00000000000..c50aa319963
--- /dev/null
+++
b/packages/boxed-expression-component/src/expressions/ConditionalExpression/ConditionalExpressionCell.tsx
@@ -0,0 +1,73 @@
+import { BeeTableCellProps, BoxedConditional } from "../../api";
+
+import {
+ NestedExpressionDispatchContextProvider,
+ OnSetExpression,
+ useBoxedExpressionEditorDispatch,
+} from "../../BoxedExpressionEditorContext";
+import * as React from "react";
+import { useCallback } from "react";
+import { ExpressionContainer } from
"../ExpressionDefinitionRoot/ExpressionContainer";
+import { ConditionalClause, ROWTYPE } from "./ConditionalExpression";
+
+export interface ConditionalExpressionCellProps {
+ conditionalClause: ConditionalClause;
+ rowIndex: number;
+ columnIndex: number;
+ columnId: string;
+}
+
+export function ConditionalExpressionCell({
+ data,
+ rowIndex,
+ columnIndex,
+ parentElementId,
+}: BeeTableCellProps<ROWTYPE> & { parentElementId: string }) {
+ const { setExpression } = useBoxedExpressionEditorDispatch();
+
+ const onSetExpression = useCallback<OnSetExpression>(
+ ({ getNewExpression }) => {
+ setExpression((prev: BoxedConditional) => {
+ if (rowIndex === 0) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ if: { ...prev.if, expression:
getNewExpression(prev.if.expression)! },
+ };
+ return ret;
+ } else if (rowIndex === 1) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ then: { ...prev.then, expression:
getNewExpression(prev.then.expression)! },
+ };
+ return ret;
+ } else if (rowIndex === 2) {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedConditional = {
+ ...prev,
+ else: { ...prev.else, expression:
getNewExpression(prev.else.expression)! },
+ };
+ return ret;
+ } else {
+ throw new Error("ConditionalExpression shouldn't have more than 3
rows.");
+ }
+ });
+ },
+ [rowIndex, setExpression]
+ );
+
+ return (
+ <NestedExpressionDispatchContextProvider onSetExpression={onSetExpression}>
+ <ExpressionContainer
+ expression={data[rowIndex].part.expression}
+ isResetSupported={true}
+ isNested={true}
+ rowIndex={rowIndex}
+ columnIndex={columnIndex}
+ parentElementId={parentElementId}
+ parentElementTypeRef={undefined}
+ />
+ </NestedExpressionDispatchContextProvider>
+ );
+}
diff --git
a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx
b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx
index b40d738a6e6..ba0e79e5835 100644
---
a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx
@@ -35,10 +35,11 @@ import {
import { useBoxedExpressionEditorI18n } from "../../i18n";
import { useNestedExpressionContainerWithNestedExpressions } from
"../../resizing/Hooks";
import { NestedExpressionContainerContext } from
"../../resizing/NestedExpressionContainerContext";
-import { ResizerStopBehavior, ResizingWidth } from
"../../resizing/ResizingWidthsContext";
+import { ResizerStopBehavior, ResizingWidth, useResizingWidths } from
"../../resizing/ResizingWidthsContext";
import {
CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH,
CONTEXT_ENTRY_VARIABLE_MIN_WIDTH,
+ CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX,
CONTEXT_EXPRESSION_EXTRA_WIDTH,
} from "../../resizing/WidthConstants";
import { useBeeTableCoordinates, useBeeTableSelectableCellRef } from
"../../selection/BeeTableSelectionContext";
@@ -48,22 +49,24 @@ import { DEFAULT_EXPRESSION_VARIABLE_NAME } from
"../../expressionVariable/Expre
import { ContextEntryExpressionCell } from "./ContextEntryExpressionCell";
import { ExpressionVariableCell, ExpressionWithVariable } from
"../../expressionVariable/ExpressionVariableCell";
import { ContextResultExpressionCell } from "./ContextResultExpressionCell";
-import { getExpressionTotalMinWidth } from "../../resizing/WidthMaths";
+import { getExpressionMinWidth, getExpressionTotalMinWidth } from
"../../resizing/WidthMaths";
import { DMN15__tContextEntry } from
"@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types";
import { findAllIdsDeep } from "../../ids/ids";
import "./ContextExpression.css";
const CONTEXT_ENTRY_DEFAULT_DATA_TYPE = DmnBuiltInDataType.Undefined;
-const CONTEXT_ENTRY_VARIABLE_WIDTH_INDEX = 0;
export type ROWTYPE = ExpressionWithVariable & { index: number };
-export function ContextExpression(
- contextExpression: BoxedContext & {
- isNested: boolean;
- parentElementId: string;
- }
-) {
+export function ContextExpression({
+ isNested,
+ parentElementId,
+ expression: contextExpression,
+}: {
+ expression: BoxedContext;
+ isNested: boolean;
+ parentElementId: string;
+}) {
const { i18n } = useBoxedExpressionEditorI18n();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
@@ -73,7 +76,7 @@ export function ContextExpression(
const widths = useMemo(() => widthsById.get(id) ?? [], [id, widthsById]);
const getEntryVariableWidth = useCallback(
- (widths: number[]) => widths?.[CONTEXT_ENTRY_VARIABLE_WIDTH_INDEX] ??
CONTEXT_ENTRY_VARIABLE_MIN_WIDTH,
+ (widths: number[]) => widths?.[CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX]
?? CONTEXT_ENTRY_VARIABLE_MIN_WIDTH,
[]
);
@@ -87,10 +90,10 @@ export function ContextExpression(
typeof newWidthAction === "function" ?
newWidthAction(getEntryVariableWidth(prev)) : newWidthAction;
if (newWidth) {
- const minSize = CONTEXT_ENTRY_VARIABLE_WIDTH_INDEX + 1;
+ const minSize = CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX + 1;
const newValues = [...prev];
newValues.push(...Array(Math.max(0, minSize - newValues.length)));
- newValues.splice(CONTEXT_ENTRY_VARIABLE_WIDTH_INDEX, 1, newWidth);
+ newValues.splice(CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX, 1,
newWidth);
newMap.set(id, newValues);
}
});
@@ -113,34 +116,28 @@ export function ContextExpression(
/// //////////////////////////////////////////////////////
/// ///////////// RESIZING WIDTHS ////////////////////////
/// //////////////////////////////////////////////////////
-
- const resultExpression = useMemo(
- () => contextExpression.contextEntry?.find((e) => !e.variable)?.expression,
- [contextExpression.contextEntry]
- );
-
const { nestedExpressionContainerValue, onColumnResizingWidthChange:
onColumnResizingWidthChange2 } =
useNestedExpressionContainerWithNestedExpressions(
useMemo(() => {
- const entriesWidths = (contextExpression.contextEntry ?? []).map((e) =>
- getExpressionTotalMinWidth(0, e.expression, widthsById)
- );
+ const nestedExpressions = (contextExpression.contextEntry ??
[]).map((e) => e.expression);
- const resultWidth = getExpressionTotalMinWidth(0, resultExpression,
widthsById);
- const maxNestedExpressionMinWidth = Math.max(...entriesWidths,
resultWidth, CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH);
+ const maxNestedExpressionTotalMinWidth = Math.max(
+ ...nestedExpressions.map((e) => getExpressionTotalMinWidth(0, e,
widthsById)),
+ CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH
+ );
return {
- nestedExpressions: (contextExpression.contextEntry ?? []).map((e) =>
e.expression),
+ nestedExpressions: nestedExpressions,
fixedColumnActualWidth: entryVariableWidth,
fixedColumnResizingWidth: entryVariableResizingWidth,
fixedColumnMinWidth: CONTEXT_ENTRY_VARIABLE_MIN_WIDTH,
- nestedExpressionMinWidth: maxNestedExpressionMinWidth,
+ nestedExpressionMinWidth: maxNestedExpressionTotalMinWidth,
extraWidth: CONTEXT_EXPRESSION_EXTRA_WIDTH,
expression: contextExpression,
flexibleColumnIndex: 2,
widthsById: widthsById,
};
- }, [contextExpression, entryVariableResizingWidth, entryVariableWidth,
resultExpression, widthsById])
+ }, [contextExpression, entryVariableResizingWidth, entryVariableWidth,
widthsById])
);
/// //////////////////////////////////////////////////////
@@ -202,8 +199,8 @@ export function ContextExpression(
);
const headerVisibility = useMemo(() => {
- return contextExpression.isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.SecondToLastLevel;
- }, [contextExpression.isNested]);
+ return isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.SecondToLastLevel;
+ }, [isNested]);
const updateVariable = useCallback(
(index: number, { expression, variable }: ExpressionWithVariable) => {
diff --git
a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
index b6cd22d32e9..9b78b091e1a 100644
---
a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx
@@ -99,9 +99,15 @@ function createAnnotationEntry():
Unpacked<DMN15__tDecisionRule["annotationEntry
};
}
-export function DecisionTableExpression(
- decisionTableExpression: BoxedDecisionTable & { isNested: boolean;
parentElementId: string }
-) {
+export function DecisionTableExpression({
+ isNested,
+ parentElementId,
+ expression: decisionTableExpression,
+}: {
+ expression: BoxedDecisionTable;
+ isNested: boolean;
+ parentElementId: string;
+}) {
const { i18n } = useBoxedExpressionEditorI18n();
const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
@@ -309,7 +315,7 @@ export function DecisionTableExpression(
useApportionedColumnWidthsIfNestedTable(
beeTableRef,
isPivoting,
- decisionTableExpression.isNested,
+ isNested,
BEE_TABLE_ROW_INDEX_COLUMN_WIDTH,
columns,
columnResizingWidths,
@@ -977,8 +983,8 @@ export function DecisionTableExpression(
);
const beeTableHeaderVisibility = useMemo(() => {
- return decisionTableExpression.isNested ?
BeeTableHeaderVisibility.LastLevel : BeeTableHeaderVisibility.AllLevels;
- }, [decisionTableExpression.isNested]);
+ return isNested ? BeeTableHeaderVisibility.LastLevel :
BeeTableHeaderVisibility.AllLevels;
+ }, [isNested]);
const allowedOperations = useCallback(
(conditions: BeeTableContextMenuAllowedOperationsConditions) => {
diff --git
a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx
b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx
index 378e3177964..884d9c10b4d 100644
---
a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx
+++
b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx
@@ -20,7 +20,7 @@
import * as React from "react";
import { useCallback, useEffect, useRef } from "react";
import { useBoxedExpressionEditor, useBoxedExpressionEditorDispatch } from
"../../BoxedExpressionEditorContext";
-import { BoxedContext, BoxedExpression, DmnBuiltInDataType, generateUuid }
from "../../api";
+import { BoxedExpression, DmnBuiltInDataType, generateUuid } from "../../api";
import { findAllIdsDeep } from "../../ids/ids";
import { DEFAULT_EXPRESSION_VARIABLE_NAME } from
"../../expressionVariable/ExpressionVariableMenu";
import { useBeeTableSelectableCellRef } from
"../../selection/BeeTableSelectionContext";
@@ -49,7 +49,7 @@ export const ExpressionContainer:
React.FunctionComponent<ExpressionContainerPro
}) => {
const containerRef = useRef<HTMLDivElement>(null);
- const { beeGwtService, expressionHolderId } = useBoxedExpressionEditor();
+ const { beeGwtService, expressionHolderId, hideDmn14BoxedExpressions } =
useBoxedExpressionEditor();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
const { isActive } = useBeeTableSelectableCellRef(rowIndex, columnIndex,
undefined);
@@ -112,6 +112,7 @@ export const ExpressionContainer:
React.FunctionComponent<ExpressionContainerPro
isResetSupported={isResetSupported}
isNested={isNested}
parentElementId={parentElementId ?? expressionHolderId}
+ hideDmn14BoxedExpressions={hideDmn14BoxedExpressions}
/>
</div>
);
diff --git
a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector.tsx
b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector.tsx
index e162363f0df..36911234637 100644
---
a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector.tsx
+++
b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector.tsx
@@ -53,6 +53,7 @@ import {
import { findAllIdsDeep, mutateExpressionRandomizingIds } from "../../ids/ids";
import "./ExpressionDefinitionLogicTypeSelector.css";
import { NavigationKeysUtils } from "../../keysUtils/keyUtils";
+import { ConditionalExpression } from
"../ConditionalExpression/ConditionalExpression";
export interface ExpressionDefinitionLogicTypeSelectorProps {
/** Expression properties */
@@ -66,6 +67,7 @@ export interface ExpressionDefinitionLogicTypeSelectorProps {
isResetSupported: boolean;
isNested: boolean;
parentElementId: string;
+ hideDmn14BoxedExpressions?: boolean;
}
export function ExpressionDefinitionLogicTypeSelector({
@@ -76,6 +78,7 @@ export function ExpressionDefinitionLogicTypeSelector({
isResetSupported,
isNested,
parentElementId,
+ hideDmn14BoxedExpressions,
}: ExpressionDefinitionLogicTypeSelectorProps) {
const nonSelectableLogicTypes = useMemo<Set<BoxedExpression["__$$element"] |
undefined>>(
() => (isNested ? new Set([undefined]) : new Set([undefined,
"functionDefinition"])),
@@ -91,13 +94,13 @@ export function ExpressionDefinitionLogicTypeSelector({
"list",
"invocation",
...(isNested ? (["functionDefinition"] as const) : []),
+ ...(!hideDmn14BoxedExpressions ? (["conditional"] as const) : []),
// "for",
// "every",
// "some",
- // "conditional",
// "filter",
],
- [isNested]
+ [hideDmn14BoxedExpressions, isNested]
);
const { i18n } = useBoxedExpressionEditorI18n();
@@ -111,23 +114,26 @@ export function ExpressionDefinitionLogicTypeSelector({
}
switch (logicType) {
case "literalExpression":
- return <LiteralExpression {...expression} isNested={isNested} />;
+ return <LiteralExpression expression={expression} isNested={isNested}
/>;
case "relation":
- return <RelationExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return <RelationExpression expression={expression} isNested={isNested}
parentElementId={parentElementId} />;
case "context":
- return <ContextExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return <ContextExpression expression={expression} isNested={isNested}
parentElementId={parentElementId} />;
case "decisionTable":
- return <DecisionTableExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return (
+ <DecisionTableExpression expression={expression} isNested={isNested}
parentElementId={parentElementId} />
+ );
case "list":
- return <ListExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return <ListExpression expression={expression} isNested={isNested}
parentElementId={parentElementId} />;
case "invocation":
- return <InvocationExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return <InvocationExpression expression={expression}
isNested={isNested} parentElementId={parentElementId} />;
case "functionDefinition":
- return <FunctionExpression {...expression} isNested={isNested}
parentElementId={parentElementId} />;
+ return <FunctionExpression expression={expression} isNested={isNested}
parentElementId={parentElementId} />;
+ case "conditional":
+ return <ConditionalExpression expression={expression}
isNested={isNested} parentElementId={parentElementId} />;
case "for":
case "every":
case "some":
- case "conditional":
case "filter":
return <></>;
default:
@@ -220,10 +226,17 @@ export function ExpressionDefinitionLogicTypeSelector({
);
case "list":
return <ListIcon />;
+ case "conditional":
+ return (
+ <span>
+ <b>
+ <i>{"if"}</i>
+ </b>
+ </span>
+ );
case "for":
case "every":
case "some":
- case "conditional":
case "filter":
return <></>;
default:
@@ -315,6 +328,8 @@ export function ExpressionDefinitionLogicTypeSelector({
return "A boxed invocation expression in DMN is a boxed expression
that invokes a business knowledge model. A boxed invocation expression contains
the name of the business knowledge model to be invoked and a list of parameter
bindings.";
case "list":
return "A boxed list expression in DMN represents a FEEL list of
items. You use boxed lists to define lists of relevant items for a particular
node in a decision.";
+ case "conditional":
+ return 'A boxed conditional offers a visual representation of an if
statement using three rows. The expression in the "if" part MUST resolve to a
boolean.';
default:
return "";
}
diff --git
a/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx
b/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx
index 6017fee9fb7..4f1e4954e96 100644
---
a/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx
@@ -37,8 +37,8 @@ import { useNestedExpressionContainerWithNestedExpressions }
from "../../resizin
import { NestedExpressionContainerContext } from
"../../resizing/NestedExpressionContainerContext";
import { ResizerStopBehavior } from "../../resizing/ResizingWidthsContext";
import {
- CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH,
FEEL_FUNCTION_EXPRESSION_EXTRA_WIDTH,
+ FEEL_FUNCTION_EXPRESSION_MIN_WIDTH,
} from "../../resizing/WidthConstants";
import { BeeTable, BeeTableColumnUpdate } from "../../table/BeeTable";
import {
@@ -166,12 +166,14 @@ export function FeelFunctionExpression({
const { nestedExpressionContainerValue, onColumnResizingWidthChange } =
useNestedExpressionContainerWithNestedExpressions(
useMemo(() => {
+ const nestedExpressions = [functionExpression.expression ??
undefined!];
+
return {
- nestedExpressions: [functionExpression.expression ?? undefined!],
+ nestedExpressions: nestedExpressions,
fixedColumnActualWidth: 0,
fixedColumnResizingWidth: { value: 0, isPivoting: false },
fixedColumnMinWidth: 0,
- nestedExpressionMinWidth: CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH,
+ nestedExpressionMinWidth: FEEL_FUNCTION_EXPRESSION_MIN_WIDTH,
extraWidth: FEEL_FUNCTION_EXPRESSION_EXTRA_WIDTH,
expression: functionExpression,
flexibleColumnIndex: 1,
diff --git
a/packages/boxed-expression-component/src/expressions/FunctionExpression/FunctionExpression.tsx
b/packages/boxed-expression-component/src/expressions/FunctionExpression/FunctionExpression.tsx
index 42f93f21abe..5875422b6c4 100644
---
a/packages/boxed-expression-component/src/expressions/FunctionExpression/FunctionExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/FunctionExpression/FunctionExpression.tsx
@@ -38,11 +38,12 @@ import "./FunctionExpression.css";
export function FunctionExpression({
isNested,
parentElementId,
- ...boxedFunction
+ expression: boxedFunction,
}: {
+ expression: BoxedFunction;
isNested: boolean;
parentElementId: string;
-} & BoxedFunction) {
+}) {
switch (boxedFunction["@_kind"]) {
case "Java":
return (
diff --git
a/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx
b/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx
index 520e4a83d11..0d7006e6744 100644
---
a/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx
@@ -41,6 +41,7 @@ import { ResizerStopBehavior } from
"../../resizing/ResizingWidthsContext";
import {
JAVA_FUNCTION_EXPRESSION_EXTRA_WIDTH,
JAVA_FUNCTION_EXPRESSION_LABEL_MIN_WIDTH,
+ JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX,
JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH,
} from "../../resizing/WidthConstants";
import { useBeeTableSelectableCellRef } from
"../../selection/BeeTableSelectionContext";
@@ -65,8 +66,6 @@ export type BoxedFunctionJava = DMN15__tFunctionDefinition & {
__$$element: "functionDefinition";
};
-const JAVA_FUNCTION_CLASS_AND_METHOD_NAMES_WIDTH_INDEX = 2; // 0 is the
rowIndex column, 1 is the label column.
-
export function JavaFunctionExpression({
functionExpression,
isNested,
@@ -93,7 +92,7 @@ export function JavaFunctionExpression({
const widths = useMemo(() => widthsById.get(id) ?? [], [id, widthsById]);
const getClassAndMethodNamesWidth = useCallback((widths: number[]) => {
- return widths[JAVA_FUNCTION_CLASS_AND_METHOD_NAMES_WIDTH_INDEX] ??
JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH;
+ return widths[JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX] ??
JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH;
}, []);
const classAndMethodNamesWidth = useMemo(
@@ -109,10 +108,10 @@ export function JavaFunctionExpression({
typeof newWidthAction === "function" ?
newWidthAction(getClassAndMethodNamesWidth(prev)) : newWidthAction;
if (newWidth) {
- const minSize = JAVA_FUNCTION_CLASS_AND_METHOD_NAMES_WIDTH_INDEX + 1;
+ const minSize = JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX +
1;
const newValues = [...prev];
newValues.push(...Array(Math.max(0, minSize - newValues.length)));
- newValues.splice(JAVA_FUNCTION_CLASS_AND_METHOD_NAMES_WIDTH_INDEX,
1, newWidth);
+ newValues.splice(JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX,
1, newWidth);
newMap.set(id, newValues);
}
});
diff --git
a/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx
b/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx
index b1c626055d1..215b2a5fb9f 100644
---
a/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx
@@ -40,6 +40,7 @@ import {
INVOCATION_PARAMETER_MIN_WIDTH,
INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH,
INVOCATION_EXTRA_WIDTH,
+ INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX,
} from "../../resizing/WidthConstants";
import { BeeTable, BeeTableColumnUpdate } from "../../table/BeeTable";
import { useBoxedExpressionEditor, useBoxedExpressionEditorDispatch } from
"../../BoxedExpressionEditorContext";
@@ -57,14 +58,15 @@ export type ROWTYPE = ExpressionWithVariable & { index:
number };
export const INVOCATION_EXPRESSION_DEFAULT_PARAMETER_NAME = "p-1";
export const INVOCATION_EXPRESSION_DEFAULT_PARAMETER_DATA_TYPE =
DmnBuiltInDataType.Undefined;
-export const INVOCATION_PARAMETER_INFO_WIDTH_INDEX = 0;
-
-export function InvocationExpression(
- invocationExpression: BoxedInvocation & {
- isNested: boolean;
- parentElementId: string;
- }
-) {
+export function InvocationExpression({
+ isNested,
+ parentElementId,
+ expression: invocationExpression,
+}: {
+ expression: BoxedInvocation;
+ isNested: boolean;
+ parentElementId: string;
+}) {
const { i18n } = useBoxedExpressionEditorI18n();
const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
@@ -74,7 +76,7 @@ export function InvocationExpression(
const widths = useMemo(() => widthsById.get(id) ?? [], [id, widthsById]);
const getParametersWidth = useCallback((widths: number[]) => {
- return widths?.[INVOCATION_PARAMETER_INFO_WIDTH_INDEX] ??
INVOCATION_PARAMETER_MIN_WIDTH;
+ return widths?.[INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX] ??
INVOCATION_PARAMETER_MIN_WIDTH;
}, []);
const parametersWidth = useMemo(() => getParametersWidth(widths),
[getParametersWidth, widths]);
@@ -87,10 +89,10 @@ export function InvocationExpression(
typeof newWidthAction === "function" ?
newWidthAction(getParametersWidth(prev)) : newWidthAction;
if (newWidth) {
- const minSize = INVOCATION_PARAMETER_INFO_WIDTH_INDEX + 1;
+ const minSize = INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX + 1;
const newValues = [...prev];
newValues.push(...Array(Math.max(0, minSize - newValues.length)));
- newValues.splice(INVOCATION_PARAMETER_INFO_WIDTH_INDEX, 1, newWidth);
+ newValues.splice(INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX, 1,
newWidth);
newMap.set(id, newValues);
}
});
@@ -117,19 +119,19 @@ export function InvocationExpression(
const { nestedExpressionContainerValue, onColumnResizingWidthChange:
onColumnResizingWidthChange2 } =
useNestedExpressionContainerWithNestedExpressions(
useMemo(() => {
- const bindingWidths =
- invocationExpression.binding?.map((e) =>
getExpressionTotalMinWidth(0, e.expression!, widthsById)) ?? [];
-
- const maxNestedExpressionWidth = Math.max(...bindingWidths,
INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH);
+ const nestedExpressions = (invocationExpression.binding ?? []).map((b)
=> b.expression ?? undefined!);
- const nestedExpressions = (invocationExpression.binding ?? []).map((b)
=> b.expression!);
+ const maxNestedExpressionTotalMinWidth = Math.max(
+ ...nestedExpressions.map((e) => getExpressionTotalMinWidth(0, e,
widthsById)),
+ INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH
+ );
return {
- nestedExpressions: nestedExpressions ?? [],
+ nestedExpressions: nestedExpressions,
fixedColumnActualWidth: parametersWidth,
fixedColumnResizingWidth: parametersResizingWidth,
fixedColumnMinWidth: INVOCATION_PARAMETER_MIN_WIDTH,
- nestedExpressionMinWidth: maxNestedExpressionWidth,
+ nestedExpressionMinWidth: maxNestedExpressionTotalMinWidth,
extraWidth: INVOCATION_EXTRA_WIDTH,
expression: invocationExpression,
flexibleColumnIndex: 2,
@@ -239,9 +241,8 @@ export function InvocationExpression(
);
const headerVisibility = useMemo(
- () =>
- invocationExpression.isNested ?
BeeTableHeaderVisibility.SecondToLastLevel : BeeTableHeaderVisibility.AllLevels,
- [invocationExpression.isNested]
+ () => (isNested ? BeeTableHeaderVisibility.SecondToLastLevel :
BeeTableHeaderVisibility.AllLevels),
+ [isNested]
);
const getRowKey = useCallback((row: ReactTable.Row<ROWTYPE>) => {
@@ -271,11 +272,9 @@ export function InvocationExpression(
const cellComponentByColumnAccessor:
BeeTableProps<ROWTYPE>["cellComponentByColumnAccessor"] = useMemo(
() => ({
parameter: (props) => <ExpressionVariableCell {...props}
onExpressionWithVariableUpdated={updateParameter} />,
- expression: (props) => (
- <ArgumentEntryExpressionCell {...props}
parentElementId={invocationExpression.parentElementId} />
- ),
+ expression: (props) => <ArgumentEntryExpressionCell {...props}
parentElementId={parentElementId} />,
}),
- [invocationExpression.parentElementId, updateParameter]
+ [parentElementId, updateParameter]
);
const beeTableOperationConfig = useMemo<BeeTableOperationConfig>(() => {
diff --git
a/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx
b/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx
index 5e20fbde203..569629d9783 100644
---
a/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx
@@ -47,12 +47,15 @@ import "./ListExpression.css";
export type ROWTYPE = DMN15__tContextEntry;
-export function ListExpression(
- listExpression: BoxedList & {
- isNested: boolean;
- parentElementId: string;
- }
-) {
+export function ListExpression({
+ isNested,
+ parentElementId,
+ expression: listExpression,
+}: {
+ expression: BoxedList;
+ isNested: boolean;
+ parentElementId: string;
+}) {
const { i18n } = useBoxedExpressionEditorI18n();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
@@ -64,8 +67,10 @@ export function ListExpression(
const { nestedExpressionContainerValue, onColumnResizingWidthChange } =
useNestedExpressionContainerWithNestedExpressions(
useMemo(() => {
+ const nestedExpressions = listExpression.expression ?? [];
+
return {
- nestedExpressions: listExpression.expression ?? [],
+ nestedExpressions: nestedExpressions,
fixedColumnActualWidth: 0,
fixedColumnResizingWidth: { value: 0, isPivoting: false },
fixedColumnMinWidth: 0,
@@ -140,10 +145,10 @@ export function ListExpression(
const cellComponentByColumnAccessor:
BeeTableProps<ROWTYPE>["cellComponentByColumnAccessor"] = useMemo(
(): { [p: string]: ({ rowIndex, data, columnIndex }:
BeeTableCellProps<ROWTYPE>) => JSX.Element } => ({
[expressionHolderId]: (props) => (
- <ListItemCell parentElementId={listExpression.parentElementId}
listExpression={listExpression} {...props} />
+ <ListItemCell parentElementId={parentElementId}
listExpression={listExpression} {...props} />
),
}),
- [expressionHolderId, listExpression]
+ [expressionHolderId, listExpression, parentElementId]
);
const onRowAdded = useCallback(
@@ -225,8 +230,8 @@ export function ListExpression(
);
const beeTableHeaderVisibility = useMemo(() => {
- return listExpression.isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.AllLevels;
- }, [listExpression.isNested]);
+ return isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.AllLevels;
+ }, [isNested]);
const onColumnUpdates = useCallback(
([{ name, typeRef }]: BeeTableColumnUpdate<ROWTYPE>[]) => {
diff --git
a/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx
b/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx
index e07b9709abf..b27e7454143 100644
---
a/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx
@@ -28,7 +28,11 @@ import {
BoxedLiteral,
} from "../../api";
import { useNestedExpressionContainer } from
"../../resizing/NestedExpressionContainerContext";
-import { LITERAL_EXPRESSION_EXTRA_WIDTH, LITERAL_EXPRESSION_MIN_WIDTH } from
"../../resizing/WidthConstants";
+import {
+ LITERAL_EXPRESSION_EXTRA_WIDTH,
+ LITERAL_EXPRESSION_MIN_WIDTH,
+ LITERAL_EXPRESSION_WIDTH_INDEX,
+} from "../../resizing/WidthConstants";
import { BeeTable, BeeTableCellUpdate, BeeTableColumnUpdate, BeeTableRef }
from "../../table/BeeTable";
import { usePublishedBeeTableResizableColumns } from
"../../resizing/BeeTableResizableColumnsContext";
import { useBeeTableCoordinates, useBeeTableSelectableCellRef } from
"../../selection/BeeTableSelectionContext";
@@ -40,7 +44,13 @@ import "./LiteralExpression.css";
type ROWTYPE = any; // FIXME: https://github.com/kiegroup/kie-issues/issues/169
-export function LiteralExpression(literalExpression: BoxedLiteral & {
isNested: boolean }) {
+export function LiteralExpression({
+ isNested,
+ expression: literalExpression,
+}: {
+ expression: BoxedLiteral;
+ isNested: boolean;
+}) {
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
const { expressionHolderId, widthsById } = useBoxedExpressionEditor();
@@ -52,13 +62,17 @@ export function LiteralExpression(literalExpression:
BoxedLiteral & { isNested:
const setValue = useCallback(
(value: string) => {
- setExpression(() => ({ ...literalExpression, text: { __$$text: value }
}));
+ setExpression((prev: BoxedLiteral) => {
+ // Do not inline this variable for type safety. See
https://github.com/microsoft/TypeScript/issues/241
+ const ret: BoxedLiteral = { ...literalExpression, text: { __$$text:
value } };
+ return ret;
+ });
},
[literalExpression, setExpression]
);
const width = useMemo(() => {
- return widthsById.get(id)?.[0] ?? LITERAL_EXPRESSION_MIN_WIDTH;
+ return widthsById.get(id)?.[LITERAL_EXPRESSION_WIDTH_INDEX] ??
LITERAL_EXPRESSION_MIN_WIDTH;
}, [id, widthsById]);
const { containerCellCoordinates } = useBeeTableCoordinates();
@@ -84,7 +98,7 @@ export function LiteralExpression(literalExpression:
BoxedLiteral & { isNested:
(newWidthAction: React.SetStateAction<number | undefined>) => {
setWidthsById(({ newMap }) => {
const prev = newMap.get(id) ?? [];
- const prevWidth = prev[0];
+ const prevWidth = prev[LITERAL_EXPRESSION_WIDTH_INDEX];
const newWidth = typeof newWidthAction === "function" ?
newWidthAction(prevWidth) : newWidthAction;
newMap.set(id, [newWidth ?? LITERAL_EXPRESSION_MIN_WIDTH]);
});
@@ -117,7 +131,7 @@ export function LiteralExpression(literalExpression:
BoxedLiteral & { isNested:
const beeTableRef = useRef<BeeTableRef>(null);
useEffect(() => {
- if (isPivoting || !literalExpression.isNested) {
+ if (isPivoting || !isNested) {
return;
}
@@ -133,7 +147,7 @@ export function LiteralExpression(literalExpression:
BoxedLiteral & { isNested:
],
])
);
- }, [isPivoting, literalExpression.isNested, minWidth,
nestedExpressionContainer.resizingWidth.value]);
+ }, [isPivoting, isNested, minWidth,
nestedExpressionContainer.resizingWidth.value]);
/// //////////////////////////////////////////////////////
@@ -156,8 +170,8 @@ export function LiteralExpression(literalExpression:
BoxedLiteral & { isNested:
}, [expressionHolderId, literalExpression.text, id]);
const beeTableHeaderVisibility = useMemo(() => {
- return literalExpression.isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.AllLevels;
- }, [literalExpression.isNested]);
+ return isNested ? BeeTableHeaderVisibility.None :
BeeTableHeaderVisibility.AllLevels;
+ }, [isNested]);
const getRowKey = useCallback((row: ReactTable.Row<ROWTYPE>) => {
return row.id;
diff --git
a/packages/boxed-expression-component/src/expressions/RelationExpression/RelationExpression.tsx
b/packages/boxed-expression-component/src/expressions/RelationExpression/RelationExpression.tsx
index 7c34509b21a..1fadabf054b 100644
---
a/packages/boxed-expression-component/src/expressions/RelationExpression/RelationExpression.tsx
+++
b/packages/boxed-expression-component/src/expressions/RelationExpression/RelationExpression.tsx
@@ -51,12 +51,15 @@ type ROWTYPE = any; // FIXME:
https://github.com/kiegroup/kie-issues/issues/169
export const RELATION_EXPRESSION_DEFAULT_VALUE = "";
-export function RelationExpression(
- relationExpression: BoxedRelation & {
- isNested: boolean;
- parentElementId: string;
- }
-) {
+export function RelationExpression({
+ isNested,
+ parentElementId,
+ expression: relationExpression,
+}: {
+ expression: BoxedRelation;
+ isNested: boolean;
+ parentElementId: string;
+}) {
const { i18n } = useBoxedExpressionEditorI18n();
const { widthsById, expressionHolderId } = useBoxedExpressionEditor();
const { setExpression, setWidthsById } = useBoxedExpressionEditorDispatch();
@@ -149,7 +152,7 @@ export function RelationExpression(
useApportionedColumnWidthsIfNestedTable(
beeTableRef,
isPivoting,
- relationExpression.isNested,
+ isNested,
BEE_TABLE_ROW_INDEX_COLUMN_WIDTH,
columns,
columnResizingWidths,
@@ -441,8 +444,8 @@ export function RelationExpression(
);
const beeTableHeaderVisibility = useMemo(() => {
- return relationExpression.isNested ? BeeTableHeaderVisibility.LastLevel :
BeeTableHeaderVisibility.AllLevels;
- }, [relationExpression.isNested]);
+ return isNested ? BeeTableHeaderVisibility.LastLevel :
BeeTableHeaderVisibility.AllLevels;
+ }, [isNested]);
const allowedOperations = useCallback(
(conditions: BeeTableContextMenuAllowedOperationsConditions) => {
diff --git a/packages/boxed-expression-component/src/resizing/WidthConstants.ts
b/packages/boxed-expression-component/src/resizing/WidthConstants.ts
index c98341a43bb..0e307d20eef 100644
--- a/packages/boxed-expression-component/src/resizing/WidthConstants.ts
+++ b/packages/boxed-expression-component/src/resizing/WidthConstants.ts
@@ -25,11 +25,13 @@ export const BEE_TABLE_ROW_INDEX_COLUMN_WIDTH = 60;
export const CONTEXT_ENTRY_VARIABLE_MIN_WIDTH = 120;
export const CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH = 210;
export const CONTEXT_EXPRESSION_EXTRA_WIDTH = 2; // 2px for borders of context
entry expression // It's a mistery why to this cell is counting the borders.
+export const CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX = 0;
// INVOCATION
export const INVOCATION_PARAMETER_MIN_WIDTH = 120;
export const INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH = 210;
export const INVOCATION_EXTRA_WIDTH = 2; // 2px for borders of context entry
expression // It's a mistery why to this cell is counting the borders.
+export const INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX = 0;
// DECISION TABLE
export const DECISION_TABLE_INPUT_MIN_WIDTH = 100;
@@ -45,7 +47,7 @@ export const RELATION_EXPRESSION_COLUMN_DEFAULT_WIDTH = 100;
// LITERAL
export const LITERAL_EXPRESSION_EXTRA_WIDTH = 20; // 20px for the equals sign
-
+export const LITERAL_EXPRESSION_WIDTH_INDEX = 0;
export const LITERAL_EXPRESSION_MIN_WIDTH = CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH
- LITERAL_EXPRESSION_EXTRA_WIDTH;
// LIST
@@ -63,5 +65,9 @@ export const PMML_FUNCTION_EXPRESSION_EXTRA_WIDTH =
BEE_TABLE_ROW_INDEX_COLUMN_W
export const JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH = 210;
export const JAVA_FUNCTION_EXPRESSION_LABEL_MIN_WIDTH = 140;
-
+export const JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX = 2; // 0 is
the rowIndex column, 1 is the label column.
export const JAVA_FUNCTION_EXPRESSION_EXTRA_WIDTH =
BEE_TABLE_ROW_INDEX_COLUMN_WIDTH;
+
+export const CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH = 80;
+export const CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH = 210;
+export const CONDITIONAL_EXPRESSION_EXTRA_WIDTH = 2; // 2px for borders of
context entry expression // It's a mistery why to this cell is counting the
borders.
diff --git a/packages/boxed-expression-component/src/resizing/WidthMaths.ts
b/packages/boxed-expression-component/src/resizing/WidthMaths.ts
index 0c2059e1a72..ba4430b3d34 100644
--- a/packages/boxed-expression-component/src/resizing/WidthMaths.ts
+++ b/packages/boxed-expression-component/src/resizing/WidthMaths.ts
@@ -21,8 +21,12 @@ import { BoxedExpression, BoxedFunctionKind } from
"../api/BoxedExpression";
import { ResizingWidth } from "./ResizingWidthsContext";
import {
BEE_TABLE_ROW_INDEX_COLUMN_WIDTH,
+ CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ CONDITIONAL_EXPRESSION_EXTRA_WIDTH,
+ CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH,
CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH,
CONTEXT_ENTRY_VARIABLE_MIN_WIDTH,
+ CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX,
CONTEXT_EXPRESSION_EXTRA_WIDTH,
DECISION_TABLE_ANNOTATION_MIN_WIDTH,
DECISION_TABLE_INPUT_MIN_WIDTH,
@@ -32,14 +36,17 @@ import {
FEEL_FUNCTION_EXPRESSION_MIN_WIDTH,
INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH,
INVOCATION_EXTRA_WIDTH,
+ INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX,
INVOCATION_PARAMETER_MIN_WIDTH,
JAVA_FUNCTION_EXPRESSION_EXTRA_WIDTH,
JAVA_FUNCTION_EXPRESSION_LABEL_MIN_WIDTH,
+ JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX,
JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH,
LIST_EXPRESSION_EXTRA_WIDTH,
LIST_EXPRESSION_ITEM_MIN_WIDTH,
LITERAL_EXPRESSION_EXTRA_WIDTH,
LITERAL_EXPRESSION_MIN_WIDTH,
+ LITERAL_EXPRESSION_WIDTH_INDEX,
PMML_FUNCTION_EXPRESSION_EXTRA_WIDTH,
PMML_FUNCTION_EXPRESSION_LABEL_MIN_WIDTH,
PMML_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH,
@@ -49,11 +56,15 @@ import {
export function getExpressionMinWidth(expression?: BoxedExpression): number {
if (!expression || !expression.__$$element) {
return DEFAULT_MIN_WIDTH;
- } else if (expression.__$$element === "literalExpression") {
+ }
+
+ // Literal
+ else if (expression.__$$element === "literalExpression") {
return LITERAL_EXPRESSION_MIN_WIDTH + LITERAL_EXPRESSION_EXTRA_WIDTH;
+ }
- // Context + Invocation
- } else if (expression.__$$element === "context") {
+ // Context + Invocation
+ else if (expression.__$$element === "context") {
const result = expression.contextEntry?.find((e) => !e.variable);
const nestedExpressions = [...(expression.contextEntry ?? []).map((e) =>
e.expression), result?.expression];
return (
@@ -68,9 +79,10 @@ export function getExpressionMinWidth(expression?:
BoxedExpression): number {
Math.max(INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH,
...nestedExpressions.map((e) => getExpressionMinWidth(e))) +
INVOCATION_EXTRA_WIDTH
);
+ }
- // Function
- } else if (expression.__$$element === "functionDefinition") {
+ // Function
+ else if (expression.__$$element === "functionDefinition") {
if (expression["@_kind"] === BoxedFunctionKind.Feel) {
return (
Math.max(
@@ -93,9 +105,10 @@ export function getExpressionMinWidth(expression?:
BoxedExpression): number {
} else {
throw new Error("Should never get here");
}
+ }
- // Relation + DecisionTable
- } else if (expression.__$$element === "relation") {
+ // Relation + DecisionTable
+ else if (expression.__$$element === "relation") {
return (
BEE_TABLE_ROW_INDEX_COLUMN_WIDTH + //
(expression.column?.length ?? 0) * RELATION_EXPRESSION_COLUMN_MIN_WIDTH
@@ -119,23 +132,28 @@ export function getExpressionMinWidth(expression?:
BoxedExpression): number {
);
}
+ // Conditional
+ else if (expression.__$$element === "conditional") {
+ const nestedExpressions = [expression.if.expression,
expression.then.expression, expression.else.expression];
+ return (
+ CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH +
+ Math.max(
+ CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ ...nestedExpressions.map((e) => getExpressionMinWidth(e))
+ ) +
+ CONDITIONAL_EXPRESSION_EXTRA_WIDTH
+ );
+ }
+
// Others
else {
throw new Error("Shouldn't ever reach this point");
}
}
-export function getWidth(id: string | undefined, widthsById: Map<string,
number[]>) {
- const widths = widthsById.get(id ?? "");
- if (widths && widths.length > 0) {
- return widths[0];
- } else {
- return undefined;
- }
-}
-
/**
- * This function goes recursively through all `expression`'s nested
expressions and sums either `entryInfoWidth` or default minimal width, returned
by `getExpressionMinWidth`, if it is the last nested expression in the chain.
+ * This function goes recursively through all `expression`'s nested
expressions and sums either `fixed column width` or
+ * default minimal width, returned by `getExpressionMinWidth`, if it is the
last nested expression in the chain.
*
* This function returns maximal sum found in all `expression`'s nested
expressions.
*/
@@ -149,29 +167,34 @@ export function getExpressionTotalMinWidth(
}
if (expression.__$$element === "context") {
- const width = currentWidth + (getWidth(expression["@_id"], widthsById) ??
0);
- const contextEntriesMaxWidth = (expression.contextEntry ??
[]).reduce((maxWidth, currentExpression) => {
- return Math.max(maxWidth, getExpressionTotalMinWidth(width,
currentExpression.expression, widthsById));
- }, width);
- const result = expression.contextEntry?.find((e) => !e.variable);
- const resultWidth = result ? getExpressionTotalMinWidth(width,
result.expression, widthsById) : 0;
- return Math.max(contextEntriesMaxWidth, resultWidth);
+ const width =
+ currentWidth +
+ (getWidthAt(CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX, widthsById,
expression["@_id"]) ??
+ CONTEXT_ENTRY_VARIABLE_MIN_WIDTH) +
+ CONTEXT_EXPRESSION_EXTRA_WIDTH;
+ const contextEntriesMaxWidth = (expression.contextEntry ?? []).reduce(
+ (maxWidth, currentExpression) =>
+ Math.max(maxWidth, getExpressionTotalMinWidth(width,
currentExpression.expression, widthsById)),
+ width
+ );
+ return contextEntriesMaxWidth;
} else if (expression.__$$element === "invocation") {
- const width = currentWidth + (getWidth(expression["@_id"], widthsById) ??
0);
- return (expression.binding ?? []).reduce((maxWidth, currentExpression) => {
- return Math.max(maxWidth, getExpressionTotalMinWidth(width,
currentExpression.expression, widthsById));
- }, width);
- } else {
- // it is an expression without entryInfoWidth
- return currentWidth + getExpressionMinWidth(expression);
+ const width =
+ currentWidth +
+ (getWidthAt(INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX, widthsById,
expression["@_id"]) ??
+ INVOCATION_PARAMETER_MIN_WIDTH) +
+ INVOCATION_EXTRA_WIDTH;
+ return (expression.binding ?? []).reduce(
+ (maxWidth, currentExpression) =>
+ Math.max(maxWidth, getExpressionTotalMinWidth(width,
currentExpression.expression, widthsById)),
+ width
+ );
}
-}
-function getWidthAt(index: number, widths?: number[]): number | undefined {
- if (!widths || widths.length <= index) {
- return undefined;
+ // Expression without fixed column
+ else {
+ return currentWidth + getExpressionMinWidth(expression);
}
- return widths[index];
}
export function getExpressionResizingWidth(
@@ -188,8 +211,9 @@ export function getExpressionResizingWidth(
// Literal
if (expression.__$$element === "literalExpression") {
return (
- (resizingWidth ?? getWidth(expression["@_id"], widthsById) ??
LITERAL_EXPRESSION_MIN_WIDTH) +
- LITERAL_EXPRESSION_EXTRA_WIDTH
+ (resizingWidth ??
+ getWidthAt(LITERAL_EXPRESSION_WIDTH_INDEX, widthsById,
expression["@_id"]!) ??
+ LITERAL_EXPRESSION_MIN_WIDTH) + LITERAL_EXPRESSION_EXTRA_WIDTH
);
}
@@ -197,21 +221,22 @@ export function getExpressionResizingWidth(
else if (expression.__$$element === "relation") {
const columns = expression.column ?? [];
- const expressionWidth = widthsById.get(expression["@_id"]!);
-
return (
resizingWidth ??
columns.reduce((acc, c, currentIndex) => {
- return acc + (getWidthAt(currentIndex + 1, expressionWidth) ??
RELATION_EXPRESSION_COLUMN_MIN_WIDTH);
+ return (
+ acc + (getWidthAt(currentIndex + 1, widthsById, expression["@_id"]!)
?? RELATION_EXPRESSION_COLUMN_MIN_WIDTH)
+ );
}, BEE_TABLE_ROW_INDEX_COLUMN_WIDTH)
);
} else if (expression.__$$element === "decisionTable") {
const columns = [...(expression.input ?? []), ...(expression.output ??
[]), ...(expression.annotation ?? [])];
- const expressionWidth = widthsById.get(expression["@_id"]!);
return (
resizingWidth ??
columns.reduce((acc, c, currentIndex) => {
- return acc + (getWidthAt(currentIndex + 1, expressionWidth) ??
RELATION_EXPRESSION_COLUMN_MIN_WIDTH);
+ return (
+ acc + (getWidthAt(currentIndex + 1, widthsById, expression["@_id"]!)
?? RELATION_EXPRESSION_COLUMN_MIN_WIDTH)
+ );
}, BEE_TABLE_ROW_INDEX_COLUMN_WIDTH)
);
}
@@ -222,7 +247,8 @@ export function getExpressionResizingWidth(
const nestedExpressions = [...(expression.contextEntry ?? []).map((e) =>
e.expression), result?.expression];
return (
resizingWidth ??
- (getWidth(expression["@_id"], widthsById) ??
CONTEXT_ENTRY_VARIABLE_MIN_WIDTH) +
+ (getWidthAt(CONTEXT_ENTRY_VARIABLE_COLUMN_WIDTH_INDEX, widthsById,
expression["@_id"]!) ??
+ CONTEXT_ENTRY_VARIABLE_MIN_WIDTH) +
Math.max(
CONTEXT_ENTRY_EXPRESSION_MIN_WIDTH,
...nestedExpressions.map((e) => getExpressionResizingWidth(e,
resizingWidths, widthsById))
@@ -233,7 +259,8 @@ export function getExpressionResizingWidth(
const nestedExpressions = (expression.binding ?? []).map((e) =>
e.expression);
return (
resizingWidth ??
- (getWidth(expression["@_id"], widthsById) ??
INVOCATION_PARAMETER_MIN_WIDTH) +
+ (getWidthAt(INVOCATION_PARAMETER_INFO_COLUMN_WIDTH_INDEX, widthsById,
expression["@_id"]!) ??
+ INVOCATION_PARAMETER_MIN_WIDTH) +
Math.max(
INVOCATION_ARGUMENT_EXPRESSION_MIN_WIDTH,
...nestedExpressions.map((e) => getExpressionResizingWidth(e,
resizingWidths, widthsById))
@@ -258,7 +285,8 @@ export function getExpressionResizingWidth(
return (
resizingWidth ??
JAVA_FUNCTION_EXPRESSION_LABEL_MIN_WIDTH +
- (getWidthAt(2, widthsById.get(expression["@_id"]!)) ??
JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH) +
+ (getWidthAt(JAVA_FUNCTION_EXPRESSION_VALUES_COLUMN_WIDTH_INDEX,
widthsById, expression["@_id"]!) ??
+ JAVA_FUNCTION_EXPRESSION_VALUES_MIN_WIDTH) +
JAVA_FUNCTION_EXPRESSION_EXTRA_WIDTH
);
} else if (expression["@_kind"] === BoxedFunctionKind.Pmml) {
@@ -286,8 +314,34 @@ export function getExpressionResizingWidth(
);
}
+ // Conditional
+ else if (expression.__$$element === "conditional") {
+ const nestedExpressions = [expression.if.expression,
expression.then.expression, expression.else.expression];
+ return (
+ resizingWidth ??
+ CONDITIONAL_EXPRESSION_LABEL_COLUMN_WIDTH +
+ Math.max(
+ CONDITIONAL_EXPRESSION_CLAUSE_COLUMN_MIN_WIDTH,
+ ...nestedExpressions.map((e) => getExpressionResizingWidth(e,
resizingWidths, widthsById))
+ ) +
+ CONDITIONAL_EXPRESSION_EXTRA_WIDTH
+ );
+ }
+
// Others
else {
- return resizingWidth ?? DEFAULT_MIN_WIDTH;
+ throw new Error(`Can't determine resizing width for expression of unknown
type '${expression.__$$element}'`);
}
}
+
+function getWidthAt(
+ index: number,
+ widthsById: Map<string, number[]>,
+ expressionId: string | undefined
+): number | undefined {
+ const widths = widthsById.get(expressionId!);
+ if (!widths || widths.length <= index) {
+ return undefined;
+ }
+ return widths[index];
+}
diff --git
a/packages/boxed-expression-component/src/table/BeeTable/BeeTableReadOnlyCell.tsx
b/packages/boxed-expression-component/src/table/BeeTable/BeeTableReadOnlyCell.tsx
new file mode 100644
index 00000000000..d2fbd928dfe
--- /dev/null
+++
b/packages/boxed-expression-component/src/table/BeeTable/BeeTableReadOnlyCell.tsx
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { useBeeTableCoordinates, useBeeTableSelectableCellRef } from
"../../selection/BeeTableSelectionContext";
+import { useCallback, useEffect } from "react";
+
+import * as React from "react";
+import { useBoxedExpressionEditor } from "../../BoxedExpressionEditorContext";
+
+export interface BeeTableReadOnlyCellProps {
+ value: string;
+}
+
+export const BeeTableReadOnlyCell:
React.FunctionComponent<BeeTableReadOnlyCellProps> = ({ value }) => {
+ const { containerCellCoordinates } = useBeeTableCoordinates();
+
+ const getValue = useCallback(() => {
+ return value;
+ }, [value]);
+
+ const { isActive } = useBeeTableSelectableCellRef(
+ containerCellCoordinates?.rowIndex ?? 0,
+ containerCellCoordinates?.columnIndex ?? 0,
+ undefined,
+ getValue
+ );
+
+ const { beeGwtService } = useBoxedExpressionEditor();
+
+ useEffect(() => {
+ if (isActive) {
+ beeGwtService?.selectObject("");
+ }
+ }, [beeGwtService, isActive]);
+
+ return <div>{value}</div>;
+};
diff --git
a/packages/boxed-expression-component/stories/dev/getDefaultBoxedExpressionForDevWebapp.ts
b/packages/boxed-expression-component/stories/dev/getDefaultBoxedExpressionForDevWebapp.ts
index f13b59fa3b4..887a4781837 100644
---
a/packages/boxed-expression-component/stories/dev/getDefaultBoxedExpressionForDevWebapp.ts
+++
b/packages/boxed-expression-component/stories/dev/getDefaultBoxedExpressionForDevWebapp.ts
@@ -28,6 +28,11 @@ import {
BoxedList,
BoxedLiteral,
BoxedRelation,
+ BoxedConditional,
+ BoxedFor,
+ BoxedSome,
+ BoxedEvery,
+ BoxedFilter,
} from "../../src/api";
import {
INVOCATION_EXPRESSION_DEFAULT_PARAMETER_DATA_TYPE,
@@ -217,6 +222,76 @@ export function getDefaultBoxedExpressionForDevWebapp(
],
};
return decisionTableExpression;
+ } else if (logicType === "conditional") {
+ const conditionalExpression: BoxedConditional = {
+ __$$element: "conditional",
+ if: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ then: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ else: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+
+ return conditionalExpression;
+ } else if (logicType === "for") {
+ const forExpression: BoxedFor = {
+ __$$element: "for",
+ return: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return forExpression;
+ } else if (logicType == "some") {
+ const someExpression: BoxedSome = {
+ __$$element: "some",
+ satisfies: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return someExpression;
+ } else if (logicType === "every") {
+ const everyExpression: BoxedEvery = {
+ __$$element: "every",
+ satisfies: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return everyExpression;
+ } else if (logicType === "filter") {
+ const filterExpression: BoxedFilter = {
+ __$$element: "filter",
+ match: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return filterExpression;
} else {
throw new Error(`No default expression available for ${logicType}`);
}
diff --git
a/packages/dmn-editor/src/boxedExpressions/getDefaultBoxedExpression.tsx
b/packages/dmn-editor/src/boxedExpressions/getDefaultBoxedExpression.tsx
index 065bbed6636..3410cf7d2e7 100644
--- a/packages/dmn-editor/src/boxedExpressions/getDefaultBoxedExpression.tsx
+++ b/packages/dmn-editor/src/boxedExpressions/getDefaultBoxedExpression.tsx
@@ -28,6 +28,11 @@ import {
BoxedInvocation,
BoxedRelation,
BoxedDecisionTable,
+ BoxedConditional,
+ BoxedFor,
+ BoxedSome,
+ BoxedEvery,
+ BoxedFilter,
} from "@kie-tools/boxed-expression-component/dist/api";
import {
LITERAL_EXPRESSION_MIN_WIDTH,
@@ -319,6 +324,76 @@ export function getDefaultBoxedExpression({
]);
return decisionTableExpression;
+ } else if (logicType === "conditional") {
+ const conditionalExpression: BoxedConditional = {
+ __$$element: "conditional",
+ if: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ then: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ else: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+
+ return conditionalExpression;
+ } else if (logicType === "for") {
+ const forExpression: BoxedFor = {
+ __$$element: "for",
+ return: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return forExpression;
+ } else if (logicType == "some") {
+ const someExpression: BoxedSome = {
+ __$$element: "some",
+ satisfies: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return someExpression;
+ } else if (logicType === "every") {
+ const everyExpression: BoxedEvery = {
+ __$$element: "every",
+ satisfies: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return everyExpression;
+ } else if (logicType === "filter") {
+ const filterExpression: BoxedFilter = {
+ __$$element: "filter",
+ match: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ in: {
+ "@_id": generateUuid(),
+ expression: undefined as any,
+ },
+ };
+ return filterExpression;
} else {
throw new Error(`No default expression available for ${logicType}.`);
}
diff --git a/packages/stunner-editors-dmn-loader/src/index.tsx
b/packages/stunner-editors-dmn-loader/src/index.tsx
index cbba6cdd34c..1272896f3b4 100644
--- a/packages/stunner-editors-dmn-loader/src/index.tsx
+++ b/packages/stunner-editors-dmn-loader/src/index.tsx
@@ -59,6 +59,8 @@ export interface BoxedExpressionEditorWrapperProps {
boxedExpressionEditorRootNode: Element | null;
/** The DMN XML */
dmnXml: string;
+ /** A boolean used to hide DMN 1.4 expressions. */
+ hideDmn14BoxedExpressions?: boolean;
}
const BoxedExpressionEditorWrapper:
React.FunctionComponent<BoxedExpressionEditorWrapperProps> = ({
@@ -69,6 +71,7 @@ const BoxedExpressionEditorWrapper:
React.FunctionComponent<BoxedExpressionEdito
pmmlDocuments,
boxedExpressionEditorRootNode,
dmnXml,
+ hideDmn14BoxedExpressions,
}) => {
const [expressionWrapper, setExpressionWrapper] = useState<{
source: "gwt" | "react";
@@ -207,6 +210,7 @@ const BoxedExpressionEditorWrapper:
React.FunctionComponent<BoxedExpressionEdito
onExpressionChange={setExpressionNotifyingUserAction}
widthsById={expressionWrapper.widthsById}
onWidthsChange={setWidthsByIdNotifyingUserAction}
+ hideDmn14BoxedExpressions={hideDmn14BoxedExpressions}
/>
);
};
@@ -230,6 +234,7 @@ const renderBoxedExpressionEditor = (
pmmlDocuments={pmmlDocuments}
boxedExpressionEditorRootNode={boxedExpressionEditorRootNode}
dmnXml={dmnXml}
+ hideDmn14BoxedExpressions={true}
/>,
boxedExpressionEditorRootNode
);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]