diff --git a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryExpressionCell.tsx b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryExpressionCell.tsx index 621a7fd1694..6e9a4e64f76 100644 --- a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryExpressionCell.tsx +++ b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryExpressionCell.tsx @@ -21,23 +21,24 @@ import { ContextExpressionDefinitionEntry, ExpressionDefinitionLogicType, } from "../../api"; -import * as _ from "lodash"; import { NestedExpressionDispatchContextProvider, useBoxedExpressionEditorDispatch, } from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; -import { useCallback, useMemo } from "react"; +import { useCallback } from "react"; import { ExpressionContainer } from "../ExpressionDefinitionRoot/ExpressionContainer"; export interface ContextEntryExpressionCellProps { // This name ('data') can't change, as this is used on "cellComponentByColumnAccessor". data: readonly ContextExpressionDefinitionEntry[]; rowIndex: number; + columnIndex: number; } export const ContextEntryExpressionCell: React.FunctionComponent = ({ data: contextEntries, rowIndex, + columnIndex, }) => { const { setExpression } = useBoxedExpressionEditorDispatch(); @@ -60,6 +61,8 @@ export const ContextEntryExpressionCell: React.FunctionComponent ); diff --git a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryInfoCell.tsx b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryInfoCell.tsx index b59aa813b43..8777dbccf43 100644 --- a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryInfoCell.tsx +++ b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextEntryInfoCell.tsx @@ -16,13 +16,14 @@ import { ContextExpressionDefinitionEntry, DmnBuiltInDataType, ExpressionDefinition } from "../../api"; import * as React from "react"; -import { useCallback, useMemo } from "react"; +import { useCallback, useEffect, useMemo } from "react"; import * as _ from "lodash"; import { useBeeTableSelectableCellRef } from "../../selection/BeeTableSelectionContext"; import { DEFAULT_EXPRESSION_NAME, ExpressionDefinitionHeaderMenu } from "../ExpressionDefinitionHeaderMenu"; import "./ContextEntryInfoCell.css"; import { useCellWidthToFitDataRef } from "../../resizing/BeeTableCellWidthToFitDataContext"; import { getCanvasFont, getTextWidth } from "../../resizing/WidthsToFitData"; +import { useBoxedExpressionEditor } from "../../expressions/BoxedExpressionEditor/BoxedExpressionEditorContext"; export interface ContextEntryInfoCellProps { // This name ('data') can't change, as this is used on "cellComponentByColumnAccessor". @@ -86,13 +87,21 @@ export const ContextEntryInfoCell: React.FunctionComponent `${entryInfo.name} (${entryInfo.dataType})`, [entryInfo.dataType, entryInfo.name]) ); + const { beeGwtService } = useBoxedExpressionEditor(); + + useEffect(() => { + if (isActive) { + beeGwtService?.selectObject(entryInfo.id); + } + }, [beeGwtService, entryInfo, isActive]); + const renderEntryDefinition = useCallback( (args: { additionalCssClass?: string }) => (
diff --git a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx index e11376c968d..877e17da74b 100644 --- a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextExpression.tsx @@ -118,7 +118,7 @@ export function ContextExpression(contextExpression: ContextExpressionDefinition const beeTableColumns = useMemo[]>(() => { return [ { - accessor: "context-expression" as any, // FIXME: Tiago -> ? + accessor: contextExpression.id as any, // FIXME: Tiago -> ? label: contextExpression.name ?? DEFAULT_EXPRESSION_NAME, isRowIndexColumn: false, dataType: contextExpression.dataType ?? CONTEXT_ENTRY_DEFAULT_DATA_TYPE, @@ -205,7 +205,12 @@ export function ContextExpression(contextExpression: ContextExpressionDefinition const beeTableAdditionalRow = useMemo(() => { return [ , - , + , ]; }, [contextExpression]); diff --git a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextResultExpressionCell.tsx b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextResultExpressionCell.tsx index 0ec5728280a..bcd6b6d30a6 100644 --- a/packages/boxed-expression-component/src/expressions/ContextExpression/ContextResultExpressionCell.tsx +++ b/packages/boxed-expression-component/src/expressions/ContextExpression/ContextResultExpressionCell.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { useCallback, useMemo } from "react"; +import { useCallback } from "react"; import { ContextExpressionDefinition } from "../../api"; import { useBoxedExpressionEditorDispatch, @@ -7,7 +7,11 @@ import { } from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; import { ExpressionContainer } from "../ExpressionDefinitionRoot/ExpressionContainer"; -export function ContextResultExpressionCell(props: { contextExpression: ContextExpressionDefinition }) { +export function ContextResultExpressionCell(props: { + contextExpression: ContextExpressionDefinition; + rowIndex: number; + columnIndex: number; +}) { const { setExpression } = useBoxedExpressionEditorDispatch(); const onSetExpression = useCallback( @@ -22,7 +26,13 @@ export function ContextResultExpressionCell(props: { contextExpression: ContextE return ( - + ); } diff --git a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx index a42ad922394..593665567d3 100644 --- a/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/DecisionTableExpression/DecisionTableExpression.tsx @@ -254,7 +254,7 @@ export function DecisionTableExpression( const outputSection = { groupType: DecisionTableColumnType.OutputClause, - id: "Outputs", + id: decisionTableExpression.id, accessor: "decision-table-expression" as any, // FIXME: Tiago -> ? label: decisionTableExpression.name ?? DEFAULT_EXPRESSION_NAME, dataType: decisionTableExpression.dataType ?? DmnBuiltInDataType.Undefined, diff --git a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx index 841927c03d7..ebc12cb1288 100644 --- a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx +++ b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionContainer.tsx @@ -14,33 +14,43 @@ * limitations under the License. */ -import { DmnBuiltInDataType, ExpressionDefinition, ExpressionDefinitionLogicType, generateUuid } from "../../api"; +import { ExpressionDefinition, ExpressionDefinitionLogicType, generateUuid } from "../../api"; import * as React from "react"; -import { useCallback, useRef } from "react"; +import { useCallback, useEffect, useRef } from "react"; import { ExpressionDefinitionLogicTypeSelector } from "./ExpressionDefinitionLogicTypeSelector"; -import * as _ from "lodash"; import { useBoxedExpressionEditor, useBoxedExpressionEditorDispatch, } from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; import { DEFAULT_EXPRESSION_NAME } from "../ExpressionDefinitionHeaderMenu"; -import { useNestedExpressionContainer } from "../../resizing/NestedExpressionContainerContext"; +import { useBeeTableSelectableCellRef } from "../../selection/BeeTableSelectionContext"; export interface ExpressionContainerProps { expression: ExpressionDefinition; isNested: boolean; isResetSupported: boolean; + rowIndex: number; + columnIndex: number; } export const ExpressionContainer: React.FunctionComponent = ({ expression, isNested, isResetSupported, + rowIndex, + columnIndex, }) => { const containerRef = useRef(null); const { beeGwtService } = useBoxedExpressionEditor(); const { setExpression } = useBoxedExpressionEditorDispatch(); + const { isActive } = useBeeTableSelectableCellRef(rowIndex, columnIndex, undefined); + + useEffect(() => { + if (isActive) { + beeGwtService?.selectObject(""); + } + }, [beeGwtService, isActive]); const onLogicTypeSelected = useCallback( (logicType) => { diff --git a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector/ExpressionDefinitionLogicTypeSelector.tsx b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector/ExpressionDefinitionLogicTypeSelector.tsx index a40551ba423..1d322032924 100644 --- a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector/ExpressionDefinitionLogicTypeSelector.tsx +++ b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionLogicTypeSelector/ExpressionDefinitionLogicTypeSelector.tsx @@ -26,7 +26,6 @@ import { CutIcon } from "@patternfly/react-icons/dist/js/icons/cut-icon"; import { ListIcon } from "@patternfly/react-icons/dist/js/icons/list-icon"; import { PasteIcon } from "@patternfly/react-icons/dist/js/icons/paste-icon"; import { TableIcon } from "@patternfly/react-icons/dist/js/icons/table-icon"; -import _ from "lodash"; import * as React from "react"; import { useCallback, useEffect, useMemo, useState } from "react"; import { ExpressionDefinition, ExpressionDefinitionLogicType, generateUuid } from "../../../api"; diff --git a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionRoot.tsx b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionRoot.tsx index bfda6d09d32..d9e4fe9fbaf 100644 --- a/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionRoot.tsx +++ b/packages/boxed-expression-component/src/expressions/ExpressionDefinitionRoot/ExpressionDefinitionRoot.tsx @@ -40,7 +40,13 @@ export function ExpressionDefinitionRoot({ ({expression.logicType})
- + ); diff --git a/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx b/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx index 687a506f1d6..c05813e0ff9 100644 --- a/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/FunctionExpression/FeelFunctionExpression.tsx @@ -65,7 +65,7 @@ export function FeelFunctionExpression({ return [ { label: functionExpression.name ?? DEFAULT_EXPRESSION_NAME, - accessor: "function-expression" as any, // FIXME: Tiago -> ? + accessor: functionExpression.id as any, // FIXME: Tiago -> ? dataType: functionExpression.dataType ?? DmnBuiltInDataType.Undefined, isRowIndexColumn: false, width: undefined, @@ -182,7 +182,7 @@ export function FeelFunctionExpression({ ); } -export function FeelFunctionImplementationCell({ data, rowIndex }: BeeTableCellProps) { +export function FeelFunctionImplementationCell({ data, rowIndex, columnIndex }: BeeTableCellProps) { const functionExpression = data[rowIndex].functionExpression as FeelFunctionExpressionDefinition; const { setExpression } = useBoxedExpressionEditorDispatch(); @@ -199,7 +199,13 @@ export function FeelFunctionImplementationCell({ data, rowIndex }: BeeTableCellP return ( - + ); } diff --git a/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx b/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx index 3fb25637e3f..b8fbab64b3e 100644 --- a/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/FunctionExpression/JavaFunctionExpression.tsx @@ -80,7 +80,7 @@ export function JavaFunctionExpression({ return [ { label: functionExpression.name ?? DEFAULT_EXPRESSION_NAME, - accessor: "function-expression" as any, // FIXME: Tiago -> ? + accessor: functionExpression.id as any, // FIXME: Tiago -> ? dataType: functionExpression.dataType ?? DmnBuiltInDataType.Undefined, isRowIndexColumn: false, width: undefined, diff --git a/packages/boxed-expression-component/src/expressions/FunctionExpression/PmmlFunctionExpression.tsx b/packages/boxed-expression-component/src/expressions/FunctionExpression/PmmlFunctionExpression.tsx index 88341fb8d72..90c74fab111 100644 --- a/packages/boxed-expression-component/src/expressions/FunctionExpression/PmmlFunctionExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/FunctionExpression/PmmlFunctionExpression.tsx @@ -69,7 +69,7 @@ export function PmmlFunctionExpression({ return [ { label: functionExpression.name ?? DEFAULT_EXPRESSION_NAME, - accessor: "function-expression" as any, // FIXME: Tiago -> ? + accessor: functionExpression.id as any, // FIXME: Tiago -> ? dataType: functionExpression.dataType ?? DmnBuiltInDataType.Undefined, isRowIndexColumn: false, width: undefined, diff --git a/packages/boxed-expression-component/src/expressions/InvocationExpression/ArgumentEntryExpressionCell.tsx b/packages/boxed-expression-component/src/expressions/InvocationExpression/ArgumentEntryExpressionCell.tsx index baec3ce23fe..5e600faeaaa 100644 --- a/packages/boxed-expression-component/src/expressions/InvocationExpression/ArgumentEntryExpressionCell.tsx +++ b/packages/boxed-expression-component/src/expressions/InvocationExpression/ArgumentEntryExpressionCell.tsx @@ -32,11 +32,13 @@ export interface ArgumentEntryExpressionCellProps { // This name ('data') can't change, as this is used on "cellComponentByColumnAccessor". data: readonly ContextExpressionDefinitionEntry[]; rowIndex: number; + columnIndex: number; } export const ArgumentEntryExpressionCell: React.FunctionComponent = ({ data: argumentEntries, rowIndex, + columnIndex, }) => { const { setExpression } = useBoxedExpressionEditorDispatch(); @@ -59,6 +61,8 @@ export const ArgumentEntryExpressionCell: React.FunctionComponent ); diff --git a/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx b/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx index 50fc45adb80..f6579a252ed 100644 --- a/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/InvocationExpression/InvocationExpression.tsx @@ -124,7 +124,7 @@ export function InvocationExpression(invocationExpression: InvocationExpressionD () => [ { label: invocationExpression.name ?? DEFAULT_EXPRESSION_NAME, - accessor: "invocation-expression" as keyof ROWTYPE, + accessor: invocationExpression.id as keyof ROWTYPE, dataType: invocationExpression.dataType ?? INVOCATION_EXPRESSION_DEFAULT_PARAMETER_DATA_TYPE, isRowIndexColumn: false, width: undefined, diff --git a/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx b/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx index f6a5746622e..aa52730e06a 100644 --- a/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/ListExpression/ListExpression.tsx @@ -34,7 +34,10 @@ import { useNestedExpressionContainerWithNestedExpressions } from "../../resizin import { NestedExpressionContainerContext } from "../../resizing/NestedExpressionContainerContext"; import { LIST_EXPRESSION_EXTRA_WIDTH, LIST_EXPRESSION_ITEM_MIN_WIDTH } from "../../resizing/WidthConstants"; import { BeeTable, BeeTableColumnUpdate } from "../../table/BeeTable"; -import { useBoxedExpressionEditorDispatch } from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; +import { + useBoxedExpressionEditor, + useBoxedExpressionEditorDispatch, +} from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; import { DEFAULT_EXPRESSION_NAME } from "../ExpressionDefinitionHeaderMenu"; import "./ListExpression.css"; import { ListItemCell } from "./ListItemCell"; @@ -45,6 +48,7 @@ export type ROWTYPE = ContextExpressionDefinitionEntry; export function ListExpression(listExpression: ListExpressionDefinition & { isNested: boolean }) { const { i18n } = useBoxedExpressionEditorI18n(); const { setExpression } = useBoxedExpressionEditorDispatch(); + const { decisionNodeId } = useBoxedExpressionEditor(); /// ////////////////////////////////////////////////////// /// ///////////// RESIZING WIDTHS //////////////////////// @@ -93,7 +97,7 @@ export function ListExpression(listExpression: ListExpressionDefinition & { isNe const beeTableColumns = useMemo[]>( () => [ { - accessor: "list" as any, + accessor: decisionNodeId as any, label: listExpression.name ?? DEFAULT_EXPRESSION_NAME, dataType: listExpression.dataType, isRowIndexColumn: false, @@ -110,7 +114,7 @@ export function ListExpression(listExpression: ListExpressionDefinition & { isNe const cellComponentByColumnAccessor: BeeTableProps["cellComponentByColumnAccessor"] = useMemo( () => ({ - list: ListItemCell, + [decisionNodeId]: ListItemCell, }), [] ); diff --git a/packages/boxed-expression-component/src/expressions/ListExpression/ListItemCell.tsx b/packages/boxed-expression-component/src/expressions/ListExpression/ListItemCell.tsx index 27b1d26e14c..90cc0ddd695 100644 --- a/packages/boxed-expression-component/src/expressions/ListExpression/ListItemCell.tsx +++ b/packages/boxed-expression-component/src/expressions/ListExpression/ListItemCell.tsx @@ -8,7 +8,7 @@ import { import { ExpressionContainer } from "../ExpressionDefinitionRoot/ExpressionContainer"; import { ROWTYPE } from "./ListExpression"; -export function ListItemCell({ rowIndex, data: items }: BeeTableCellProps) { +export function ListItemCell({ rowIndex, data: items, columnIndex }: BeeTableCellProps) { const { setExpression } = useBoxedExpressionEditorDispatch(); const onSetExpression = useCallback( @@ -26,7 +26,13 @@ export function ListItemCell({ rowIndex, data: items }: BeeTableCellProps - + ); } diff --git a/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx b/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx index 70df4597c2d..5bb21faa448 100644 --- a/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx +++ b/packages/boxed-expression-component/src/expressions/LiteralExpression/LiteralExpression.tsx @@ -23,7 +23,10 @@ import { LITERAL_EXPRESSION_EXTRA_WIDTH, LITERAL_EXPRESSION_MIN_WIDTH } from ".. import { BeeTable, BeeTableCellUpdate, BeeTableColumnUpdate, BeeTableRef } from "../../table/BeeTable"; import { usePublishedBeeTableResizableColumns } from "../../resizing/BeeTableResizableColumnsContext"; import { useBeeTableCoordinates, useBeeTableSelectableCellRef } from "../../selection/BeeTableSelectionContext"; -import { useBoxedExpressionEditorDispatch } from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; +import { + useBoxedExpressionEditor, + useBoxedExpressionEditorDispatch, +} from "../BoxedExpressionEditor/BoxedExpressionEditorContext"; import "./LiteralExpression.css"; import { DEFAULT_EXPRESSION_NAME } from "../ExpressionDefinitionHeaderMenu"; import { ResizerStopBehavior } from "../../resizing/ResizingWidthsContext"; @@ -32,6 +35,7 @@ type ROWTYPE = any; export function LiteralExpression(literalExpression: LiteralExpressionDefinition & { isNested: boolean }) { const { setExpression } = useBoxedExpressionEditorDispatch(); + const { decisionNodeId } = useBoxedExpressionEditor(); const getValue = useCallback(() => { return literalExpression.content ?? ""; @@ -125,7 +129,7 @@ export function LiteralExpression(literalExpression: LiteralExpressionDefinition const beeTableColumns = useMemo[]>(() => { return [ { - accessor: "literal-expression" as any, // FIXME: Tiago -> No bueno. + accessor: decisionNodeId as any, // FIXME: Tiago -> No bueno. label: literalExpression.name ?? DEFAULT_EXPRESSION_NAME, isRowIndexColumn: false, dataType: literalExpression.dataType, @@ -137,17 +141,13 @@ export function LiteralExpression(literalExpression: LiteralExpressionDefinition }, [literalExpression.dataType, literalExpression.name, literalExpression.width, minWidth, setWidth]); const beeTableRows = useMemo(() => { - return [{ "literal-expression": { content: literalExpression.content ?? "", id: literalExpression.id } }]; + return [{ [decisionNodeId]: { content: literalExpression.content ?? "", id: literalExpression.id } }]; }, [literalExpression]); const beeTableHeaderVisibility = useMemo(() => { return literalExpression.isNested ? BeeTableHeaderVisibility.None : BeeTableHeaderVisibility.AllLevels; }, [literalExpression.isNested]); - const getColumnKey = useCallback((column: ReactTable.Column) => { - return column.label; - }, []); - const getRowKey = useCallback((row: ReactTable.Row) => { return row.id; }, []); @@ -163,7 +163,6 @@ export function LiteralExpression(literalExpression: LiteralExpressionDefinition { dataType: DmnBuiltInDataType; diff --git a/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImpl.java b/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImpl.java index 436549493b6..ff7b2c67cb0 100644 --- a/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImpl.java +++ b/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/main/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImpl.java @@ -359,7 +359,7 @@ public void selectDomainObject(final String uuid) { DomainObject findDomainObject(final String uuid) { - if (innerExpressionMatches(uuid)) { + if (currentDomainObjectMatches(uuid)) { return (DomainObject) getHasExpression(); } else if (businessKnowledgeModelMatches(uuid)) { return getBusinessKnowledgeModel(); @@ -374,6 +374,8 @@ DomainObject findDomainObjectInCurrentExpression(final String uuid) { final Optional domainObject = getHasExpression().getExpression().findDomainObject(uuid); if (domainObject.isPresent()) { return domainObject.get(); + } else if (innerExpressionMatches(uuid)) { + return (DomainObject) getHasExpression(); } } return new NOPDomainObject(); @@ -383,9 +385,16 @@ BusinessKnowledgeModel getBusinessKnowledgeModel() { return ((BusinessKnowledgeModel) hasExpression.getExpression().asDMNModelInstrumentedBase().getParent()); } + boolean currentDomainObjectMatches(final String uuid) { + return getHasExpression() instanceof DomainObject + && matches(((DomainObject) getHasExpression()), uuid); + } + boolean innerExpressionMatches(final String uuid) { - return hasExpression instanceof DomainObject - && matches(((DomainObject) hasExpression), uuid); + + return getHasExpression() instanceof DomainObject + && !Objects.isNull(getHasExpression().getExpression()) + && Objects.equals(getHasExpression().getExpression().getId().getValue(), uuid); } boolean businessKnowledgeModelMatches(final String uuid) { diff --git a/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImplTest.java b/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImplTest.java index 9ddb8befa14..97576db7663 100644 --- a/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImplTest.java +++ b/packages/stunner-editors/kie-wb-common-dmn/kie-wb-common-dmn-client/src/test/java/org/kie/workbench/common/dmn/client/editors/expressions/ExpressionEditorViewImplTest.java @@ -43,6 +43,7 @@ import org.kie.workbench.common.dmn.api.definition.model.Expression; import org.kie.workbench.common.dmn.api.definition.model.ItemDefinition; import org.kie.workbench.common.dmn.api.definition.model.LiteralExpression; +import org.kie.workbench.common.dmn.api.property.dmn.Id; import org.kie.workbench.common.dmn.api.property.dmn.Name; import org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType; import org.kie.workbench.common.dmn.client.commands.factory.DefaultCanvasCommandFactory; @@ -800,7 +801,7 @@ public void testFindDomainObject_WhenObjectIsInsideHasExpression() { final String uuid = "someUuid"; final DomainObject domainObject = mock(DomainObject.class); - doReturn(false).when(view).innerExpressionMatches(uuid); + doReturn(false).when(view).currentDomainObjectMatches(uuid); doReturn(false).when(view).businessKnowledgeModelMatches(uuid); doReturn(domainObject).when(view).findDomainObject(uuid); @@ -815,7 +816,8 @@ public void testFindDomainObject_WhenObjectIsInsideBkm() { final String uuid = "someUuid"; final BusinessKnowledgeModel bkm = mock(BusinessKnowledgeModel.class); - doReturn(false).when(view).innerExpressionMatches(uuid); + doReturn(false).when(view).currentDomainObjectMatches(uuid); + doReturn(false).when(view).innerExpressionMatches(eq(uuid)); doReturn(true).when(view).businessKnowledgeModelMatches(uuid); doReturn(bkm).when(view).getBusinessKnowledgeModel(); @@ -829,7 +831,7 @@ public void testFindDomainObject_WhenObjectIsTheInnerExpression() { final String uuid = "someUuid"; - doReturn(true).when(view).innerExpressionMatches(uuid); + doReturn(true).when(view).currentDomainObjectMatches(uuid); final DomainObject foundDomainObject = view.findDomainObject(uuid); @@ -854,6 +856,7 @@ public void testFindDomainObjectInCurrentExpression_WhenIsNotFound() { when(expression.findDomainObject(uuid)).thenReturn(Optional.empty()); when(hasExpression.getExpression()).thenReturn(expression); + doReturn(false).when(view).innerExpressionMatches(uuid); final DomainObject domainObject = view.findDomainObjectInCurrentExpression(uuid); @@ -877,4 +880,40 @@ public void testFindDomainObjectInCurrentExpression_WhenIsFound() { assertFalse(result instanceof NOPDomainObject); assertEquals(domainObject, result); } + + @Test + public void testInnerExpressionMatches() { + + final String uuid = "uuid"; + final Id id = new Id(uuid); + final Expression expression = mock(Expression.class); + + when(expression.getId()).thenReturn(id); + when(hasExpression.getExpression()).thenReturn(expression); + + assertTrue(view.innerExpressionMatches(uuid)); + } + + @Test + public void testInnerExpressionMatches_WhenDoesNot() { + + final String uuid = "uuid"; + final Id id = new Id(uuid); + final Expression expression = mock(Expression.class); + + when(expression.getId()).thenReturn(id); + when(hasExpression.getExpression()).thenReturn(expression); + + assertFalse(view.innerExpressionMatches("anotherUuid")); + } + + @Test + public void testInnerExpressionMatches_WhenExpressionIsNull() { + + final String uuid = "uuid"; + + when(hasExpression.getExpression()).thenReturn(null); + + assertFalse(view.innerExpressionMatches(uuid)); + } }