Skip to content

Commit b88e9eb

Browse files
authored
Merge pull request patternfly#246 from jeff-phillips-18/v6-updates
feat(update): Cherry pick missing v5 updates into main
2 parents dab2de2 + 8759db1 commit b88e9eb

25 files changed

Lines changed: 515 additions & 302 deletions

README.md

Lines changed: 87 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,74 @@
1-
# @patternfly/react-topology
2-
3-
This package provides Topology View components based on [PatternFly 4][patternfly-4]
4-
5-
Based from https://github.com/patternfly/patternfly-react version 4.91.40
1+
# PatternFly Topology
62

7-
### Prerequisites
3+
This package provides the resources necessary to use PatternFly Topology, an open source utility that you can use to create a visual representation of all the applications within your project, their build status, and the components and services associated with them.
84

9-
#### Node Environment
5+
Topology utilizes some of PatternFly's React components https://github.com/patternfly/patternfly-react.
106

11-
This project currently supports Node [Active LTS](https://github.com/nodejs/Release#release-schedule) releases. Please stay current with Node Active LTS when developing patternfly-react.
7+
Documentation for Topology and its features is available on [the PatternFly website.](www.patternfly.org/topology/about-topology)
128

13-
For example, to develop with Node 8, use the following:
9+
## Table of contents
10+
- [Prerequisites](#prerequisites)
11+
- [Installing Topology](#installing-topology)
12+
- [Initial setup and usage](#initial-setup-and-usage)
13+
- [Example](#example)
14+
- [Demo app](#demo-app)
1415

15-
```
16-
nvm install 8
17-
nvm use 8
18-
```
16+
## Prerequisites
1917

20-
This project also requires a Yarn version of >=1.6.0. The latest version can be installed [here](https://yarnpkg.com/).
18+
To use Topology, you will need to have both [Node Active LTS](https://github.com/nodejs/Release#release-schedule) and [Yarn](https://yarnpkg.com/) installed.
2119

22-
### Installing
20+
1. Install and develop with the most up-to-date version of Node Active LTS. For example, to develop with Node 8, you would use the following commands:
2321

24-
```
25-
yarn add @patternfly/react-topology
26-
```
22+
```
23+
nvm install 8
24+
nvm use 8
25+
```
26+
1. Install and use version 1.6.0 or later of Yarn.
2727
28-
or
28+
## Installing Topology
2929
30-
```
31-
npm install @patternfly/react-topology --save
32-
```
30+
Once you have all of the prequisites, you can install the Topology package with Yarn or npm:
31+
32+
1. Using Yarn:
3333
34-
## Basic Usage
34+
```
35+
yarn add @patternfly/react-topology
36+
```
37+
1. Using npm:
3538
36-
To use React Topology out-of-the-box, you will first need to transform your back-end data into a [Model](https://github.com/patternfly/patternfly-react/blob/main/packages/react-topology/src/types.ts#L16-L20). These model objects contain the information needed to display the nodes and edges. Each node and edge has a set of properties used by PF Topology as well as a data field which can be used to customize the nodes and edges by the application.
39+
```
40+
npm install @patternfly/react-topology --save
41+
```
3742
38-
You will then need to declare a controller, which can be initialized via the `useVisualizationController()` method.
43+
## Initial setup and usage
3944
40-
The `fromModel` method must be called on the controller to create the nodes. `fromModel` will take your data model as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type` and `layout`.
45+
To use Topology out of the box, follow these steps:
4146
42-
To create your topology view component, you can use `TopologyView` to Wrap `<VisualizationSurface>` which can accept `state` as a parameter. The state is application specific. It can be any data the application wants to store/retrieve from the controller. Adding state to the surface allows hooks to update when state changes. The state is useful to keep graph state such as selected elements.
47+
1. First transform your back-end data into a [Model](https://github.com/patternfly/react-topology/blob/main/packages/module/src/types.ts) object. This will contain the information needed to display the nodes and edges in your Topology view. Each node and edge contains a set of properties used by Topology, as well as a data field, which Topology can be used to customize the nodes and edges.
4348
44-
Use a controller to wrap your topology view component. In the example below, this is done via the `VisualizationProvider` which consumes the `Controller` via context.
49+
1. Declare a controller, which can be initialized via the `useVisualizationController()` method.
4550
46-
Three `register` methods are accessed by the controller.
51+
1. Create nodes by calling the `fromModel` method on the controller you initialized. `fromModel` will take the `Model` that you created as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type`, and `layout`.
4752
48-
The following two must be declared explicitly\:
53+
1. To create your Topology view component, wrap `TopologyView` around `<VisualizationSurface>`, which can accept a `state` parameter.
54+
- The value of state is application specific and should include any data the application wants to store/retrieve from the controller.
55+
- Adding state to `<VisualizationSurface>` allows hooks to update when state changes.
56+
- State can also be used to keep track of your graph state, such as selected elements.
4957
50-
- `registerLayoutFactory`\: This method sets the layout of your topology view (e.g. Force, Dagre, Cola, etc.). You can use `defaultLayoutFactory` as a parameter if your application supports all layouts. You can also update `defaultLayout` to a custom implementation if you only want to support a subset of the available layout options.
58+
1. Wrap your `TopologyView` with your controller. In the example below, this is done via the `VisualizationProvider` which consumes the `Controller` via context.
5159
52-
- `registerComponentFactory`\: This method lets you customize the components in your topology view (e.g. nodes, groups, and edges). You can use `defaultComponentFactory` as a parameter.
60+
1. There are 3 `register` methods that the controller accesses.
5361
54-
The register method below is initialized in `Visualization.ts`, therefore it doesn't need to be declared unless you want to support a custom implementation which modifies the types.
62+
These 2 must be declared explicitly:
5563
56-
- `registerElementFactory`\: This method sets the types of the elements being used (e.g. graphs, nodes, edges). `defaultElementFactory` uses types from `ModelKind` and is exported in `index.ts`.
64+
1. **`registerLayoutFactory`:** Sets the layout of your topology view (e.g. Force, Dagre, Cola, etc.). You can use `defaultLayoutFactory` as a parameter if your application supports all layouts. You can also update `defaultLayout` to a custom implementation if you only want to support a subset of the available layout options.
65+
1. **`registerComponentFactory`:** Lets you customize the components in your topology view (e.g. nodes, groups, and edges). You can use `defaultComponentFactory` as a parameter.
66+
67+
The remaining method is initialized in `Visualization.ts`, so it doesn't need to be declared unless you want to support a custom implementation that modifies the types:
5768
58-
#### Example Component Usage
69+
3. **`registerElementFactory`:** Sets the types of the elements being used (e.g. graphs, nodes, edges). `defaultElementFactory` uses types from `ModelKind` and is exported in `index.ts`.
70+
71+
## Example
5972
6073
```ts
6174
import * as React from 'react';
@@ -185,3 +198,42 @@ export const TopologyBaselineDemo = React.memo(() => {
185198
});
186199
```
187200

201+
## Demo app
202+
203+
To help you better understand and visualize the different Topology components, we have created an interactive demo, [which is contained here.](https://github.com/patternfly/react-topology/tree/main/packages/demo-app-ts)
204+
205+
Continue reading for instructions on how to build and run the demo app.
206+
207+
### Prerequisites
208+
209+
In order to run the demo app, you need to make sure the following prerequisites are met.
210+
211+
1. Make sure that you have yarn installed, as outlined in [the general Topology prerequisites.](#prerequisites)
212+
1. If you haven’t already, [fork the Topology project.](https://github.com/patternfly/react-topology)
213+
214+
### Running the demo app
215+
216+
Once you’ve set up the prerequisites, you can follow these steps to run the docs workspace or the demo app on your local machine
217+
218+
1. In a terminal, type the following commands to start the docs workspace:
219+
220+
```
221+
yarn install
222+
yarn start
223+
```
224+
225+
2. In a terminal, type the following commands to navigate to demo-app-ts and launch the demo app:
226+
227+
```
228+
cd packages/demo-app-ts
229+
yarn start:demo-app:hot
230+
```
231+
232+
3. You will receive a message confirming that the app is running. To view the locally running workspace, visit http://localhost:8008/.
233+
234+
4. Explore the demo app in your browser:
235+
236+
![Demo app landing page.](packages/module/patternfly-docs/content/examples/img/topology-demo-app.png)
237+
238+
## Need help?
239+
If you find a bug, have a request, or have any questions about Topology that aren't answered in our documentation, please [reach out to us on Slack.](https://patternfly.slack.com/archives/CK7URGJ2W)

packages/demo-app-ts/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Topology demo app
2+
3+
To help you better understand and visualize the different Topology components, we have created an interactive demo, [which is contained here.](https://github.com/patternfly/react-topology/tree/main/packages/demo-app-ts)
4+
5+
Continue reading for instructions on how to build and run the demo app.
6+
7+
### Prerequisites
8+
9+
In order to run the demo app, you need to make sure the following prerequisites are met.
10+
11+
1. Make sure that you have yarn installed, as outlined in [the general Topology prerequisites.](#prerequisites)
12+
1. Make sure that you have the PatternFly React library installed. [Follow these instructions if you need to install this package.](https://github.com/patternfly/patternfly-react?tab=readme-ov-file#install-and-configure-patternfly-react)
13+
1. If you haven’t already, clone [the Topology project](https://github.com/patternfly/react-topology) and navigate to your local directory:
14+
15+
```
16+
git clone https://github.com/patternfly/react-topology.git
17+
cd react-topology
18+
```
19+
20+
### Running the demo app
21+
22+
Once you’ve set up the prerequisites, you can follow these steps to run the demo app on your local machine
23+
24+
1. In a terminal, type the following commands to start the docs workspace:
25+
26+
```
27+
yarn install
28+
yarn start
29+
```
30+
31+
2. In a separate terminal window, type the following commands to navigate to demo-app-ts and launch the demo app:
32+
33+
```
34+
cd packages/demo-app-ts
35+
yarn start:demo-app:hot
36+
```
37+
38+
3. You will receive a message confirming that the app is running, as well the URL that you can enter in your browser to load the app:
39+
40+
```
41+
<i> [webpack-dev-server] Project is running at:
42+
<i> [webpack-dev-server] Loopback: http://localhost:3000/
43+
```
44+
45+
4. Explore the demo app in your browser:
46+
47+
![Demo app landing page.](packages/module/patternfly-docs/content/examples/img/topology-demo-app.png)
48+
49+
## Need help?
50+
If you find a bug, have a request, or have any questions about Topology that aren't answered in our documentation, please [reach out to us on Slack.](https://patternfly.slack.com/archives/CK7URGJ2W)

packages/demo-app-ts/src/demos/pipelineGroupsDemo/DemoTaskGroup.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
RunStatus,
1616
TaskGroupPillLabel
1717
} from '@patternfly/react-topology';
18+
import { BanIcon } from '@patternfly/react-icons';
1819
import { DEFAULT_TASK_HEIGHT, GROUP_TASK_WIDTH } from './createDemoPipelineGroupsNodes';
1920

2021
type DemoTaskGroupProps = {
@@ -43,12 +44,18 @@ const DemoTaskGroup: React.FunctionComponent<DemoTaskGroupProps> = ({ element, .
4344
collapsible
4445
collapsedWidth={GROUP_TASK_WIDTH}
4546
collapsedHeight={DEFAULT_TASK_HEIGHT}
46-
GroupLabelComponent={TaskGroupPillLabel}
47+
GroupLabelComponent={(props) => (
48+
<TaskGroupPillLabel
49+
{...props}
50+
customStatusIcon={data.status === RunStatus.Cancelled ? <BanIcon /> : undefined}
51+
/>
52+
)}
4753
element={element as Node}
4854
centerLabelOnEdge
4955
recreateLayoutOnCollapseChange
5056
getEdgeCreationTypes={getEdgeCreationTypes}
5157
scaleNode={hover && detailsLevel !== ScaleDetailsLevel.high}
58+
customStatusIcon={data.status === RunStatus.Cancelled ? <BanIcon /> : undefined}
5259
showLabelOnHover
5360
hideDetailsAtMedium
5461
showStatusState

packages/demo-app-ts/src/demos/pipelineGroupsDemo/DemoTaskNode.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
DEFAULT_LAYER,
55
GraphElement,
66
Layer,
7+
RunStatus,
78
ScaleDetailsLevel,
89
TaskNode,
910
TOP_LAYER,
1011
useHover,
1112
WithContextMenuProps,
1213
WithSelectionProps
1314
} from '@patternfly/react-topology';
15+
import { BanIcon } from '@patternfly/react-icons';
1416

1517
type DemoTaskNodeProps = {
1618
element: GraphElement;
@@ -31,6 +33,7 @@ const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({ element, ...
3133
showStatusState
3234
status={data.status}
3335
hideDetailsAtMedium
36+
customStatusIcon={data.status === RunStatus.Cancelled ? <BanIcon /> : undefined}
3437
{...rest}
3538
/>
3639
</g>

packages/demo-app-ts/src/demos/pipelineGroupsDemo/createDemoPipelineGroupsNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const createExecution3 = (runAfter?: string): [string, PipelineNodeModel[
159159
},
160160
runAfterTasks: [task_3_1.id],
161161
data: {
162-
status: RunStatus.Succeeded,
162+
status: RunStatus.Cancelled,
163163
isDependency: true
164164
}
165165
};
@@ -294,7 +294,7 @@ export const createExecution3 = (runAfter?: string): [string, PipelineNodeModel[
294294
padding: [NODE_PADDING_VERTICAL, NODE_PADDING_HORIZONTAL]
295295
},
296296
data: {
297-
status: RunStatus.Succeeded,
297+
status: RunStatus.Cancelled,
298298
isDependency: true
299299
}
300300
};
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
id: About Topology
3+
section: topology
4+
sortValue: 1
5+
sourceLink: https://github.com/patternfly/react-topology/blob/main/packages/module/patternfly-docs/content/examples/TopologyGettingStartedDemo.tsx
6+
propComponents: ['VisualizationProvider', 'VisualizationSurface']
7+
---
8+
9+
import {
10+
ColaLayout,
11+
DefaultEdge,
12+
DefaultGroup,
13+
DefaultNode,
14+
EdgeStyle,
15+
GraphComponent,
16+
ModelKind,
17+
NodeShape,
18+
SELECTION_EVENT,
19+
Visualization,
20+
VisualizationProvider,
21+
VisualizationSurface
22+
} from '@patternfly/react-topology';
23+
import Icon1 from '@patternfly/react-icons/dist/esm/icons/regions-icon';
24+
import Icon2 from '@patternfly/react-icons/dist/esm/icons/folder-open-icon';
25+
26+
import './topology-example.css';
27+
28+
# Introduction
29+
30+
**Note:** Topology lives in its own package at [`@patternfly/react-topology`](https://www.npmjs.com/package/@patternfly/react-topology).
31+
32+
PatternFly's **Topology** is an open source utility built off of [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core) that you can use to create a visual representation of all the applications within your project, their build status, and the components and services associated with them. Creating these visuals can help document and communicate the intricacies of the processes behind your product.
33+
34+
To create a Topology view for your application, you can create a simple layout of nodes, which represents your data points, and connecting edges, which represent the relationships between nodes. Beyond this basis, you can continue to customize and enhance your Topology view to fit the specific needs of your application.
35+
36+
## Prerequisites
37+
38+
To use Topology, you will need to have both [Node Active LTS](https://github.com/nodejs/Release#release-schedule) and [Yarn](https://yarnpkg.com/) installed.
39+
40+
1. Install and develop with the most up-to-date version of Node Active LTS. For example, to develop with Node 8, you would use the following commands:
41+
42+
```
43+
nvm install 8
44+
nvm use 8
45+
```
46+
2. Install and use version 1.6.0 or later of Yarn.
47+
48+
## Installing Topology
49+
50+
Once you have all of the prequisites, you can install the Topology package with Yarn or npm:
51+
52+
1. Using Yarn:
53+
54+
```
55+
yarn add @patternfly/react-topology
56+
```
57+
2. Using npm:
58+
59+
```
60+
npm install @patternfly/react-topology --save
61+
```
62+
63+
## Initial setup and usage
64+
65+
To use Topology out of the box, follow these steps:
66+
67+
1. First transform your back-end data into a [Model](https://github.com/patternfly/react-topology/blob/main/packages/module/src/types.ts) object. This will contain the information needed to display the nodes and edges in your Topology view. Each node and edge contains a set of properties used by Topology, as well as a data field, which Topology can be used to customize the nodes and edges.
68+
69+
1. Declare a controller, which can be initialized via the `useVisualizationController()` method.
70+
71+
1. Create nodes by calling the `fromModel` method on the controller you initialized. `fromModel` will take the `Model` that you created as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type`, and `layout`.
72+
73+
1. To create your Topology view component, wrap `TopologyView` around `<VisualizationSurface>`, which can accept a `state` parameter.
74+
- The value of state is application specific and should include any data the application wants to store/retrieve from the controller.
75+
- Adding state to `<VisualizationSurface>` allows hooks to update when state changes.
76+
- State cam also be used to keep track of your graph state, such as selected elements.
77+
78+
1. Wrap your `TopologyView` with your controller. In the example below, this is done via the `VisualizationProvider` which consumes the `Controller` via context.
79+
80+
1. There are 3 `register` methods that the controller accesses.
81+
82+
These 2 must be declared explicitly:
83+
84+
1. **`registerLayoutFactory`:** Sets the layout of your topology view (e.g. Force, Dagre, Cola, etc.). You can use `defaultLayoutFactory` as a parameter if your application supports all layouts. You can also update `defaultLayout` to a custom implementation if you only want to support a subset of the available layout options.
85+
1. **`registerComponentFactory`:** Lets you customize the components in your topology view (e.g. nodes, groups, and edges). You can use `defaultComponentFactory` as a parameter.
86+
87+
The remaining method is initialized in `Visualization.ts`, so it doesn't need to be declared unless you want to support a custom implementation that modifies the types:
88+
89+
3. **`registerElementFactory`:** Sets the types of the elements being used (e.g. graphs, nodes, edges). `defaultElementFactory` uses types from `ModelKind` and is exported in `index.ts`.
90+
91+
1. Create nodes by calling the `fromModel` method on the controller. `fromModel` will take your data model as a parameter. Your data model should include a `graph` object, on which you will need to set `id` , `type`, and `layout`.
92+
93+
1. To create your topology view component, add a `<VisualizationProvider>`, which is a useful context provider. It allows access to the created controller and is required when using the `<VisualizationSurface>` component.
94+
95+
1. Use `<VisualizationSurface>` to provide the SVG component required for your topology components. `<VisualizationSurface>` can take a state parameter, which enables you to pass your state settings to the controller.
96+
97+
## Demo app
98+
99+
To help you better understand and visualize the different Topology components, we have created an interactive demo, [which is contained in the react-topology repository.](https://github.com/patternfly/react-topology/tree/main/packages/demo-app-ts)
100+
101+
You can run the demo app [by following these instructions.](https://github.com/patternfly/react-topology?tab=readme-ov-file#demo-app)
102+
103+
### Example
104+
105+
```ts file='./TopologyGettingStartedDemo.tsx'
106+
```

0 commit comments

Comments
 (0)