Skip to content

Commit

Permalink
[4195] Prevent objects disappearing when dropped on themselves in the…
Browse files Browse the repository at this point in the history
… Explorer

Bug: #4195
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid authored and sbegaudeau committed Nov 19, 2024
1 parent c0a6b02 commit c414633
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

=== Bug fixes


- https://github.com/eclipse-sirius/sirius-web/issues/4195[#4195] [sirius-web] Prevent objects disappearing when dropped on themselves (or a descendant) in the _Explorer_.

=== New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private IStatus moveObjects(List<EObject> objectsToMove, EObject targetContainer
.flatMap(children -> this.getContainerChild(children, this.objectService.getId(targetContainer)).stream())
.toList();
return objectsToMove.stream()
.filter(eObject -> !EcoreUtil.isAncestor(eObject, targetContainer))
.map(source -> {
Optional<EStructuralFeature> optionalFeature = this.getContainmentFeatureName(source, targetContainer)
.map(featureName -> targetContainer.eClass().getEStructuralFeature(featureName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.eclipse.sirius.components.collaborative.trees.dto.DropTreeItemInput;
import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload;
import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.SuccessPayload;
import org.eclipse.sirius.components.trees.tests.graphql.DropTreeItemMutationRunner;
import org.eclipse.sirius.web.AbstractIntegrationTests;
Expand Down Expand Up @@ -224,4 +225,58 @@ public void givenStudioWhenWeDragAndDropAnItemToSpecificPositionThenTheObjectIsM
.verify(Duration.ofSeconds(10));
}

@Test
@DisplayName("Given a studio, when we drag and drop an item on itself in the explorer, then nothing is changed")
@Sql(scripts = { "/scripts/studio.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void givenStudioWhenWeDragAndDropAnItemOnItselfTheNothingIsChanged() {
var expandedIds = List.of(
StudioIdentifiers.DOMAIN_DOCUMENT.toString(),
StudioIdentifiers.DOMAIN_OBJECT.toString(),
StudioIdentifiers.ROOT_ENTITY_OBJECT.toString(),
StudioIdentifiers.NAMED_ELEMENT_ENTITY_OBJECT.toString()
);
var explorerRepresentationId = this.representationIdBuilder.buildExplorerRepresentationId(ExplorerDescriptionProvider.DESCRIPTION_ID, expandedIds, List.of());
var input = new ExplorerEventInput(UUID.randomUUID(), StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString(), explorerRepresentationId);
var flux = this.treeEventSubscriptionRunner.run(input);


Consumer<Object> initialTreeContentConsumer = object -> Optional.of(object)
.filter(DataFetcherResult.class::isInstance)
.map(DataFetcherResult.class::cast)
.map(DataFetcherResult::getData)
.filter(TreeRefreshedEventPayload.class::isInstance)
.map(TreeRefreshedEventPayload.class::cast)
.map(TreeRefreshedEventPayload::tree)
.ifPresentOrElse(tree -> {
assertThat(tree).isNotNull();
assertThat(tree.getChildren().get(1).getChildren().get(0).getChildren().get(0).getChildren()).hasSize(3);
assertThat(tree.getChildren().get(1).getChildren().get(0).getChildren().get(1).getChildren()).hasSize(1);
assertThat(tree.getChildren().get(1).getChildren().get(0).getChildren().get(1).getChildren()).anyMatch(treeItem -> treeItem.getId().equals(StudioIdentifiers.NAME_ATTRIBUTE_OBJECT.toString()));
}, () -> fail("Missing tree"));

Runnable dropItemMutation = () -> {
DropTreeItemInput dropTreeItemInput = new DropTreeItemInput(
UUID.randomUUID(), StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString(),
explorerRepresentationId,
List.of(StudioIdentifiers.NAME_ATTRIBUTE_OBJECT.toString()),
StudioIdentifiers.NAME_ATTRIBUTE_OBJECT.toString(),
-1
);
var result = this.dropTreeItemMutationRunner.run(dropTreeItemInput);
String typename = JsonPath.read(result, "$.data.dropTreeItem.__typename");
assertThat(typename).isEqualTo(ErrorPayload.class.getSimpleName());

TestTransaction.flagForCommit();
TestTransaction.end();
TestTransaction.start();
};

StepVerifier.create(flux)
.consumeNextWith(initialTreeContentConsumer)
.then(dropItemMutation)
.thenCancel()
.verify(Duration.ofSeconds(10));
}

}

0 comments on commit c414633

Please sign in to comment.