Skip to content

Commit 494baf8

Browse files
authored
DISPATCH-2352: deps(console): update dependencies and refactor the code (#1643)
* DISPATCH-2352: deps(console): update to react 18 * DISPATCH-2352: deps(console): update react router * DISPATCH-2352: deps(console): update various other dependencies
1 parent 3c36267 commit 494baf8

File tree

8 files changed

+23673
-26144
lines changed

8 files changed

+23673
-26144
lines changed

console/react/babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

console/react/package-lock.json

Lines changed: 23574 additions & 26063 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/react/package.json

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
"version": "1.19.0",
44
"private": true,
55
"dependencies": {
6-
"@patternfly/patternfly": "^4.183.1",
7-
"@patternfly/react-charts": "^6.51.19",
8-
"@patternfly/react-core": "^4.198.19",
9-
"@patternfly/react-icons": "^4.49.19",
10-
"@patternfly/react-styles": "^4.48.19",
11-
"@patternfly/react-table": "^4.67.19",
12-
"@patternfly/react-topology": "^4.45.19",
6+
"@patternfly/patternfly": "^4.224.2",
7+
"@patternfly/react-charts": "^6.94.19",
8+
"@patternfly/react-core": "^4.276.8",
9+
"@patternfly/react-icons": "^4.93.6",
10+
"@patternfly/react-styles": "^4.92.6",
11+
"@patternfly/react-table": "^4.113.0",
12+
"@patternfly/react-topology": "^4.93.5",
1313
"d3": "^3.5.17",
1414
"d3-queue": "^3.0.7",
15-
"express": "^4.17.3",
1615
"font-awesome": "^4.7.0",
1716
"prop-types": "^15.8.1",
18-
"react": "^17.0.2",
19-
"react-dom": "^17.0.2",
17+
"react": "^18.2.0",
18+
"react-dom": "^18.2.0",
2019
"react-fontawesome": "^1.7.1",
21-
"react-router-dom": "^6.2.2",
22-
"rhea": "^3.0.0",
20+
"react-router-dom": "^6.14.1",
21+
"rhea": "^3.0.2",
2322
"topojson-client": "^3.1.0"
2423
},
2524
"scripts": {
@@ -58,15 +57,24 @@
5857
]
5958
},
6059
"devDependencies": {
60+
"@babel/preset-env": "^7.22.9",
6161
"@react-mock/localstorage": "^0.1.2",
62-
"@testing-library/jest-dom": "^5.16.2",
63-
"@testing-library/react": "^12.1.4",
64-
"@types/jest": "^27.4.1",
65-
"body-parser": "^1.19.2",
66-
"browserslist": "^4.20.0",
67-
"jest-axe": "^6.0.0",
68-
"prettier": "^2.5.1",
69-
"react-scripts": "^4.0.3",
70-
"typescript": "^4.6.2"
62+
"@testing-library/jest-dom": "^5.16.5",
63+
"@testing-library/react": "^14.0.0",
64+
"@types/jest": "^29.5.3",
65+
"body-parser": "^1.20.2",
66+
"identity-obj-proxy": "^3.0.0",
67+
"jest": "^29.6.1",
68+
"jest-axe": "^8.0.0",
69+
"prettier": "^3.0.0",
70+
"react-scripts": "^5.0.1"
71+
},
72+
"jest": {
73+
"moduleNameMapper": {
74+
"\\.(css)$": "identity-obj-proxy"
75+
},
76+
"transformIgnorePatterns": [
77+
"node_modules/(?!@patternfly/.*)"
78+
]
7179
}
7280
}

console/react/src/App.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ under the License.
1818
*/
1919

2020
import React from "react";
21-
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
22-
import { createHashHistory } from "history";
21+
import { HashRouter } from "react-router-dom";
2322

2423
import "@patternfly/patternfly/patternfly.css";
2524
import "@patternfly/patternfly/patternfly-addons.css";
@@ -31,19 +30,17 @@ import "./App.css";
3130
import PageLayout from "./overview/dashboard/layout";
3231

3332
function App(props) {
34-
3533
// service is passed in to make testing easier
3634
const service = new QDRService();
3735

3836
// also, a router is used here to provide PageLayout with a history property
39-
const history = createHashHistory({ window });
4037

4138
return (
42-
<HistoryRouter history={history}>
39+
<HashRouter>
4340
<div className="App pf-m-redhat-font">
44-
<PageLayout service={service} {...props} history={history} config={props.config}/>
41+
<PageLayout service={service} {...props} config={props.config} />
4542
</div>
46-
</HistoryRouter>
43+
</HashRouter>
4744
);
4845
}
4946

console/react/src/common/amqp/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ under the License.
1818
*/
1919

2020
import Correlator from "./correlator";
21-
import rhea from "rhea";
21+
import rhea from "rhea/dist/rhea-umd";
2222

