Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: Replace reactflow with @xyflow/react and Update Dependencies #8940

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/nodemailer": "^6.4.14",
"@types/passport-microsoft": "^1.0.3",
"@wyw-in-js/vite": "^0.5.3",
"@xyflow/react": "^12.3.5",
"add": "^2.0.6",
"addressparser": "^1.0.1",
"afterframe": "^1.0.2",
Expand Down Expand Up @@ -168,7 +169,6 @@
"react-router-dom": "^6.4.4",
"react-textarea-autosize": "^8.4.1",
"react-tooltip": "^5.13.1",
"reactflow": "^11.11.3",
"recoil": "^0.7.7",
"rehype-slug": "^6.0.0",
"remark-behead": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { SettingsDataModelOverviewObject } from '@/settings/data-model/graph-ove
import { SettingsDataModelOverviewRelationMarkers } from '@/settings/data-model/graph-overview/components/SettingsDataModelOverviewRelationMarkers';
import { calculateHandlePosition } from '@/settings/data-model/graph-overview/utils/calculateHandlePosition';
import styled from '@emotion/styled';
import { useCallback, useState } from 'react';
import ReactFlow, {
import {
Background,
EdgeChange,
NodeChange,
Edge,
Node,
NodeTypes,
OnEdgesChange,
OnNodesChange,
ReactFlow,
applyEdgeChanges,
applyNodeChanges,
getIncomers,
getOutgoers,
useEdgesState,
useNodesState,
useReactFlow,
} from 'reactflow';
} from '@xyflow/react';
import { useCallback, useState } from 'react';
import {
Button,
IconButtonGroup,
Expand All @@ -28,7 +32,7 @@ import {
} from 'twenty-ui';
import { isDefined } from '~/utils/isDefined';

const NodeTypes = {
const nodeTypes: NodeTypes = {
object: SettingsDataModelOverviewObject,
};
const StyledContainer = styled.div`
Expand Down Expand Up @@ -67,25 +71,25 @@ const StyledCloseButton = styled.div`
export const SettingsDataModelOverview = () => {
const { fitView, zoomIn, zoomOut } = useReactFlow();

const [nodes, setNodes] = useNodesState([]);
const [edges, setEdges] = useEdgesState([]);
const [nodes, setNodes] = useNodesState<Node>([]);
const [edges, setEdges] = useEdgesState<Edge>([]);
const [isInteractive, setInteractive] = useState(true);

const onNodesChange = useCallback(
(changes: NodeChange[]) =>
setNodes((nds) => applyNodeChanges(changes, nds)),
const onNodesChange: OnNodesChange = useCallback(
(changes) => setNodes((nds) => applyNodeChanges(changes, nds)),
[setNodes],
);
const onEdgesChange = useCallback(
(changes: EdgeChange[]) =>
setEdges((eds) => applyEdgeChanges(changes, eds)),
const onEdgesChange: OnEdgesChange = useCallback(
(changes) => setEdges((eds) => applyEdgeChanges(changes, eds)),
[setEdges],
);

const handleNodesChange = useCallback(
(nodeChanges: any[]) => {
const handleNodesChange: OnNodesChange = useCallback(
(nodeChanges) => {
nodeChanges.forEach((nodeChange) => {
const node = nodes.find((node) => node.id === nodeChange.id);
const node = nodes.find(
(node) => node.id === (nodeChange as { id: string }).id,
);
if (!node) {
return;
}
Expand Down Expand Up @@ -119,8 +123,8 @@ export const SettingsDataModelOverview = () => {
newXPos,
'target',
);
const sourceHandle = `${edge.data.sourceField}-${sourcePosition}`;
const targetHandle = `${edge.data.targetField}-${targetPosition}`;
const sourceHandle = `${edge.data?.sourceField}-${sourcePosition}`;
const targetHandle = `${edge.data?.targetField}-${targetPosition}`;
ed.sourceHandle = sourceHandle;
ed.targetHandle = targetHandle;
ed.markerEnd = 'marker';
Expand Down Expand Up @@ -157,8 +161,8 @@ export const SettingsDataModelOverview = () => {
'target',
);

const sourceHandle = `${edge.data.sourceField}-${sourcePosition}`;
const targetHandle = `${edge.data.targetField}-${targetPosition}`;
const sourceHandle = `${edge.data?.sourceField}-${sourcePosition}`;
const targetHandle = `${edge.data?.targetField}-${targetPosition}`;

ed.sourceHandle = sourceHandle;
ed.targetHandle = targetHandle;
Expand Down Expand Up @@ -193,7 +197,7 @@ export const SettingsDataModelOverview = () => {
nodes={nodes}
edges={edges}
onEdgesChange={onEdgesChange}
nodeTypes={NodeTypes}
nodeTypes={nodeTypes}
onNodesChange={handleNodesChange}
nodesDraggable={isInteractive}
elementsSelectable={isInteractive}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dagre from '@dagrejs/dagre';
import { useTheme } from '@emotion/react';
import { Edge, Node } from '@xyflow/react';
import { useEffect } from 'react';
import { Edge, Node } from 'reactflow';
import { useRecoilValue } from 'recoil';

import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Handle, Position } from 'reactflow';
import { Handle, Position } from '@xyflow/react';
import { useRecoilValue } from 'recoil';
import { useIcons } from 'twenty-ui';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Node, NodeProps } from '@xyflow/react';
import { Link } from 'react-router-dom';
import { NodeProps } from 'reactflow';
import { IconChevronDown, IconChevronUp, useIcons } from 'twenty-ui';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
Expand All @@ -14,10 +14,12 @@ import { FieldMetadataType } from '~/generated/graphql';
import { capitalize } from '~/utils/string/capitalize';

import { ObjectFieldRowWithoutRelation } from '@/settings/data-model/graph-overview/components/SettingsDataModelOverviewFieldWithoutRelation';
import '@reactflow/node-resizer/dist/style.css';
import '@xyflow/react/dist/style.css';
import { useState } from 'react';

type SettingsDataModelOverviewObjectProps = NodeProps<ObjectMetadataItem>;
type SettingsDataModelOverviewObjectNode = Node<ObjectMetadataItem, 'object'>;
type SettingsDataModelOverviewObjectProps =
NodeProps<SettingsDataModelOverviewObjectNode>;

const StyledNode = styled.div`
background-color: ${({ theme }) => theme.background.secondary};
Expand Down Expand Up @@ -135,7 +137,7 @@ export const SettingsDataModelOverviewObject = ({
{fields
.filter((x) => x.type === FieldMetadataType.Relation)
.map((field) => (
<StyledCardRow>
<StyledCardRow key={field.id}>
<ObjectFieldRow field={field} />
</StyledCardRow>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactFlowProvider } from 'reactflow';
import { ReactFlowProvider } from '@xyflow/react';

import { SettingsDataModelOverview } from '@/settings/data-model/graph-overview/components/SettingsDataModelOverview';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const IconButtonGroup = ({

return (
<IconButton
key={index}
accent={accent}
Icon={Icon}
onClick={onClick}
Expand Down
Loading
Loading