eclipse-sirius / sirius-web

Sirius Web: open-source low-code platform to define custom web applications supporting your specific visual languages
https://eclipse.dev/sirius/sirius-web.html
Eclipse Public License 2.0
72 stars 48 forks source link

The edge creation feedback is still activated when the connector tool tries to display available tools #1378

Open gcoutable opened 1 year ago

gcoutable commented 1 year ago

Screenshots

image

Steps to reproduce

Create View

  1. Create a Diagram Description in a new View Model (domain type: flow::System)
  2. Add a Node Description (domain type: flow::CompositeProcessor)
  3. Add an Edge Description (domain type: flow::DataFlow)
  4. Add two edge Tool for the Edge Description (no need to make them actually do something)

Reproduce

  1. In the same project, create a robot flow model
  2. Create a new diagram based on the created diagram description above
  3. Create an edge using the connector tool (first tool in the palette)

Expected behavior

A sub-menu should display the two edge creation tool defined in the edge description.

Actual behavior

An error is raised instead of displaying available tools and, the edge creation feedback is still activated.

gcoutable commented 1 year ago

The issue may be fixed by making the payload from GetConnectorToolsEventHandler not return a null payload.

pcdavid commented 1 year ago

The issue may be fixed by making the payload from GetConnectorToolsEventHandler not return a null payload.

That will not be enough (I tested). If the handler returns an empty list of candidate tools, the frontend never displays the context menu, so no edge tool is invoked.

  1. The end user gets zero feedback about what is wrong.
  2. The edgeCreationFeedback.reset() is never called on the frontend (it's normally invoked after we call a tool), so the edge creaation feedback stays active.
pcdavid commented 1 year ago

FWIW, I had started an attempt to fix this:

diff --git a/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/GetConnectorToolsEventHandler.java b/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/GetConnectorToolsEventHandler.java
index af5b1af80..71fd41c0b 100644
--- a/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/GetConnectorToolsEventHandler.java
+++ b/packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/handlers/GetConnectorToolsEventHandler.java
@@ -123,6 +123,8 @@ public class GetConnectorToolsEventHandler implements IDiagramEventHandler {
                     }

                     payload = new GetConnectorToolsSuccessPayload(diagramInput.getId(), connectorTools);
+                } else {
+                    payload = new GetConnectorToolsSuccessPayload(diagramInput.getId(), List.of());
                 }
             }
         } else {
diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/palette/ContextualMenu.tsx b/packages/diagrams/frontend/sirius-components-diagrams/src/palette/ContextualMenu.tsx
index a3474ed41..777b1c14a 100644
--- a/packages/diagrams/frontend/sirius-components-diagrams/src/palette/ContextualMenu.tsx
+++ b/packages/diagrams/frontend/sirius-components-diagrams/src/palette/ContextualMenu.tsx
@@ -135,6 +135,13 @@ export const ContextualMenu = ({
     }
   });

+  // Close properly when there are no tools to propose.
+  useEffect(() => {
+    if (contextualMenu === 'loaded' && connectorTools.length === 0) {
+      invokeClose();
+    }
+  }, [contextualMenu, connectorTools, invokeClose]);
+
   const onToolClick = useCallback(
     (tool) => {
       invokeTool(tool);

The patch is old, I don't remember if it fixed the issue completely or not. Feel free to ignore it if it is not relevant anymore.