Skip to content

Commit

Permalink
[2080] Add an inital label value when editing tree items label
Browse files Browse the repository at this point in the history
Bug: #2080
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi authored and sbegaudeau committed Jul 3, 2023
1 parent cb6e9cc commit 4d9c791
Show file tree
Hide file tree
Showing 28 changed files with 684 additions and 189 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-components/issues/2080[#2080] [tree] EditingContextRepresentationDataFetcher will filter on IRepresentation unstead of ISemanticRepresentation to be able to support TreeDescription.
+
As such targetObjectId is removed from RepresentationMetadata.

=== Dependency update

- [releng] Switch to Jacoco 0.8.10
- [releng] Switch to Guava 32.0.0-jre

=== Bug fixes

- https://github.com/eclipse-sirius/sirius-components/issues/2058[#2058] [view] Fix an issue where the default icon for List widget candidates was missing when the candidates were not EObjects.
- https://github.com/eclipse-sirius/sirius-components/issues/2058[#2058] [view] Fix an issue where the default icon for List widget candidates was missing when the candidates wer
e not EObjects.
- https://github.com/eclipse-sirius/sirius-components/issues/2060[#2060] [form] Fix an issue where the list widget was displayed on a single line inside a flexbox container, no matter the length of the labels of its items.
- https://github.com/eclipse-sirius/sirius-components/issues/2076[#2076] [sirius-web] Fix `EditingDomainFactoryService` declaration to use an interface.
- https://github.com/eclipse-sirius/sirius-components/issues/2032[#2032] [form] Add domainType on PageDescription in the view DSL and takes into account the impacts for the FormDescriptionAggregator.
Expand All @@ -47,6 +52,7 @@ image:doc/screenshots/ShowIconOptionSelectWidget.jpg[Icons on select widget opti
- https://github.com/eclipse-sirius/sirius-components/issues/2055[#2055] [form] Added initial version of a custom widget to view & edit EMF references (both single and multi-valued).
- https://github.com/eclipse-sirius/sirius-components/issues/2056[#2056] [form] Add the possibility to control read-only mode for widgets with an expression.
- https://github.com/eclipse-sirius/sirius-components/issues/2077[#2077] [form] Add the ability to define a border style for groups and flexbox containers.
- https://github.com/eclipse-sirius/sirius-components/issues/2080[#2080] [tree] Add an inital label value when editing tree items label.

=== Improvements

Expand Down
11 changes: 11 additions & 0 deletions integration-tests/cypress/e2e/project/edit/explorer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('/projects/:projectId/edit - Explorer', () => {
cy.getByTestId('selected').contains('robot');
cy.getByTestId('robot').click();
cy.getByTestId('robot').type('renamed-robot{esc}');
cy.getByTestId('name-edit').should('not.exist');
cy.getByTestId('robot').should('exist');
});

Expand Down Expand Up @@ -167,21 +168,31 @@ describe('/projects/:projectId/edit - Explorer', () => {
cy.getByTestId('tree-root-elements').children().last().contains('robot').should('exist');
cy.getByTestId('tree-root-elements').children().first().contains('robot').should('not.exist');
cy.getByTestId('tree-root-elements').children().last().contains('Flow').should('not.exist');

// Rename Flow Model to sFlow
cy.getByTestId('Flow').click();
cy.getByTestId('Flow-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('rename-tree-item').click();
cy.getByTestId('name-edit').should('exist');
cy.getByTestId('name-edit').get('input').should('have.value', 'Flow');
cy.getByTestId('name-edit').type('sFlow{enter}');
cy.getByTestId('sFlow').should('exist');

// Check documents order
cy.getByTestId('tree-root-elements').children().first().contains('robot').should('exist');
cy.getByTestId('tree-root-elements').children().last().contains('sFlow').should('exist');
cy.getByTestId('tree-root-elements').children().first().contains('sFlow').should('not.exist');
cy.getByTestId('tree-root-elements').children().last().contains('robot').should('not.exist');

// Rename sFlow Model to ROBOT
cy.getByTestId('sFlow').click();
cy.getByTestId('sFlow-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('rename-tree-item').click();
cy.getByTestId('name-edit').should('exist');
cy.getByTestId('name-edit').get('input').should('have.value', 'sFlow');
cy.getByTestId('name-edit').type('ROBOT{enter}');
cy.getByTestId('ROBOT').should('exist');

// Check documents order
cy.getByTestId('tree-root-elements').children().first().contains('robot').should('exist');
cy.getByTestId('tree-root-elements').children().last().contains('ROBOT').should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('/projects/:projectId/edit - Representation Context Menu', () => {
cy.getByTestId('representation-tab-B01').should('not.exist');
cy.getByTestId('A01-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('rename-tree-item').click();
cy.getByTestId('name-edit').should('exist');
cy.getByTestId('name-edit').get('input').should('have.value', 'A01');
cy.getByTestId('name-edit').type('A02{enter}');

/*
Expand All @@ -68,6 +70,8 @@ describe('/projects/:projectId/edit - Representation Context Menu', () => {
cy.getByTestId('representation-tab-B01').should('not.exist');
cy.getByTestId('A01-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('rename-tree-item').click();
cy.getByTestId('name-edit').should('exist');
cy.getByTestId('name-edit').get('input').should('have.value', 'A01');
cy.getByTestId('name-edit').type('A02{enter}');

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -62,9 +62,9 @@ public class NavigationOperationHandlerTests {
private final IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp() {
@Override
public List<RepresentationMetadata> findAllByTargetObjectId(IEditingContext editingContext, String targetObjectId) {
var firstRepresentationMetadata = new RepresentationMetadata(FIRST_DIAGRAM_ID, Diagram.KIND, FIRST_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var secondRepresentationMetadata = new RepresentationMetadata(SECOND_DIAGRAM_ID, Diagram.KIND, SECOND_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var thirdRepresentationMetadata = new RepresentationMetadata(THIRD_DIAGRAM_ID, Diagram.KIND, THIRD_DIAGRAM_LABEL, SECOND_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var firstRepresentationMetadata = new RepresentationMetadata(FIRST_DIAGRAM_ID, Diagram.KIND, FIRST_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID);
var secondRepresentationMetadata = new RepresentationMetadata(SECOND_DIAGRAM_ID, Diagram.KIND, SECOND_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID);
var thirdRepresentationMetadata = new RepresentationMetadata(THIRD_DIAGRAM_ID, Diagram.KIND, THIRD_DIAGRAM_LABEL, SECOND_DIAGRAM_DESCRIPTION_ID);
return List.of(firstRepresentationMetadata, secondRepresentationMetadata, thirdRepresentationMetadata);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import jakarta.annotation.PreDestroy;

import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorFactory;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
Expand All @@ -34,6 +32,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import jakarta.annotation.PreDestroy;
import reactor.core.Disposable;
import reactor.core.publisher.Mono;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -29,14 +29,11 @@ public class RepresentationMetadata {

private final String descriptionId;

private final String targetObjectId;

public RepresentationMetadata(String id, String kind, String label, String descriptionId, String targetObjectId) {
public RepresentationMetadata(String id, String kind, String label, String descriptionId) {
this.id = Objects.requireNonNull(id);
this.kind = Objects.requireNonNull(kind);
this.label = Objects.requireNonNull(label);
this.descriptionId = Objects.requireNonNull(descriptionId);
this.targetObjectId = targetObjectId;
}

public String getId() {
Expand All @@ -55,13 +52,9 @@ public String getDescriptionId() {
return this.descriptionId;
}

public String getTargetObjectId() {
return this.targetObjectId;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, descriptionId: {4}, targetObjectId: {5}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.descriptionId, this.targetObjectId);
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, descriptionId: {4}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.descriptionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.LocalContextConstants;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.eclipse.sirius.components.representations.ISemanticRepresentation;
import org.eclipse.sirius.web.services.api.representations.IRepresentationService;
import org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor;

Expand Down Expand Up @@ -66,22 +63,18 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env

Map<String, Object> localContext = new HashMap<>(environment.getLocalContext());
localContext.put(LocalContextConstants.REPRESENTATION_ID, representationId);

// Search among the active representations first. They are already loaded in memory and include transient
// representations.
// @formatter:off
var representationMetadata = this.editingContextEventProcessorRegistry.getEditingContextEventProcessors().stream()
.flatMap(editingContextEventProcessor -> editingContextEventProcessor.getRepresentationEventProcessors().stream())
.filter(editingContextEventProcessor -> editingContextEventProcessor.getRepresentation().getId().equals(representationId))
.map(IRepresentationEventProcessor::getRepresentation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map((ISemanticRepresentation representation) -> {
.map(representation -> {
return new RepresentationMetadata(representation.getId(),
representation.getKind(),
representation.getLabel(),
representation.getDescriptionId(),
representation.getTargetObjectId());
representation.getDescriptionId());
})
.findFirst();
// @formatter:on
Expand All @@ -90,7 +83,10 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env
if (representationMetadata.isEmpty()) {
representationMetadata = this.representationService.getRepresentationDescriptorForProjectId(editingContextId, representationId)
.map(RepresentationDescriptor::getRepresentation)
.map(this::toRepresentationMetadata);
.map(representation -> new RepresentationMetadata(representation.getId(),
representation.getKind(),
representation.getLabel(),
representation.getDescriptionId()));
}

return DataFetcherResult.<RepresentationMetadata>newResult()
Expand All @@ -99,16 +95,4 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env
.build();
// @formatter:on
}

private RepresentationMetadata toRepresentationMetadata(IRepresentation representation) {
// @formatter:off
String targetObjectId = Optional.of(representation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map(ISemanticRepresentation::getTargetObjectId)
.orElse(null);
// @formatter:on
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId(), targetObjectId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import java.util.Base64;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.eclipse.sirius.components.representations.ISemanticRepresentation;
import org.eclipse.sirius.web.services.api.representations.IRepresentationService;
import org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor;

Expand Down Expand Up @@ -90,14 +88,7 @@ public Connection<RepresentationMetadata> get(DataFetchingEnvironment environmen
}

private RepresentationMetadata toRepresentationMetadata(IRepresentation representation) {
// @formatter:off
String targetObjectId = Optional.of(representation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map(ISemanticRepresentation::getTargetObjectId)
.orElse(null);
// @formatter:on
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId(), targetObjectId);
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId());
}

}
Loading

0 comments on commit 4d9c791

Please sign in to comment.