diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 86e85fc19..78b55c295 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -38,6 +38,7 @@ It has long been unused by Sirius Web itself (since the transition to MUI). - https://github.com/eclipse-syson/syson/issues/2331[#2331] [diagrams] Fix the broken `New Interface` tool icon. - https://github.com/eclipse-syson/syson/issues/2320[#2320] [diagrams] Add an explicit warning message when user tries to reconnect one Actor's edge to another Actor. - https://github.com/eclipse-syson/syson/issues/2329[#2329] [import] Fix importing requirement (and sub-requirement) a text. +- https://github.com/eclipse-syson/syson/issues/2336[#2336] [details] Fix _Edit expression_ modal when the selected element is a `FeatureValue` === Improvements diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/expressions/ExpressionsControllersIntegrationTests.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/expressions/ExpressionsControllersIntegrationTests.java index f511fb788..22d39e931 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/expressions/ExpressionsControllersIntegrationTests.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/expressions/ExpressionsControllersIntegrationTests.java @@ -324,6 +324,51 @@ public void textEditAttributeExpression() { .verify(Duration.ofSeconds(10)); } + @DisplayName("GIVEN a SysML the FeatueValue of an attribute that has an existing expression, WHEN editing the expression to a new one THEN the attribute's expression is replaced") + @GivenSysONServer({ ExpressionSamplesProjectData.SCRIPT_PATH }) + @Test + public void textEditFeatureValueExpression() { + String editingContextId = ExpressionSamplesProjectData.EDITING_CONTEXT_ID; + + List defaultFilters = this.explorerDefaultFiltersSearchService.findTreeDefaultFilterIds(editingContextId, this.sysONExplorerTreeDescriptionId); + var explorerRepresentationId = this.representationIdBuilder.buildExplorerRepresentationId(this.sysONExplorerTreeDescriptionId, List.of(), defaultFilters); + var explorerInput = new ExplorerEventInput(UUID.randomUUID(), editingContextId, explorerRepresentationId); + var flux = this.explorerEventSubscriptionRunner.run(explorerInput).flux(); + + var treeId = new AtomicReference(); + Consumer initialTreeContentConsumer = assertRefreshedTreeThat(tree -> { + assertThat(tree).isNotNull(); + treeId.set(tree.getId()); + }); + + var existingExpressionId = new AtomicReference(); + + Runnable checkInitialExpression = this.checkElementHasExpression(editingContextId, + ExpressionSamplesProjectData.SemanticIds.TANK_MAX_VOLUME_ATTRIBUTE_FEATURE_VALUE_ID, FeatureValue.class, existingExpressionId, + "100.0 * minVolume"); + + Runnable editExpressionOnMaxVolumeAttribute = this.editExpression(editingContextId, existingExpressionId::get, "50 * minVolume"); + + Consumer treeRefreshed = assertRefreshedTreeThat(tree -> { + assertThat(tree).isNotNull(); + assertThat(tree.getId()).isEqualTo(treeId.get()); + }); + + Runnable checkExpressionUpdated = this.checkElementHasExpression(editingContextId, ExpressionSamplesProjectData.SemanticIds.TANK_MAX_VOLUME_ATTRIBUTE_FEATURE_VALUE_ID, + FeatureValue.class, + existingExpressionId, + "50 * minVolume"); + + StepVerifier.create(flux) + .consumeNextWith(initialTreeContentConsumer) + .then(checkInitialExpression) + .then(editExpressionOnMaxVolumeAttribute) + .consumeNextWith(treeRefreshed) + .then(checkExpressionUpdated) + .thenCancel() + .verify(Duration.ofSeconds(10)); + } + @DisplayName("GIVEN a SysML attribute with a value expression, WHEN editing it with feature value properties THEN the flags are updated together with the expression") @GivenSysONServer({ ExpressionSamplesProjectData.SCRIPT_PATH }) @Test diff --git a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/ExpressionSamplesProjectData.java b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/ExpressionSamplesProjectData.java index ec9d8c94e..547843014 100644 --- a/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/ExpressionSamplesProjectData.java +++ b/backend/application/syson-application/src/test/java/org/eclipse/syson/application/data/ExpressionSamplesProjectData.java @@ -38,6 +38,8 @@ public static final class SemanticIds { public static final String TANK_MAX_VOLUME_ATTRIBUTE_ID = "d9926727-7378-4177-a940-2fb6c1c89dce"; + public static final String TANK_MAX_VOLUME_ATTRIBUTE_FEATURE_VALUE_ID = "8f9592ef-9513-4025-ab13-e7d7f822f7d8"; + public static final String TANK_MAX_VOLUME_ATTRIBUTE_VALUE_ID = "a9216e54-f44c-4b1f-b262-13650324d325"; public static final String TANK_PRESSURE_LIMIT_CONSTRAINT_ID = "7d42ee06-3c27-4eaa-9438-344fc789906a"; diff --git a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/services/EditExpressionEventHandler.java b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/services/EditExpressionEventHandler.java index 095e315e4..d2b38599d 100644 --- a/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/services/EditExpressionEventHandler.java +++ b/backend/application/syson-sysml-import/src/main/java/org/eclipse/syson/sysml/services/EditExpressionEventHandler.java @@ -29,6 +29,7 @@ import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; import org.eclipse.syson.sysml.Element; import org.eclipse.syson.sysml.Expression; +import org.eclipse.syson.sysml.Relationship; import org.eclipse.syson.sysml.dto.EditExpressionInput; import org.eclipse.syson.sysml.dto.EditExpressionSuccessPayload; import org.eclipse.syson.sysml.metamodel.services.MetamodelQueryElementService; @@ -87,7 +88,11 @@ public void handle(Sinks.One payloadSink, Sinks.Many findSingleExpressionDefinition(Element element) { if (this.isExpressionDefinition(element)) { result = Optional.of((Expression) element); } else { - var ownedExpressions = element.getOwnedElement().stream().filter(child -> this.isExpressionDefinition(child)).toList(); + EList ownedElements; + if (element instanceof Relationship relationship) { + ownedElements = relationship.getOwnedRelatedElement(); + } else { + ownedElements = element.getOwnedElement(); + } + var ownedExpressions = ownedElements.stream().filter(child -> this.isExpressionDefinition(child)).toList(); if (ownedExpressions.size() == 1) { result = Optional.of((Expression) ownedExpressions.get(0)); }