Skip to content

Commit

Permalink
[932] Introduce the RepresentationMetadata concept
Browse files Browse the repository at this point in the history
Bug: #932
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jan 12, 2022
1 parent 884f3d3 commit a6b4084
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [core] `IEditService.findClass()` has been removed
- [core] `IRepresentationDescriptionSearchService` has a new `findAll` method to return all the representation descriptions available in a given editing context
- [core] The package containing the concepts related to the editing context has been renamed to remove references to the project
- https://github.com/eclipse-sirius/sirius-components/issues/932[#932] [graphql] Introduce the RepresentationMetadata concept in order to prepare the separation of the metadata from the representation

=== Dependency update

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public ToolService(IRepresentationDescriptionSearchService representationDescrip
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
}

@Override
public List<ToolSection> getToolSections(IEditingContext editingContext, Diagram diagram) {
private List<ToolSection> getToolSections(IEditingContext editingContext, Diagram diagram) {
// @formatter:off
return this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId())
.filter(DiagramDescription.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
*******************************************************************************/
package org.eclipse.sirius.web.spring.collaborative.diagrams.api;

import java.util.List;
import java.util.Optional;

import org.eclipse.sirius.web.core.api.IEditingContext;
import org.eclipse.sirius.web.diagrams.Diagram;
import org.eclipse.sirius.web.diagrams.tools.ITool;
import org.eclipse.sirius.web.diagrams.tools.ToolSection;

/**
* Interface used to manipulate tools.
Expand All @@ -27,22 +25,6 @@
*/
public interface IToolService {

/**
* Find a specific tool according to the given diagram and tool identifiers.
*
* @param diagram
* the diagram
* @param toolId
* the tool identifier
*/
Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId);

/**
* Get all tool sections available in a specific diagram.
*
* @param diagram
* the diagram
*/
List<ToolSection> getToolSections(IEditingContext editingContext, Diagram diagram);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Diagram implements Representation {
position: Position!
nodes: [Node!]!
edges: [Edge!]!
toolSections: [ToolSection!]!
}

type Node {
Expand Down Expand Up @@ -190,6 +189,7 @@ type DiagramDescription implements RepresentationDescription {
id: ID!
label: String!
autoLayout: Boolean!
toolSections: [ToolSection!]!
}

type NodeDescription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Viewer {
type EditingContext {
id: ID!
domains: [Domain!]!
representation(representationId: ID!): Representation
representation(representationId: ID!): RepresentationMetadata
representations: EditingContextRepresentationConnection!
representationDescriptions(kind: ID!): EditingContextRepresentationDescriptionConnection!
stereotypeDescriptions: EditingContextStereotypeDescriptionConnection!
Expand All @@ -32,6 +32,13 @@ type Domain {
label: String!
}

type RepresentationMetadata {
id: ID!
label: String!
kind: String!
description: RepresentationDescription!
}

interface Representation {
id: ID!
kind: String!
Expand Down Expand Up @@ -60,7 +67,7 @@ type EditingContextRepresentationConnection {
}

type EditingContextRepresentationEdge {
node: Representation!
node: RepresentationMetadata!
}

type EditingContextRepresentationDescriptionConnection {
Expand Down Expand Up @@ -201,7 +208,7 @@ union CreateRepresentationPayload = ErrorPayload | CreateRepresentationSuccessPa

type CreateRepresentationSuccessPayload {
id: ID!
representation: Representation!
representation: RepresentationMetadata!
}

input CreateRootObjectInput {
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/diagram/DiagramWebSocketContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { ServerContext } from 'common/ServerContext';
import {
CreateEdgeTool,
CreateNodeTool,
GQLDiagram,
GQLDiagramDescription,
GQLDiagramEventPayload,
GQLDiagramEventSubscription,
GQLDiagramRefreshedEventPayload,
GQLErrorPayload,
Expand Down Expand Up @@ -94,7 +95,6 @@ import {
import { edgeCreationFeedback } from 'diagram/sprotty/edgeCreationFeedback';
import { Toolbar } from 'diagram/Toolbar';
import { atLeastOneCanInvokeEdgeTool, canInvokeTool } from 'diagram/toolServices';
import { GQLDiagramEventPayload } from 'index';
import React, { useCallback, useContext, useEffect, useRef } from 'react';
import { SelectionDialogWebSocketContainer } from 'selection/SelectionDialogWebSocketContainer';
import { EditLabelAction, FitToScreenAction, HoverFeedbackAction, SEdge, SGraph, SModelElement, SNode } from 'sprotty';
Expand Down Expand Up @@ -136,7 +136,8 @@ const useDiagramWebSocketContainerStyle = makeStyles((theme) => ({
},
}));

const isDiagram = (representation): representation is GQLDiagram => representation.__typename === 'Diagram';
const isDiagramDescription = (representationDescription): representationDescription is GQLDiagramDescription =>
representationDescription.__typename === 'DiagramDescription';
const isDiagramRefreshedEventPayload = (payload: GQLDiagramEventPayload): payload is GQLDiagramRefreshedEventPayload =>
payload.__typename === 'DiagramRefreshedEventPayload';
const isSubscribersUpdatedEventPayload = (
Expand Down Expand Up @@ -704,9 +705,9 @@ export const DiagramWebSocketContainer = ({

useEffect(() => {
if (!toolSectionLoading && diagramWebSocketContainer === 'ready' && toolSectionData) {
const representation = toolSectionData.viewer.editingContext.representation;
if (isDiagram(representation)) {
const { toolSections } = representation;
const representationDescription = toolSectionData.viewer.editingContext.representation.description;
if (isDiagramDescription(representationDescription)) {
const { toolSections } = representationDescription;

const setToolSectionsEvent: SetToolSectionsEvent = { type: 'SET_TOOL_SECTIONS', toolSections: toolSections };
dispatch(setToolSectionsEvent);
Expand Down
23 changes: 20 additions & 3 deletions frontend/src/diagram/DiagramWebSocketContainer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,30 @@ export interface GQLViewer {
}

export interface GQLEditingContext {
representation: GQLRepresentation;
representation: GQLRepresentationMetadata;
}

export interface GQLRepresentationMetadata {
id: string;
label: string;
kind: string;
description: GQLRepresentationDescription;
}

export interface GQLRepresentationDescription {
id: string;
}

export interface GQLDiagramDescription extends GQLRepresentationDescription {
toolSections: GQLToolSection[];
}

export interface GQLRepresentation {
__typename: string;
id: string;
label: string;
kind: string;
}

export interface GQLDiagram extends GQLRepresentation {
id: string;
label: string;
Expand All @@ -131,7 +149,6 @@ export interface GQLDiagram extends GQLRepresentation {
position: GQLPosition;
nodes: GQLNode[];
edges: GQLEdge[];
toolSections: GQLToolSection[];
}

export interface GQLSize {
Expand Down
42 changes: 22 additions & 20 deletions frontend/src/diagram/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,33 @@ export const getToolSectionsQuery = gql`
viewer {
editingContext(editingContextId: $editingContextId) {
representation(representationId: $diagramId) {
... on Diagram {
toolSections {
id
label
imageURL
tools {
__typename
description {
... on DiagramDescription {
toolSections {
id
label
imageURL
... on CreateNodeTool {
targetDescriptions {
id
tools {
__typename
id
label
imageURL
... on CreateNodeTool {
targetDescriptions {
id
}
appliesToDiagramRoot
selectionDescriptionId
}
appliesToDiagramRoot
selectionDescriptionId
}
... on CreateEdgeTool {
edgeCandidates {
...edgeCandidateField
... on CreateEdgeTool {
edgeCandidates {
...edgeCandidateField
}
}
}
... on DeleteTool {
targetDescriptions {
id
... on DeleteTool {
targetDescriptions {
id
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/diagram/sprotty/__tests__/siriusWebDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const siriusWebDiagram: GQLDiagram = {
label: 'Topography',
descriptionId: "inmemory.odesign#//@ownedViewpoints[name='Exchanges']/@ownedRepresentations[name='Topography']",
autoLayout: false,
toolSections: [],
__typename: 'Diagram',
position: {
x: 0,
y: 0,
Expand Down

0 comments on commit a6b4084

Please sign in to comment.