Skip to content

Commit

Permalink
[822] Add the DiagramDescription in the context of the DiagramWebSock…
Browse files Browse the repository at this point in the history
…etContainer

It will allow us to compute additional information such as the list of all
the unsynchronized nodes and edges in order to perform some operations

Bug: #822
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jan 14, 2022
1 parent 49cda1f commit d06e77a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,28 @@ type DiagramDescription implements RepresentationDescription {
id: ID!
label: String!
autoLayout: Boolean!
nodeDescriptions: [NodeDescription!]!
edgeDescriptions: [EdgeDescription!]!
toolSections: [ToolSection!]!
}

type NodeDescription {
id: ID!
synchronizationPolicy: SynchronizationPolicy!
borderNodeDescriptions: [NodeDescription!]!
childNodeDescriptions: [NodeDescription!]!
}

type EdgeDescription {
id: ID!
synchronizationPolicy: SynchronizationPolicy!
sourceNodeDescriptions: [NodeDescription!]!
targetNodeDescriptions: [NodeDescription!]!
}

enum SynchronizationPolicy {
SYNCHRONIZED
UNSYNCHRONIZED
}

extend type Mutation {
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/diagram/DiagramWebSocketContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
SetContextualMenuEvent,
SetContextualPaletteEvent,
SetDefaultToolEvent,
SetToolSectionsEvent,
SetDiagramDescriptionEvent,
ShowSelectionDialogEvent,
ShowToastEvent,
SubscribersUpdatedEvent,
Expand Down Expand Up @@ -707,10 +707,11 @@ export const DiagramWebSocketContainer = ({
if (!toolSectionLoading && diagramWebSocketContainer === 'ready' && toolSectionData) {
const representationDescription = toolSectionData.viewer.editingContext.representation.description;
if (isDiagramDescription(representationDescription)) {
const { toolSections } = representationDescription;

const setToolSectionsEvent: SetToolSectionsEvent = { type: 'SET_TOOL_SECTIONS', toolSections: toolSections };
dispatch(setToolSectionsEvent);
const setDiagramDescriptionEvent: SetDiagramDescriptionEvent = {
type: 'SET_DIAGRAM_DESCRIPTION',
diagramDescription: representationDescription,
};
dispatch(setDiagramDescriptionEvent);
}
}
}, [toolSectionLoading, toolSectionData, diagramWebSocketContainer, dispatch]);
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/diagram/DiagramWebSocketContainer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ export interface GQLRepresentationDescription {

export interface GQLDiagramDescription extends GQLRepresentationDescription {
toolSections: GQLToolSection[];
nodeDescriptions: GQLNodeDescription[];
edgdDescriptions: GQLEdgeDescription[];
}

export interface GQLNodeDescription {
id: string;
synchronizationPolicy: GQLSynchronizationPolicy;
childNodeDescriptions: GQLNodeDescription[] | undefined;
borderNodeDescriptions: GQLNodeDescription[] | undefined;
}

export interface GQLEdgeDescription {
id: string;
synchronizationPolicy: GQLSynchronizationPolicy;
sourceNodeDescriptions: GQLNodeDescription[];
targetNodeDescriptions: GQLNodeDescription[];
}

export enum GQLSynchronizationPolicy {
SYNCHRONIZED = 'SYNCHRONIZED',
UNSYNCHRONIZED = 'UNSYNCHRONIZED',
}

export interface GQLRepresentation {
Expand Down
34 changes: 17 additions & 17 deletions frontend/src/diagram/DiagramWebSocketContainerMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*******************************************************************************/
import {
CreateEdgeTool,
GQLToolSection,
GQLDiagramDescription,
Menu,
Palette,
Position,
Expand Down Expand Up @@ -65,6 +65,7 @@ export interface DiagramWebSocketContainerContext {
displayedRepresentationId: string | null;
diagramServer: DiagramServer;
diagram: GQLDiagram;
diagramDescription: GQLDiagramDescription | null;
toolSections: ToolSection[];
activeTool: Tool | null;
activeConnectorTools: CreateEdgeTool[];
Expand All @@ -88,7 +89,7 @@ export type HandleSelectedObjectInSelectionDialogEvent = {
};
export type ResetSelectedObjectInSelectionDialogEvent = { type: 'RESET_SELECTED_OBJECT_IN_SELECTION_DIALOG' };
export type SwithRepresentationEvent = { type: 'SWITCH_REPRESENTATION'; representationId: string };
export type SetToolSectionsEvent = { type: 'SET_TOOL_SECTIONS'; toolSections: GQLToolSection[] };
export type SetDiagramDescriptionEvent = { type: 'SET_DIAGRAM_DESCRIPTION'; diagramDescription: GQLDiagramDescription };
export type SetDefaultToolEvent = { type: 'SET_DEFAULT_TOOL'; defaultTool: Tool };
export type DiagramRefreshedEvent = { type: 'HANDLE_DIAGRAM_REFRESHED'; diagram: GQLDiagram };
export type SubscribersUpdatedEvent = { type: 'HANDLE_SUBSCRIBERS_UPDATED'; subscribers: Subscriber[] };
Expand Down Expand Up @@ -128,7 +129,7 @@ export type DiagramWebSocketContainerEvent =
| ResetSelectedObjectInSelectionDialogEvent
| SwithRepresentationEvent
| InitializeRepresentationEvent
| SetToolSectionsEvent
| SetDiagramDescriptionEvent
| SetDefaultToolEvent
| DiagramRefreshedEvent
| SubscribersUpdatedEvent
Expand Down Expand Up @@ -161,6 +162,7 @@ export const diagramWebSocketContainerMachine = Machine<
displayedRepresentationId: null,
diagramServer: null,
diagram: null,
diagramDescription: null,
toolSections: [],
activeTool: null,
activeConnectorTools: [],
Expand Down Expand Up @@ -232,9 +234,9 @@ export const diagramWebSocketContainerMachine = Machine<
actions: 'switchRepresentation',
},
],
SET_TOOL_SECTIONS: [
SET_DIAGRAM_DESCRIPTION: [
{
actions: 'setToolSections',
actions: 'setDiagramDescription',
},
],
SET_DEFAULT_TOOL: [
Expand Down Expand Up @@ -416,21 +418,19 @@ export const diagramWebSocketContainerMachine = Machine<
};
}),

setToolSections: assign((_, event) => {
const { toolSections } = event as SetToolSectionsEvent;
setDiagramDescription: assign((_, event) => {
const { diagramDescription } = event as SetDiagramDescriptionEvent;

let toolSectionsWithDefaults = [];
if (toolSections) {
toolSectionsWithDefaults = toolSections.map((toolSection) => {
if (toolSection.tools && toolSection.tools.length > 0) {
return { ...toolSection, defaultTool: toolSection.tools[0] };
} else {
return { ...toolSection, defaultTool: null };
}
});
}
toolSectionsWithDefaults = diagramDescription.toolSections.map((toolSection) => {
if (toolSection.tools && toolSection.tools.length > 0) {
return { ...toolSection, defaultTool: toolSection.tools[0] };
} else {
return { ...toolSection, defaultTool: null };
}
});

return { toolSections: toolSectionsWithDefaults };
return { diagramDescription, toolSections: toolSectionsWithDefaults };
}),

setDefaultTool: assign((context, event) => {
Expand Down
54 changes: 54 additions & 0 deletions frontend/src/diagram/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,60 @@ export const getToolSectionsQuery = gql`
}
}
}
nodeDescriptions {
id
synchronizationPolicy
borderNodeDescriptions {
id
synchronizationPolicy
}
childNodeDescriptions {
id
synchronizationPolicy
borderNodeDescriptions {
id
synchronizationPolicy
}
childNodeDescriptions {
id
synchronizationPolicy
borderNodeDescriptions {
id
synchronizationPolicy
}
childNodeDescriptions {
id
synchronizationPolicy
borderNodeDescriptions {
id
synchronizationPolicy
}
childNodeDescriptions {
id
synchronizationPolicy
borderNodeDescriptions {
id
synchronizationPolicy
}
}
}
}
}
}
edgeDescriptions {
id
synchronizationPolicy
sourceNodeDescriptions {
id
synchronizationPolicy
}
targetNodeDescriptions {
id
synchronizationPolicy
}
}
}
}
}
Expand Down

0 comments on commit d06e77a

Please sign in to comment.