Skip to content
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
9 changes: 2 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/jsx-runtime",
"prettier"
],
"overrides": [
Expand All @@ -31,13 +32,7 @@
"version": "detect"
}
},
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"patternfly-react",
"prettier"
],
"plugins": ["react", "react-hooks", "@typescript-eslint", "patternfly-react", "prettier"],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ To use Topology out of the box, follow these steps:
## Example

```ts
import * as React from 'react';
import { memo, useState, useMemo } from 'react';
import {
EdgeStyle,
Model,
Expand Down Expand Up @@ -172,10 +172,10 @@ const EDGES = [
}
];

export const TopologyBaselineDemo = React.memo(() => {
const [selectedIds, setSelectedIds] = React.useState<string[]>([]);
export const TopologyBaselineDemo = memo(() => {
const [selectedIds, setSelectedIds] = useState<string[]>([]);

const controller = React.useMemo(() => {
const controller = useMemo(() => {
const model: Model = {
nodes: NODES,
edges: EDGES,
Expand Down
8 changes: 4 additions & 4 deletions packages/demo-app-ts/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
const root = createRoot(div);
root.render(<App />);
root.unmount();
});
8 changes: 4 additions & 4 deletions packages/demo-app-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import { createElement } from 'react';
import { BrowserRouter as Router, Route, Link, Switch } from 'react-router-dom';
import {
Page,
Expand Down Expand Up @@ -81,7 +81,7 @@ class App extends React.Component<{}, AppState> {
style={{ zIndex: 2 }}
id={`/${demo.id}-nav-link/${subDemo.id}-nav-link`}
>
{React.createElement(subDemo.componentType)}
{createElement(subDemo.componentType)}
</PageSection>
)}
key={demo.id}
Expand All @@ -94,7 +94,7 @@ class App extends React.Component<{}, AppState> {
path={`/${demo.id}-nav-link`}
render={() => (
<PageSection isFilled hasBodyWrapper={false} style={{ zIndex: 2 }} id={`/${demo.id}-page-section`}>
{React.createElement(demo.componentType)}
{createElement(demo.componentType)}
</PageSection>
)}
key={demo.id}
Expand All @@ -108,7 +108,7 @@ class App extends React.Component<{}, AppState> {
path="/"
render={() => (
<PageSection isFilled hasBodyWrapper={false} style={{ zIndex: 2 }} id={`/${defaultDemo.id}-page-section`}>
{React.createElement(defaultDemo.componentType)}
{createElement(defaultDemo.componentType)}
</PageSection>
)}
key={defaultDemo.id}
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/CustomCircleNode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useEffect } from 'react';
import { observer } from 'mobx-react';
import {
WithCreateConnectorProps,
Expand Down Expand Up @@ -28,7 +28,7 @@ type CustomCircleNodeProps = {

const CustomCircle: React.FunctionComponent<ShapeProps> = ({ element, className }) => {
useAnchor(EllipseAnchor);
React.useEffect(() => {
useEffect(() => {
// init height
element.setDimensions(new Dimensions(40, 40));
}, [element]);
Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/CustomPathNode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import {
WithCreateConnectorProps,
Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/CustomPolygonNode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import {
WithCreateConnectorProps,
Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/CustomRectNode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import {
WithCreateConnectorProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/DemoDefaultEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useState } from 'react';
import { observer } from 'mobx-react';
import {
Edge,
Expand All @@ -25,7 +25,7 @@ interface BendpointProps {
}

const Bendpoint: React.FunctionComponent<BendpointProps> = observer(({ point }) => {
const [hover, setHover] = React.useState(false);
const [hover, setHover] = useState(false);
const [, ref] = useBendpoint(point);
return (
<circle
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/DemoDefaultGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useRef } from 'react';
import { observer } from 'mobx-react';
import {
useCombineRefs,
Expand Down Expand Up @@ -39,7 +39,7 @@ const DemoDefaultGroup: React.FunctionComponent<GroupProps> = ({
}) => {
const nodeElement = element as Node;
useAnchor(RectAnchor);
const boxRef = React.useRef<Rect | null>(null);
const boxRef = useRef<Rect | null>(null);
const refs = useCombineRefs<SVGRectElement>(dragNodeRef, dndDragRef, dndDropRef);

if (!droppable || !boxRef.current) {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/DemoDefaultNode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useEffect } from 'react';
import classNames from 'classnames';
import { observer } from 'mobx-react';
import {
Expand Down Expand Up @@ -52,7 +52,7 @@ const DemoDefaultNode: React.FunctionComponent<DemoDefaultNodeProps> = ({
});
const ShapeComponent = (getCustomShape && getCustomShape(nodeElement)) || getShapeComponent(nodeElement);

React.useEffect(() => {
useEffect(() => {
if (hover) {
onShowCreateConnector && onShowCreateConnector();
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/GroupHull.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useRef } from 'react';
import { observer } from 'mobx-react';
import { polygonHull } from 'd3-polygon';
import {
Expand Down Expand Up @@ -45,7 +45,7 @@ const GroupHull: React.FunctionComponent<GroupHullProps> = ({
canDrop
}) => {
const nodeElement = element as Node;
const pathRef = React.useRef<string | null>(null);
const pathRef = useRef<string | null>(null);
const refs = useCombineRefs<SVGPathElement | SVGRectElement>(dragNodeRef, dndDragRef, dndDropRef);
useAnchor(RectAnchor);

Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/MultiEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { Edge, vecSum, vecScale, unitNormal, GraphElement } from '@patternfly/react-topology';

Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/NodeRect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import {
Node,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import {
GraphElement,
ComponentFactory,
Expand Down
1 change: 0 additions & 1 deletion packages/demo-app-ts/src/components/shapes/Path.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ShapeProps, useCombineRefs, useSvgAnchor } from '@patternfly/react-topology';
import * as React from 'react';

const Path: React.FunctionComponent<ShapeProps> = ({ className, width, height, filter, dndDropRef }) => {
const anchorRef = useSvgAnchor();
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-app-ts/src/components/shapes/Polygon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PointTuple, ShapeProps, usePolygonAnchor } from '@patternfly/react-topology';
import * as React from 'react';
import { useMemo } from 'react';

const Polygon: React.FunctionComponent<ShapeProps> = ({ className, width, height, filter, dndDropRef }) => {
const points: PointTuple[] = React.useMemo(
const points: PointTuple[] = useMemo(
() => [
[width / 2, 0],
[width - width / 8, height],
Expand Down
18 changes: 9 additions & 9 deletions packages/demo-app-ts/src/demos/Basics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useMemo, useCallback, useState } from 'react';
import {
DefaultNode,
Model,
Expand All @@ -17,7 +17,7 @@ import { Tab, Tabs, TabTitleText } from '@patternfly/react-core';
export const SingleNode = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand All @@ -43,7 +43,7 @@ export const SingleNode = withTopologySetup(() => {
export const SingleEdge = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -89,15 +89,15 @@ export const SingleEdge = withTopologySetup(() => {
export const MultiEdge = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useComponentFactory(
React.useCallback<ComponentFactory>((kind) => {
useCallback<ComponentFactory>((kind) => {
if (kind === ModelKind.node) {
return withDragNode()(DefaultNode);
}
return undefined;
}, [])
);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -193,7 +193,7 @@ const groupStory =
() => {
useComponentFactory(defaultComponentFactory);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -247,7 +247,7 @@ export const GroupHull = withTopologySetup(groupStory('group-hull'));
export const AutoSizeNode = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useComponentFactory(
React.useCallback<ComponentFactory>((kind, type) => {
useCallback<ComponentFactory>((kind, type) => {
if (type === 'autoSize-circle') {
return CustomCircleNode;
}
Expand All @@ -258,7 +258,7 @@ export const AutoSizeNode = withTopologySetup(() => {
}, [])
);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -317,7 +317,7 @@ export const AutoSizeNode = withTopologySetup(() => {
});

export const Basics: React.FunctionComponent = () => {
const [activeKey, setActiveKey] = React.useState<string | number>(0);
const [activeKey, setActiveKey] = useState<string | number>(0);

const handleTabClick = (_event: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => {
setActiveKey(tabIndex);
Expand Down
16 changes: 8 additions & 8 deletions packages/demo-app-ts/src/demos/CollapsibleGroups.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useState, useEffect } from 'react';
import { action } from 'mobx';
import {
TopologyView,
Expand Down Expand Up @@ -117,12 +117,12 @@ interface TopologyViewComponentProps {
}

const TopologyViewComponent: React.FunctionComponent<TopologyViewComponentProps> = ({ vis }) => {
const [selectedIds, setSelectedIds] = React.useState<string[]>();
const [collapseBlue, setCollapseBlue] = React.useState<boolean>(false);
const [collapseLightBlue, setCollapseLightBlue] = React.useState<boolean>(false);
const [collapseCyan, setCollapseCyan] = React.useState<boolean>(false);
const [collapseOrange, setCollapseOrange] = React.useState<boolean>(false);
const [collapsePink, setCollapsePink] = React.useState<boolean>(false);
const [selectedIds, setSelectedIds] = useState<string[]>();
const [collapseBlue, setCollapseBlue] = useState<boolean>(false);
const [collapseLightBlue, setCollapseLightBlue] = useState<boolean>(false);
const [collapseCyan, setCollapseCyan] = useState<boolean>(false);
const [collapseOrange, setCollapseOrange] = useState<boolean>(false);
const [collapsePink, setCollapsePink] = useState<boolean>(false);

useEventListener<SelectionEventListener>(SELECTION_EVENT, (ids) => {
setSelectedIds(ids);
Expand Down Expand Up @@ -183,7 +183,7 @@ const TopologyViewComponent: React.FunctionComponent<TopologyViewComponentProps>
</>
);

React.useEffect(() => {
useEffect(() => {
action(() => {
const collapsedTypes: string[] = [];
if (collapseBlue) {
Expand Down
16 changes: 8 additions & 8 deletions packages/demo-app-ts/src/demos/Connectors.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { useCallback, useMemo, useState } from 'react';
import {
Model,
ModelKind,
Expand Down Expand Up @@ -38,7 +38,7 @@ import { Tab, Tabs, TabTitleText } from '@patternfly/react-core';
export const Reconnect = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useComponentFactory(
React.useCallback<ComponentFactory>((kind) => {
useCallback<ComponentFactory>((kind) => {
if (kind === ModelKind.graph) {
return withPanZoom()(GraphComponent);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ export const Reconnect = withTopologySetup(() => {
}, [])
);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -158,7 +158,7 @@ type ColorChoice = ConnectorChoice & {
};

export const CreateConnector = withTopologySetup(() => {
const model = React.useMemo(
const model = useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -196,7 +196,7 @@ export const CreateConnector = withTopologySetup(() => {
const controller = useVisualizationController();
useComponentFactory(defaultComponentFactory);
useComponentFactory(
React.useCallback<ComponentFactory>(
useCallback<ComponentFactory>(
(kind) => {
if (kind === ModelKind.graph) {
return withDndDrop({
Expand Down Expand Up @@ -295,15 +295,15 @@ const NodeWithPointAnchor: React.FunctionComponent<{ element: GraphElement } & W
export const Anchors = withTopologySetup(() => {
useComponentFactory(defaultComponentFactory);
useComponentFactory(
React.useCallback<ComponentFactory>((kind) => {
useCallback<ComponentFactory>((kind) => {
if (kind === ModelKind.node) {
return withDragNode()(NodeWithPointAnchor);
}
return undefined;
}, [])
);
useModel(
React.useMemo(
useMemo(
(): Model => ({
graph: {
id: 'g1',
Expand Down Expand Up @@ -357,7 +357,7 @@ export const Anchors = withTopologySetup(() => {
});

export const Connectors: React.FunctionComponent = () => {
const [activeKey, setActiveKey] = React.useState<string | number>(0);
const [activeKey, setActiveKey] = useState<string | number>(0);

const handleTabClick = (_event: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => {
setActiveKey(tabIndex);
Expand Down
Loading