Skip to content

Commit

Permalink
Fix selected & DiagramContext
Browse files Browse the repository at this point in the history
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Feb 3, 2025
1 parent f05e66d commit 4875861
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { DiagramContextValue } from './DiagramContext.types';
const value: DiagramContextValue = {
editingContextId: '',
diagramId: '',
refreshEventPayloadId: '',
payload: null,
readOnly: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
* Obeo - initial API and implementation
*******************************************************************************/

import { GQLDiagramEventPayload } from '../graphql/subscription/diagramEventSubscription.types';

export interface DiagramContextValue {
editingContextId: string;
diagramId: string;
refreshEventPayloadId: string;
payload: GQLDiagramEventPayload | null;
readOnly: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2025 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import React from 'react';
import { DiagramPayloadContextValue } from './DiagramPayloadContext.types';

const value: DiagramPayloadContextValue = {
refreshEventPayloadId: '',
payload: null,
};

export const DiagramPayloadContext = React.createContext<DiagramPayloadContextValue>(value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2025 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { GQLDiagramEventPayload } from '../graphql/subscription/diagramEventSubscription.types';

export interface DiagramPayloadContextValue {
refreshEventPayloadId: string;
payload: GQLDiagramEventPayload | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node } from '@xyflow/react';
import { InternalNode, Node } from '@xyflow/react';
import { NodeLookup } from '@xyflow/system';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import { GQLDiagram } from '../graphql/subscription/diagramFragment.types';
import { GQLEdge } from '../graphql/subscription/edgeFragment.types';
import { GQLNode, GQLNodeStyle } from '../graphql/subscription/nodeFragment.types';
import { NodeData } from '../renderer/DiagramRenderer.types';
import { GQLDiagramDescription } from '../representation/DiagramRepresentation.types';

export interface IConvertEngine {
convertNodes(
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNodesToConvert: GQLNode<GQLNodeStyle>[],
parentNode: GQLNode<GQLNodeStyle> | null,
Expand All @@ -33,6 +35,7 @@ export interface INodeConverter {

handle(
convertEngine: IConvertEngine,
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLNodeStyle>,
gqlEdges: GQLEdge[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node, XYPosition } from '@xyflow/react';
import { InternalNode, Node, XYPosition } from '@xyflow/react';
import { NodeLookup } from '@xyflow/system';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import { GQLDiagram, GQLNodeLayoutData } from '../graphql/subscription/diagramFragment.types';
import { GQLEdge } from '../graphql/subscription/edgeFragment.types';
Expand All @@ -20,7 +21,7 @@ import {
GQLNodeStyle,
GQLViewModifier,
} from '../graphql/subscription/nodeFragment.types';
import { BorderNodePosition } from '../renderer/DiagramRenderer.types';
import { BorderNodePosition, NodeData } from '../renderer/DiagramRenderer.types';
import { ConnectionHandle } from '../renderer/handles/ConnectionHandles.types';
import { defaultHeight, defaultWidth } from '../renderer/layout/layoutParams';
import { IconLabelNodeData } from '../renderer/node/IconsLabelNode.types';
Expand All @@ -32,6 +33,7 @@ import { convertInsideLabel, convertOutsideLabels } from './convertLabel';
const defaultPosition: XYPosition = { x: 0, y: 0 };

const toIconLabelNode = (
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLIconLabelNodeStyle>,
gqlParentNode: GQLNode<GQLNodeStyle> | null,
Expand Down Expand Up @@ -95,6 +97,7 @@ const toIconLabelNode = (
data,
position: defaultPosition,
hidden: state === GQLViewModifier.Hidden,
selected: !!nodeLookUp.get(id)?.selected,
};

if (gqlParentNode) {
Expand Down Expand Up @@ -130,6 +133,7 @@ export class IconLabelNodeConverter implements INodeConverter {

handle(
_convertEngine: IConvertEngine,
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLIconLabelNodeStyle>,
_gqlEdges: GQLEdge[],
Expand All @@ -141,7 +145,7 @@ export class IconLabelNodeConverter implements INodeConverter {
) {
const nodeDescription = nodeDescriptions.find((description) => description.id === gqlNode.descriptionId);
if (nodeDescription) {
nodes.push(toIconLabelNode(gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode));
nodes.push(toIconLabelNode(nodeLookUp, gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node, XYPosition } from '@xyflow/react';
import { InternalNode, Node, XYPosition } from '@xyflow/react';
import { NodeLookup } from '@xyflow/system';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import { GQLDiagram, GQLNodeLayoutData } from '../graphql/subscription/diagramFragment.types';
import { GQLEdge } from '../graphql/subscription/edgeFragment.types';
import { GQLImageNodeStyle, GQLNode, GQLNodeStyle, GQLViewModifier } from '../graphql/subscription/nodeFragment.types';
import { BorderNodePosition } from '../renderer/DiagramRenderer.types';
import { BorderNodePosition, NodeData } from '../renderer/DiagramRenderer.types';
import { ConnectionHandle } from '../renderer/handles/ConnectionHandles.types';
import { defaultHeight, defaultWidth } from '../renderer/layout/layoutParams';
import { FreeFormNodeData } from '../renderer/node/FreeFormNode.types';
Expand All @@ -28,6 +29,7 @@ import { convertInsideLabel, convertOutsideLabels } from './convertLabel';
const defaultPosition: XYPosition = { x: 0, y: 0 };

const toImageNode = (
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLImageNodeStyle>,
gqlParentNode: GQLNode<GQLNodeStyle> | null,
Expand Down Expand Up @@ -101,6 +103,7 @@ const toImageNode = (
data,
position: defaultPosition,
hidden: state === GQLViewModifier.Hidden,
selected: !!nodeLookUp.get(id)?.selected,
};

if (gqlParentNode) {
Expand Down Expand Up @@ -136,6 +139,7 @@ export class ImageNodeConverter implements INodeConverter {

handle(
convertEngine: IConvertEngine,
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLImageNodeStyle>,
gqlEdges: GQLEdge[],
Expand All @@ -147,7 +151,7 @@ export class ImageNodeConverter implements INodeConverter {
) {
const nodeDescription = nodeDescriptions.find((description) => description.id === gqlNode.descriptionId);
if (nodeDescription) {
nodes.push(toImageNode(gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges));
nodes.push(toImageNode(nodeLookUp, gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges));
}

const borderNodeDescriptions: GQLNodeDescription[] = (nodeDescription?.borderNodeDescriptionIds ?? []).flatMap(
Expand All @@ -160,6 +164,7 @@ export class ImageNodeConverter implements INodeConverter {
);

convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.borderNodes ?? [],
gqlNode,
Expand All @@ -168,6 +173,7 @@ export class ImageNodeConverter implements INodeConverter {
borderNodeDescriptions
);
convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.childNodes ?? [],
gqlNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node, XYPosition } from '@xyflow/react';
import { InternalNode, Node, XYPosition } from '@xyflow/react';
import { NodeLookup } from '@xyflow/system';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import { GQLDiagram, GQLNodeLayoutData } from '../graphql/subscription/diagramFragment.types';
import { GQLEdge } from '../graphql/subscription/edgeFragment.types';
Expand All @@ -33,6 +34,7 @@ import { convertInsideLabel, convertOutsideLabels } from './convertLabel';
const defaultPosition: XYPosition = { x: 0, y: 0 };

const toListNode = (
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLRectangularNodeStyle>,
gqlParentNode: GQLNode<GQLNodeStyle> | null,
Expand Down Expand Up @@ -116,6 +118,7 @@ const toListNode = (
data,
position: defaultPosition,
hidden: state === GQLViewModifier.Hidden,
selected: !!nodeLookUp.get(id)?.selected,
};

if (gqlParentNode) {
Expand Down Expand Up @@ -177,6 +180,7 @@ export class ListNodeConverter implements INodeConverter {

handle(
convertEngine: IConvertEngine,
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLRectangularNodeStyle>,
gqlEdges: GQLEdge[],
Expand All @@ -188,7 +192,7 @@ export class ListNodeConverter implements INodeConverter {
) {
const nodeDescription = nodeDescriptions.find((description) => description.id === gqlNode.descriptionId);
if (nodeDescription) {
nodes.push(toListNode(gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges));
nodes.push(toListNode(nodeLookUp, gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges));
}

const borderNodeDescriptions: GQLNodeDescription[] = (nodeDescription?.borderNodeDescriptionIds ?? []).flatMap(
Expand All @@ -201,6 +205,7 @@ export class ListNodeConverter implements INodeConverter {
);

convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.borderNodes ?? [],
gqlNode,
Expand All @@ -209,6 +214,7 @@ export class ListNodeConverter implements INodeConverter {
borderNodeDescriptions
);
convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.childNodes ?? [],
gqlNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node, XYPosition } from '@xyflow/react';
import { InternalNode, Node, XYPosition } from '@xyflow/react';
import { NodeLookup } from '@xyflow/system';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import { GQLDiagram, GQLNodeLayoutData } from '../graphql/subscription/diagramFragment.types';
import { GQLEdge } from '../graphql/subscription/edgeFragment.types';
Expand All @@ -20,7 +21,7 @@ import {
GQLRectangularNodeStyle,
GQLViewModifier,
} from '../graphql/subscription/nodeFragment.types';
import { BorderNodePosition } from '../renderer/DiagramRenderer.types';
import { BorderNodePosition, NodeData } from '../renderer/DiagramRenderer.types';
import { ConnectionHandle } from '../renderer/handles/ConnectionHandles.types';
import { defaultHeight, defaultWidth } from '../renderer/layout/layoutParams';
import { FreeFormNodeData } from '../renderer/node/FreeFormNode.types';
Expand All @@ -33,6 +34,7 @@ import { convertInsideLabel, convertOutsideLabels } from './convertLabel';
const defaultPosition: XYPosition = { x: 0, y: 0 };

const toRectangularNode = (
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLRectangularNodeStyle>,
gqlParentNode: GQLNode<GQLNodeStyle> | null,
Expand Down Expand Up @@ -108,6 +110,7 @@ const toRectangularNode = (
data,
position: defaultPosition,
hidden: state === GQLViewModifier.Hidden,
selected: !!nodeLookUp.get(id)?.selected,
};

if (gqlParentNode) {
Expand Down Expand Up @@ -143,6 +146,7 @@ export class RectangleNodeConverter implements INodeConverter {

handle(
convertEngine: IConvertEngine,
nodeLookUp: NodeLookup<InternalNode<Node<NodeData>>>,
gqlDiagram: GQLDiagram,
gqlNode: GQLNode<GQLRectangularNodeStyle>,
gqlEdges: GQLEdge[],
Expand All @@ -154,7 +158,9 @@ export class RectangleNodeConverter implements INodeConverter {
) {
const nodeDescription = nodeDescriptions.find((description) => description.id === gqlNode.descriptionId);
if (nodeDescription) {
nodes.push(toRectangularNode(gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges));
nodes.push(
toRectangularNode(nodeLookUp, gqlDiagram, gqlNode, parentNode, nodeDescription, isBorderNode, gqlEdges)
);
}

const borderNodeDescriptions: GQLNodeDescription[] = (nodeDescription?.borderNodeDescriptionIds ?? []).flatMap(
Expand All @@ -167,6 +173,7 @@ export class RectangleNodeConverter implements INodeConverter {
);

convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.borderNodes ?? [],
gqlNode,
Expand All @@ -175,6 +182,7 @@ export class RectangleNodeConverter implements INodeConverter {
borderNodeDescriptions
);
convertEngine.convertNodes(
nodeLookUp,
gqlDiagram,
gqlNode.childNodes ?? [],
gqlNode,
Expand Down
Loading

0 comments on commit 4875861

Please sign in to comment.