From 6aae8f60da3974125a3374e593214a8c313a7f94 Mon Sep 17 00:00:00 2001 From: Michael Nelson Date: Wed, 2 Aug 2023 17:40:23 +1000 Subject: [PATCH] Remove history and add BrowserRouter. Signed-off-by: Michael Nelson --- dashboard/package.json | 1 - .../components/ConfigLoader/ConfigLoader.tsx | 2 +- .../DeploymentForm/DeploymentForm.test.tsx | 12 +++---- .../ConfigLoaderContainer.ts | 23 ------------ .../containers/ConfigLoaderContainer/index.ts | 6 ---- dashboard/src/containers/Root.tsx | 17 +++++---- dashboard/src/store/index.ts | 4 --- dashboard/yarn.lock | 36 ++----------------- 8 files changed, 19 insertions(+), 82 deletions(-) delete mode 100644 dashboard/src/containers/ConfigLoaderContainer/ConfigLoaderContainer.ts delete mode 100644 dashboard/src/containers/ConfigLoaderContainer/index.ts diff --git a/dashboard/package.json b/dashboard/package.json index 56c25bdfb25f..01e089c44662 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -42,7 +42,6 @@ "axios": "^1.3.5", "fast-json-patch": "^3.1.1", "google-protobuf": "^3.21.2", - "history": "^4.10.1", "jsonwebtoken": "^9.0.1", "lodash": "^4.17.21", "lodash-es": "^4.17.21", diff --git a/dashboard/src/components/ConfigLoader/ConfigLoader.tsx b/dashboard/src/components/ConfigLoader/ConfigLoader.tsx index 6a6874cff07d..a8cde0f4eed9 100644 --- a/dashboard/src/components/ConfigLoader/ConfigLoader.tsx +++ b/dashboard/src/components/ConfigLoader/ConfigLoader.tsx @@ -20,7 +20,7 @@ function ConfigLoader({ ...otherProps }: IConfigLoaderProps) { const intl = useIntl(); React.useEffect(() => { dispatch(actions.config.getConfig()); - }); + }, [dispatch]); const kubeappsTitle = intl.formatMessage({ id: "Kubeapps", defaultMessage: "Kubeapps" }); const { diff --git a/dashboard/src/components/DeploymentForm/DeploymentForm.test.tsx b/dashboard/src/components/DeploymentForm/DeploymentForm.test.tsx index 2a74b236134d..b049137b24c3 100644 --- a/dashboard/src/components/DeploymentForm/DeploymentForm.test.tsx +++ b/dashboard/src/components/DeploymentForm/DeploymentForm.test.tsx @@ -15,7 +15,6 @@ import { } from "gen/kubeappsapis/core/packages/v1alpha1/packages_pb"; import { Plugin } from "gen/kubeappsapis/core/plugins/v1alpha1/plugins_pb"; import { GetServiceAccountNamesResponse } from "gen/kubeappsapis/plugins/resources/v1alpha1/resources_pb"; -import { createMemoryHistory } from "history"; import * as ReactRedux from "react-redux"; import * as ReactRouter from "react-router"; import { MemoryRouter, Route, Routes } from "react-router-dom"; @@ -53,15 +52,16 @@ const defaultSelectedPkg = { const routePathParam = `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/new/${defaultProps.plugin.name}/${defaultProps.plugin.version}/${defaultProps.packageCluster}/${defaultProps.packageNamespace}/${defaultProps.pkgName}/versions/${defaultProps.version}`; const routePath = "/c/:cluster/ns/:namespace/apps/new/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId/versions/:packageVersion"; -const history = createMemoryHistory({ initialEntries: [routePathParam] }); let spyOnUseDispatch: jest.SpyInstance; let spyOnUseNavigate: jest.SpyInstance; +let mockNavigate: jest.Func; beforeEach(() => { - const mockDispatch = jest.fn(); + const mockDispatch = jest.fn().mockReturnValue(true); spyOnUseDispatch = jest.spyOn(ReactRedux, "useDispatch").mockReturnValue(mockDispatch); - spyOnUseNavigate = jest.spyOn(ReactRouter, "useNavigate").mockReturnValue(jest.fn()); + mockNavigate = jest.fn(); + spyOnUseNavigate = jest.spyOn(ReactRouter, "useNavigate").mockReturnValue(mockNavigate); // mock the window.matchMedia for selecting the theme Object.defineProperty(window, "matchMedia", { writable: true, @@ -411,8 +411,8 @@ describe("renders an error", () => { {} as ReconciliationOptions, ); - expect(history.location.pathname).toBe( - `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/new/my.plugin/0.0.1/${defaultProps.packageCluster}/${defaultProps.packageNamespace}/foo/versions/0.0.1`, + expect(navigate).toHaveBeenCalledWith( + `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/my.plugin/0.0.1/${defaultProps.releaseName}`, ); }); }); diff --git a/dashboard/src/containers/ConfigLoaderContainer/ConfigLoaderContainer.ts b/dashboard/src/containers/ConfigLoaderContainer/ConfigLoaderContainer.ts deleted file mode 100644 index 1538652cf170..000000000000 --- a/dashboard/src/containers/ConfigLoaderContainer/ConfigLoaderContainer.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018-2022 the Kubeapps contributors. -// SPDX-License-Identifier: Apache-2.0 - -import { connect } from "react-redux"; -import { ThunkDispatch } from "redux-thunk"; -import { IStoreState } from "shared/types"; -import actions from "../../actions"; -import { ConfigAction } from "../../actions/config"; -import ConfigLoader from "../../components/ConfigLoader"; - -function mapStateToProps({ config }: IStoreState) { - return { - loaded: config.loaded, - error: config.error, - }; -} -function mapDispatchToProps(dispatch: ThunkDispatch) { - return { - getConfig: () => dispatch(actions.config.getConfig()), - }; -} - -export default connect(mapStateToProps, mapDispatchToProps)(ConfigLoader); diff --git a/dashboard/src/containers/ConfigLoaderContainer/index.ts b/dashboard/src/containers/ConfigLoaderContainer/index.ts deleted file mode 100644 index ab06e563901e..000000000000 --- a/dashboard/src/containers/ConfigLoaderContainer/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2018-2022 the Kubeapps contributors. -// SPDX-License-Identifier: Apache-2.0 - -import ConfigLoaderContainer from "./ConfigLoaderContainer"; - -export default ConfigLoaderContainer; diff --git a/dashboard/src/containers/Root.tsx b/dashboard/src/containers/Root.tsx index 65ba5bf3b8e1..eb446b16266e 100644 --- a/dashboard/src/containers/Root.tsx +++ b/dashboard/src/containers/Root.tsx @@ -11,6 +11,7 @@ import I18n, { ISupportedLangs } from "shared/I18n"; import store from "../store"; import Routes from "./RoutesContainer"; import ConfigLoader from "components/ConfigLoader"; +import { BrowserRouter } from "react-router-dom"; async function initLocale() { const fullLang = (navigator.languages && navigator.languages[0]) || navigator.language; @@ -34,13 +35,15 @@ function Root() { defaultLocale="en" > - - - - - - - + + + + + + + + + diff --git a/dashboard/src/store/index.ts b/dashboard/src/store/index.ts index f69078013848..741a3451265b 100644 --- a/dashboard/src/store/index.ts +++ b/dashboard/src/store/index.ts @@ -1,15 +1,11 @@ // Copyright 2018-2023 the Kubeapps contributors. // SPDX-License-Identifier: Apache-2.0 -import { createHashHistory } from "history"; import { applyMiddleware, createStore } from "redux"; import { composeWithDevTools } from "redux-devtools-extension"; import thunkMiddleware from "redux-thunk"; import createRootReducer from "../reducers"; -// Use Hash based routing to support deploying Kubeapps in arbitrary URL subpaths -export const history = createHashHistory(); - export default createStore( createRootReducer(), composeWithDevTools(applyMiddleware(thunkMiddleware)), diff --git a/dashboard/yarn.lock b/dashboard/yarn.lock index 0634400fd6dd..4de3913b4aa7 100644 --- a/dashboard/yarn.lock +++ b/dashboard/yarn.lock @@ -1133,7 +1133,7 @@ core-js-pure "^3.30.2" regenerator-runtime "^0.13.11" -"@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.15.4", "@babel/runtime@^7.16.3", "@babel/runtime@^7.20.7", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.15.4", "@babel/runtime@^7.16.3", "@babel/runtime@^7.20.7", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": version "7.22.6" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.6.tgz#57d64b9ae3cff1d67eb067ae117dac087f5bd438" integrity sha512-wDb5pWm4WDdF6LFUde3Jl8WzPA+3ZbxYqkC6xAXuD3irdEHN1k0NfTRrJD8ZD378SJ61miMLCqIOXYhd8x+AJQ== @@ -7374,18 +7374,6 @@ highlight.js@^10.4.1, highlight.js@~10.7.0: resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.7.3.tgz#697272e3991356e40c3cac566a74eef681756531" integrity sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A== -history@^4.10.1: - version "4.10.1" - resolved "https://registry.yarnpkg.com/history/-/history-4.10.1.tgz#33371a65e3a83b267434e2b3f3b1b4c58aad4cf3" - integrity sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew== - dependencies: - "@babel/runtime" "^7.1.2" - loose-envify "^1.2.0" - resolve-pathname "^3.0.0" - tiny-invariant "^1.0.2" - tiny-warning "^1.0.0" - value-equal "^1.0.1" - hmac-drbg@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -9429,7 +9417,7 @@ longest-streak@^3.0.0: resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-3.1.0.tgz#62fa67cd958742a1574af9f39866364102d90cd4" integrity sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g== -loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.4.0: +loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -12679,11 +12667,6 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve-pathname@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" - integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng== - resolve-pkg-maps@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" @@ -14130,16 +14113,6 @@ timers-browserify@^2.0.12: dependencies: setimmediate "^1.0.4" -tiny-invariant@^1.0.2: - version "1.3.1" - resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz#8560808c916ef02ecfd55e66090df23a4b7aa642" - integrity sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw== - -tiny-warning@^1.0.0: - version "1.0.3" - resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754" - integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA== - titleize@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/titleize/-/titleize-3.0.0.tgz#71c12eb7fdd2558aa8a44b0be83b8a76694acd53" @@ -14806,11 +14779,6 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -value-equal@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c" - integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw== - vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"