2323
class ConnectionManager {
2424
constructor(protocol) {

console/react/src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ under the License.
1818
*/
1919

2020
import React from "react";
21-
import ReactDOM from "react-dom";
21+
import { createRoot } from "react-dom/client";
2222
import App from "./App";
2323

2424
let config = { title: "Apache Qpid Dispatch Console" };
@@ -30,6 +30,8 @@ fetch("/config.json")
3030
.catch(error => {
3131
console.log("/config.json not found. Using default console title");
3232
})
33-
.finally(() =>
34-
ReactDOM.render(<App config={config} />, document.getElementById("root"))
35-
);
33+
.finally(() => {
34+
const rootElement = document.getElementById("root");
35+
const root = createRoot(rootElement);
36+
root.render(<App config={config} />);
37+
});

console/react/src/overview/dashboard/alertList.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ under the License.
1818
*/
1919

2020
import React from "react";
21-
import { render } from "@testing-library/react";
21+
import { render, waitFor } from "@testing-library/react";
2222
import AlertList from "./alertList";
2323

2424
it("renders the AlertList component", async () => {
@@ -33,12 +33,14 @@ it("renders the AlertList component", async () => {
3333
expect(queryByLabelText("alert-close-button")).toBeNull();
3434

3535
// add an alert
36-
ref.addAlert("info", "testing");
36+
await waitFor(() => {
37+
ref.addAlert("info", "testing");
38+
});
3739
// the alert close button should now be there
3840
expect(getByLabelText("alert-close-button")).toBeInTheDocument();
3941

4042
const alert = {
41-
key: 0
43+
key: 0,
4244
};
4345
// hide the alert
4446
ref.hideAlert(alert);

console/react/src/overview/dashboard/layout.js

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
NavExpandable,
3434
NavItem,
3535
NavList,
36-
PageSidebar
36+
PageSidebar,
3737
} from "@patternfly/react-core";
3838

3939
import { Routes, Route, Link, Navigate } from "react-router-dom";
@@ -73,7 +73,9 @@ function withRouter(Component) {
7373
<Component
7474
{...props}
7575
router={{ location, navigate, params }} // intended usage
76-
location={location} navigate={navigate} params={params} // what the code currently expects
76+
location={location}
77+
navigate={navigate}
78+
params={params} // what the code currently expects
7779
/>
7880
);
7981
}
@@ -95,7 +97,7 @@ class PageLayout extends React.PureComponent {
9597
isMobileView: false,
9698
user: "anonymous",
9799
timePeriod: 60,
98-
suppress: JSON.parse(localStorage.getItem(SUPPRESS_NOTIFICATIONS)) || false
100+
suppress: JSON.parse(localStorage.getItem(SUPPRESS_NOTIFICATIONS)) || false,
99101
};
100102
this.isDropdownOpen = false;
101103

@@ -108,10 +110,10 @@ class PageLayout extends React.PureComponent {
108110
{ name: "addresses", pre: true },
109111
{ name: "links", pre: true },
110112
{ name: "connections", pre: true },
111-
{ name: "logs", pre: true }
113+
{ name: "logs", pre: true },
112114
],
113115
visualizations: [{ name: "topology" }, { name: "flow", title: "Message flow" }],
114-
details: [{ name: "entities" }, { name: "schema" }]
116+
details: [{ name: "entities" }, { name: "schema" }],
115117
};
116118
this.state.connecting = true;
117119
this.tryInitialConnect();
@@ -138,9 +140,7 @@ class PageLayout extends React.PureComponent {
138140
};
139141

140142
handleIdleTimeout = () => {
141-
this.props.history.replace(
142-
`${this.props.location.pathname}${this.props.location.search}`
143-
);
143+
this.props.navigate(`${this.props.location.pathname}${this.props.location.search}`);
144144
};
145145

146146
tryInitialConnect = () => {
@@ -149,15 +149,15 @@ class PageLayout extends React.PureComponent {
149149
address: window.location.hostname,
150150
port: window.location.port === "" ? defaultPort : window.location.port,
151151
timeout: 2000,
152-
reconnect: true
152+
reconnect: true,
153153
};
154154
this.service.connect(connectOptions).then(
155155
() => {
156156
this.handleConnect("/dashboard");
157157
},
158158
() => {
159159
//this.service.disconnect();
160-
this.props.history.replace("/");
160+
this.props.navigate("/");
161161
this.setState({ connecting: false });
162162
}
163163
);
@@ -187,10 +187,10 @@ class PageLayout extends React.PureComponent {
187187
if (this.lastLocation) {
188188
to = this.lastLocation;
189189
}
190-
this.props.history.push(to);
190+
this.props.navigate(to);
191191
this.setState({
192192
isConnectFormOpen: false,
193-
connected: true
193+
connected: true,
194194
});
195195
}
196196
};
@@ -265,7 +265,7 @@ class PageLayout extends React.PureComponent {
265265
activeItem,
266266
activeGroup,
267267
connected: true,
268-
isConnectFormOpen: false
268+
isConnectFormOpen: false,
269269
});
270270
this.props.navigate(connectPath);
271271
}
@@ -276,7 +276,7 @@ class PageLayout extends React.PureComponent {
276276
onNavSelect = result => {
277277
this.setState({
278278
activeItem: result.itemId,
279-
activeGroup: result.groupId
279+
activeGroup: result.groupId,
280280
});
281281
};
282282

@@ -290,19 +290,19 @@ class PageLayout extends React.PureComponent {
290290

291291
onNavToggleDesktop = () => {
292292
this.setState({
293-
isNavOpenDesktop: !this.state.isNavOpenDesktop
293+
isNavOpenDesktop: !this.state.isNavOpenDesktop,
294294
});
295295
};
296296

297297
onNavToggleMobile = () => {
298298
this.setState({
299-
isNavOpenMobile: !this.state.isNavOpenMobile
299+
isNavOpenMobile: !this.state.isNavOpenMobile,
300300
});
301301
};
302302

303303
onPageResize = ({ mobileView, windowSize }) => {
304304
this.setState({
305-
isMobileView: mobileView
305+
isMobileView: mobileView,
306306
});
307307
};
308308

@@ -322,7 +322,7 @@ class PageLayout extends React.PureComponent {
322322
message,
323323
timestamp,
324324
severity,
325-
silent
325+
silent,
326326
});
327327
}
328328
};
@@ -447,20 +447,24 @@ class PageLayout extends React.PureComponent {
447447

448448
// don't allow access to this component unless we are logged in
449449
// https://gist.github.com/mjackson/d54b40a094277b7afdd6b81f51a0393f
450-
const RequireLogin = ( props ) => {
451-
const { component: Component, ...more } = props
452-
453-
return this.state.connected ? <Component
454-
service={this.service}
455-
handleAddNotification={this.handleAddNotification}
456-
{...this.props}
457-
{...more}
458-
location={this.props.history.location}
459-
/> : <Navigate
460-
to={`/login${this.state.connecting ? "/connecting" : ""}`}
461-
state={{ from: this.props.history.location }}
462-
/>;
463-
}
450+
const RequireLogin = props => {
451+
const { component: Component, ...more } = props;
452+
453+
return this.state.connected ? (
454+
<Component
455+
service={this.service}
456+
handleAddNotification={this.handleAddNotification}
457+
{...this.props}
458+
{...more}
459+
location={this.props.location}
460+
/>
461+
) : (
462+
<Navigate
463+
to={`/login${this.state.connecting ? "/connecting" : ""}`}
464+
state={{ from: this.props.location }}
465+
/>
466+
);
467+
};
464468

465469
const connectForm = () => {
466470
return this.state.isConnectFormOpen ? (
@@ -501,7 +505,8 @@ class PageLayout extends React.PureComponent {
501505
{connectForm()}
502506
<Routes>
503507
<Route
504-
exact path={"/"}
508+
exact
509+
path={"/"}
505510
element={
506511
<RequireLogin
507512
throughputChartData={this.throughputChartData}
@@ -520,21 +525,22 @@ class PageLayout extends React.PureComponent {
520525
/>
521526
}
522527
/>
523-
<Route path="/overview/:entity" element={<RequireLogin component={OverviewPage}/>}/>
528+
<Route
529+
path="/overview/:entity"
530+
element={<RequireLogin component={OverviewPage} />}
531+
/>
524532
<Route
525533
path="/details"
526-
element={
527-
<RequireLogin
528-
schema={this.schema}
529-
component={DetailsTablePage}
530-
/>
531-
}
534+
element={<RequireLogin schema={this.schema} component={DetailsTablePage} />}
535+
/>
536+
<Route path="/topology" element={<RequireLogin component={TopologyPage} />} />
537+
<Route path="/flow" element={<RequireLogin component={MessageFlowPage} />} />
538+
<Route path="/logs" element={<RequireLogin component={LogDetails} />} />
539+
<Route path="/entities" element={<RequireLogin component={EntitiesPage} />} />
540+
<Route
541+
path="/schema"
542+
element={<RequireLogin schema={this.schema} component={SchemaPage} />}
532543
/>
533-
<Route path="/topology" element={<RequireLogin component={TopologyPage}/>}/>
534-
<Route path="/flow" element={<RequireLogin component={MessageFlowPage}/>}/>
535-
<Route path="/logs" element={<RequireLogin component={LogDetails}/>}/>
536-
<Route path="/entities" element={<RequireLogin component={EntitiesPage}/>}/>
537-
<Route path="/schema" element={<RequireLogin schema={this.schema} component={SchemaPage}/>}/>
538544
<Route
539545
path="/login/*"
540546
element={

0 commit comments

Comments
 (0)