11/*******************************************************************************
2- * Copyright (c) 2023, 2025 Obeo.
2+ * Copyright (c) 2023, 2026 Obeo.
33 * This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v2.0
55 * which accompanies this distribution, and is available at
1111 * Obeo - initial API and implementation
1212 *******************************************************************************/
1313
14- import { gql , useMutation , useQuery } from '@apollo/client' ;
14+ import { gql , useMutation } from '@apollo/client' ;
1515import { IconOverlay , useMultiToast } from '@eclipse-sirius/sirius-components-core' ;
1616import ListItemIcon from '@mui/material/ListItemIcon' ;
1717import Menu from '@mui/material/Menu' ;
@@ -27,52 +27,18 @@ import { EdgeData, NodeData } from '../DiagramRenderer.types';
2727import { isCursorNearCenterOfTheNode } from '../edge/EdgeLayout' ;
2828import {
2929 ConnectorContextualMenuProps ,
30- GetConnectorToolsData ,
31- GetConnectorToolsVariables ,
32- GQLDiagramDescription ,
3330 GQLErrorPayload ,
3431 GQLInvokeSingleClickOnTwoDiagramElementsToolData ,
3532 GQLInvokeSingleClickOnTwoDiagramElementsToolInput ,
3633 GQLInvokeSingleClickOnTwoDiagramElementsToolPayload ,
3734 GQLInvokeSingleClickOnTwoDiagramElementsToolSuccessPayload ,
3835 GQLInvokeSingleClickOnTwoDiagramElementsToolVariables ,
39- GQLRepresentationDescription ,
4036 GQLTool ,
4137 GQLToolVariable ,
4238} from './ConnectorContextualMenu.types' ;
4339import { useConnector } from './useConnector' ;
4440import { GQLSingleClickOnTwoDiagramElementsTool } from './useConnector.types' ;
45-
46- export const getConnectorToolsQuery = gql `
47- query getConnectorTools(
48- $editingContextId: ID!
49- $representationId: ID!
50- $sourceDiagramElementId: ID!
51- $targetDiagramElementId: ID!
52- ) {
53- viewer {
54- editingContext(editingContextId: $editingContextId) {
55- representation(representationId: $representationId) {
56- description {
57- ... on DiagramDescription {
58- connectorTools(
59- sourceDiagramElementId: $sourceDiagramElementId
60- targetDiagramElementId: $targetDiagramElementId
61- ) {
62- id
63- label
64- iconURL
65- ... on SingleClickOnTwoDiagramElementsTool {
66- dialogDescriptionId
67- }
68- }
69- }
70- }
71- }
72- }
73- }
74- }
75- ` ;
41+ import { useConnectorPaletteContents } from './useConnectorPaletteContents' ;
7642
7743export const invokeSingleClickOnTwoDiagramElementsToolMutation = gql `
7844 mutation invokeSingleClickOnTwoDiagramElementsTool($input: InvokeSingleClickOnTwoDiagramElementsToolInput!) {
@@ -100,10 +66,6 @@ export const invokeSingleClickOnTwoDiagramElementsToolMutation = gql`
10066 }
10167` ;
10268
103- const isDiagramDescription = (
104- representationDescription : GQLRepresentationDescription
105- ) : representationDescription is GQLDiagramDescription => representationDescription . __typename === 'DiagramDescription' ;
106-
10769const isErrorPayload = ( payload : GQLInvokeSingleClickOnTwoDiagramElementsToolPayload ) : payload is GQLErrorPayload =>
10870 payload . __typename === 'ErrorPayload' ;
10971const isSuccessPayload = (
@@ -136,16 +98,7 @@ const ConnectorContextualMenuComponent = memo(({}: ConnectorContextualMenuProps)
13698 const sourceDiagramElementId = connectionSource ?. dataset . id ?? '' ;
13799 const targetDiagramElementId = connectionTarget ?. dataset . id ?? '' ;
138100
139- const variables : GetConnectorToolsVariables = {
140- editingContextId,
141- representationId : diagramId ,
142- sourceDiagramElementId,
143- targetDiagramElementId,
144- } ;
145- const { loading, data, error } = useQuery < GetConnectorToolsData , GetConnectorToolsVariables > ( getConnectorToolsQuery , {
146- variables,
147- skip : ! connectionSource || ! connectionTarget ,
148- } ) ;
101+ const { connectorTools, loading } = useConnectorPaletteContents ( sourceDiagramElementId , targetDiagramElementId ) ;
149102
150103 const invokeOpenSelectionDialog = ( tool : GQLSingleClickOnTwoDiagramElementsTool ) => {
151104 const onConfirm = ( variables : GQLToolVariable [ ] ) => {
@@ -168,12 +121,6 @@ const ConnectorContextualMenuComponent = memo(({}: ConnectorContextualMenuProps)
168121 }
169122 } ;
170123
171- useEffect ( ( ) => {
172- if ( error ) {
173- addErrorMessage ( error . message ) ;
174- }
175- } , [ error ] ) ;
176-
177124 const [
178125 invokeSingleClickOnTwoDiagramElementsTool ,
179126 {
@@ -257,24 +204,17 @@ const ConnectorContextualMenuComponent = memo(({}: ConnectorContextualMenuProps)
257204 }
258205 } , [ invokeSingleClickOnTwoDiagramElementToolData , invokeSingleClickOnTwoDiagramElementToolError ] ) ;
259206
260- const connectorTools : GQLTool [ ] = [ ] ;
261- const representationDescription : GQLRepresentationDescription | null | undefined =
262- data ?. viewer . editingContext ?. representation ?. description ;
263- if ( representationDescription && isDiagramDescription ( representationDescription ) ) {
264- representationDescription . connectorTools . forEach ( ( tool ) => connectorTools . push ( tool ) ) ;
265- }
266-
267207 useEffect ( ( ) => {
268208 if ( connectorTools . length > 1 ) {
269209 addTempConnectionLine ( ) ;
270210 }
271211 } , [ connection , connectorTools . length ] ) ;
272212
273213 useEffect ( ( ) => {
274- if ( ! loading && connection && data && connectorTools . length === 0 ) {
214+ if ( ! loading && connection && connectorTools . length === 0 ) {
275215 addMessages ( [ { body : 'No edge found between source and target selected' , level : 'WARNING' } ] ) ;
276216 }
277- } , [ loading , data , connection , connectorTools . length ] ) ;
217+ } , [ loading , connectorTools , connection , connectorTools . length ] ) ;
278218
279219 useEffect ( ( ) => {
280220 return ( ) => removeTempConnectionLine ( ) ;
@@ -286,7 +226,7 @@ const ConnectorContextualMenuComponent = memo(({}: ConnectorContextualMenuProps)
286226 }
287227 } , [ connectorTools ] ) ;
288228
289- if ( ! data || connectorTools . length <= 1 ) {
229+ if ( ! connectorTools || connectorTools . length <= 1 ) {
290230 return null ;
291231 }
292232
0 commit comments