Skip to content

Commit aad57e0

Browse files
chore(demo app): Fix build of demo app and center graph initially (#284)
1 parent ad2c209 commit aad57e0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/demo-app-ts/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createElement } from 'react';
1+
import { createElement, Component } from 'react';
22
import { BrowserRouter as Router, Route, Link, Switch } from 'react-router-dom';
33
import {
44
Page,
@@ -35,7 +35,7 @@ interface AppState {
3535
isDarkTheme: boolean;
3636
}
3737

38-
class App extends React.Component<{}, AppState> {
38+
class App extends Component<{}, AppState> {
3939
state: AppState = {
4040
activeItem: Demos.reduce(
4141
(active, demo) => active || (demo.isDefault ? demo.id : demo.demos?.find((subDemo) => subDemo.isDefault)?.id),

packages/demo-app-ts/src/demos/topologyPackageDemo/TopologyPackage.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useContext } from 'react';
1+
import { useState, useEffect, useContext, FunctionComponent, MouseEvent as ReactMouseEvent } from 'react';
22
import { Tab, Tabs, TabTitleText } from '@patternfly/react-core';
33
import {
44
GRAPH_POSITION_CHANGE_EVENT,
@@ -34,12 +34,13 @@ interface TopologyViewComponentProps {
3434
sideBarResizable?: boolean;
3535
}
3636

37-
const TopologyViewComponent: React.FunctionComponent<TopologyViewComponentProps> = observer(
37+
const TopologyViewComponent: FunctionComponent<TopologyViewComponentProps> = observer(
3838
({ useSidebar, sideBarResizable = false }) => {
3939
const [selectedIds, setSelectedIds] = useState<string[]>([]);
4040
const [showAreaDragHint, setShowAreaDragHint] = useState<boolean>(false);
4141
const controller = useVisualizationController();
4242
const options = useContext(DemoContext);
43+
const hasGraph = controller.hasGraph();
4344

4445
useEffect(() => {
4546
const dataModel = generateDataModel(
@@ -61,6 +62,14 @@ const TopologyViewComponent: React.FunctionComponent<TopologyViewComponentProps>
6162
controller.fromModel(model, true);
6263
}, [controller, options.creationCounts, options.layout]);
6364

65+
// Once we have the graph, run the layout. This ensures the graph size is set (by the initial size observation in VisualizationSurface)
66+
// and the graph is centered by the layout.
67+
useEffect(() => {
68+
if (hasGraph) {
69+
controller.getGraph().layout();
70+
}
71+
}, [hasGraph, controller]);
72+
6473
useEventListener<SelectionEventListener>(SELECTION_EVENT, (ids) => {
6574
setSelectedIds(ids);
6675
});
@@ -149,7 +158,7 @@ const TopologyViewComponent: React.FunctionComponent<TopologyViewComponentProps>
149158
}
150159
);
151160

152-
export const Topology: React.FC<{ useSidebar?: boolean; sideBarResizable?: boolean }> = ({
161+
export const Topology: FunctionComponent<{ useSidebar?: boolean; sideBarResizable?: boolean }> = ({
153162
useSidebar = false,
154163
sideBarResizable = false
155164
}) => {
@@ -165,10 +174,10 @@ export const Topology: React.FC<{ useSidebar?: boolean; sideBarResizable?: boole
165174
);
166175
};
167176

168-
export const TopologyPackage: React.FunctionComponent = () => {
177+
export const TopologyPackage: FunctionComponent = () => {
169178
const [activeKey, setActiveKey] = useState<string | number>(0);
170179

171-
const handleTabClick = (_event: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => {
180+
const handleTabClick = (_event: ReactMouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => {
172181
setActiveKey(tabIndex);
173182
};
174183

packages/demo-app-ts/src/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { createRoot } from 'react-dom/client';
22
import '@patternfly/react-core/dist/styles/base.css';
3-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4-
import React from 'react';
53
import './index.css';
64
import App from './App';
75

0 commit comments

Comments
 (0)